fixed some socket not working on production
This commit is contained in:
@@ -44,20 +44,16 @@ function ContactsList({
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
|
||||
socket.on(
|
||||
'added to group',
|
||||
(msg: {
|
||||
username: string;
|
||||
user_id: string;
|
||||
group_id: string;
|
||||
isadmin: false;
|
||||
}) => {
|
||||
console.log('added to group, fetching contacts');
|
||||
console.error(msg);
|
||||
const handleAddedToGroup = () => {
|
||||
fetchContacts();
|
||||
},
|
||||
);
|
||||
}, []);
|
||||
};
|
||||
|
||||
socket.on('added to group', handleAddedToGroup);
|
||||
|
||||
return () => {
|
||||
socket?.off('added to group', handleAddedToGroup);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
const fetchContacts = async () => {
|
||||
const contacts: ContactsProps[] = await getContactsList();
|
||||
|
||||
@@ -71,18 +71,13 @@ function ParticipantsBar({
|
||||
useEffect(() => {
|
||||
if (!socket || !contact) return;
|
||||
|
||||
socket.on(
|
||||
'added to group',
|
||||
(msg: {
|
||||
const handleAddedToGroup = (msg: {
|
||||
username: string;
|
||||
user_id: string;
|
||||
group_id: string;
|
||||
isadmin: false;
|
||||
}) => {
|
||||
const { group_id } = msg;
|
||||
console.log('Added to group: ', msg);
|
||||
console.log('Current participants: ', participants);
|
||||
console.log('CURRENTCONTACT: ', currentContact);
|
||||
if (
|
||||
msg.group_id == currentContact?.conversation_id &&
|
||||
msg.user_id == user?.user_id
|
||||
@@ -109,12 +104,9 @@ function ParticipantsBar({
|
||||
return [...prevMembers, msg];
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
socket.on('left group', (msg: { user_id: string; group_id: string }) => {
|
||||
console.log(`(socket on "left group")`, msg);
|
||||
// Initialize contact again to clear messages and participants list
|
||||
const handleLeftGroup = (msg: { user_id: string; group_id: string }) => {
|
||||
if (
|
||||
msg.group_id == currentContact?.conversation_id &&
|
||||
msg.user_id == user?.user_id
|
||||
@@ -124,13 +116,16 @@ function ParticipantsBar({
|
||||
setParticipants((prevMembers) =>
|
||||
prevMembers.filter((member) => member.user_id !== msg.user_id),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
socket.on('added to group', handleAddedToGroup);
|
||||
socket.on('left group', handleLeftGroup);
|
||||
|
||||
return () => {
|
||||
socket?.off('left group');
|
||||
socket?.off('added to group');
|
||||
socket?.off('added to group', handleAddedToGroup);
|
||||
socket?.off('left group', handleLeftGroup);
|
||||
};
|
||||
}, [contact, participants]);
|
||||
}, [socket, contact, currentContact, user?.user_id]);
|
||||
|
||||
const handleRemoveUser = async (userId: string) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user