Last active
October 27, 2021 05:13
-
-
Save hieptl/17bfadf07634850dfdd8cce120f852d5 to your computer and use it in GitHub Desktop.
App.tsx - Listen for Group Changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
useEffect(() => { | |
... | |
return () => { | |
... | |
if (cometChat) { | |
... | |
cometChat.removeGroupListener(groupListenerId); | |
} | |
} | |
}, []); | |
useEffect(() => { | |
if (cometChat) { | |
... | |
listenForGroupChanges(); | |
} | |
}, [cometChat]); | |
const listenForGroupChanges = () => { | |
cometChat.addGroupListener( | |
groupListenerId, | |
new cometChat.GroupListener({ | |
onMemberAddedToGroup: (message: any, userAdded: any, userAddedBy: any, userAddedIn: any) => { | |
alert(`${userAdded.name} was added to ${userAddedIn.name} by ${userAddedBy.name}`); | |
}, | |
onGroupMemberKicked: (message: any, kickedUser: any, kickedBy: any, kickedFrom: any) => { | |
alert(`${kickedUser.name} was removed from ${kickedFrom.name}`); | |
}, | |
onGroupMemberLeft: (message: any, leavingUser: any, group: any) => { | |
alert(`${leavingUser.name} has left the group ${group.name}`); | |
}, | |
onGroupMemberJoined: (message: any, joinedUser: any, joinedGroup: any) => { | |
alert(`${joinedUser.name} has joined the group ${joinedGroup.name}`); | |
} | |
}) | |
); | |
}; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment