Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created November 14, 2021 03:54
Show Gist options
  • Save hieptl/bf449382379f136b0947b72795454dc6 to your computer and use it in GitHub Desktop.
Save hieptl/bf449382379f136b0947b72795454dc6 to your computer and use it in GitHub Desktop.
Sidebars.js - Listen to Custom Message - Server - Discord Clone
...
useEffect(() => {
if (cometChat) {
listenCustomMessages();
}
return () => {
if (cometChat) {
cometChat.removeMessageListener(user.id);
}
}
}, [cometChat]);
const listenCustomMessages = () => {
cometChat.addMessageListener(
user.id,
new cometChat.MessageListener({
onCustomMessageReceived: customMessage => {
if (customMessage && customMessage.sender && customMessage.sender.uid && customMessage.sender.uid !== user.id && customMessage.data && customMessage.data.customData && customMessage.data.customData.message) {
if (customMessage && customMessage.type && customMessage.type === 'group') {
}
}
}
})
);
};
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment