Last active
October 27, 2021 05:39
-
-
Save hieptl/24d05fb82f2b8b1fcf3a692806e4d26c to your computer and use it in GitHub Desktop.
Chat.tsx - Listen for Online/Offline Users - Ionic Chat App
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
... | |
const Chat: React.FC = () => { | |
... | |
const { cometChat, user, selectedConversation, setCallType } = useContext(Context); | |
... | |
useEffect(() => { | |
... | |
return () => { | |
if (selectedConversation) { | |
... | |
if (selectedConversation.contactType === 0) { | |
cometChat.removeUserListener(userOnlineListenerId); | |
} | |
... | |
} | |
} | |
}, [selectedConversation]); | |
... | |
const listenForOnlineUsers = () => { | |
cometChat.addUserListener( | |
userOnlineListenerId, | |
new cometChat.UserListener({ | |
onUserOnline: (onlineUser: any) => { | |
if (onlineUser && onlineUser.uid === selectedConversation.uid) { | |
setIsUserOnline(() => true); | |
} | |
}, | |
onUserOffline: (offlineUser: any) => { | |
if (offlineUser && offlineUser.uid === selectedConversation.uid) { | |
setIsUserOnline(() => false); | |
} | |
} | |
}) | |
); | |
}; | |
}; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment