Skip to content

Commit 8434c68

Browse files
Merge pull request lugnitdgp#26 from Arnob-B/main
notification on active chats when user in not focused
2 parents 8a79b9b + 0ef4c60 commit 8434c68

File tree

3 files changed

+6047
-297
lines changed

3 files changed

+6047
-297
lines changed

chatopia/app/conversations/[conversationId]/components/Body.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const Body: React.FC<BodyProps> = ({ initialMessages }) => {
3131
// Body component will listen for new messages and update the state whenever a new message is received through the socket
3232

3333
useEffect(() => {
34+
//getting the notification permission
35+
Notification.requestPermission();
3436
// Update the message receive in the current message
3537
const updateMessageHandler = (newMessage: FullMessageType) => {
3638
// Update the message in the state only if the message belongs to the current conversation
@@ -63,6 +65,10 @@ const Body: React.FC<BodyProps> = ({ initialMessages }) => {
6365
// Render received message from server only if it belongs to the current conversation
6466
if(message.conversationId === conversationId){
6567
// Add the new message to the state
68+
console.log(Notification.permission);
69+
if (document.visibilityState === 'hidden') {
70+
new Notification(`${message.sender.name} sent a msg`);
71+
}
6672
setMessages((current) =>{
6773
if(find(current, {id: message.id})){
6874
return current;

0 commit comments

Comments
 (0)