Skip to content

Commit e8f8548

Browse files
author
Rishabh Garg
committed
Added events to capture correct status of conversation
1 parent a0a8527 commit e8f8548

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

app/config/socket.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export class Socket {
4141
else {
4242
next(new Error('Authentication error'));
4343
}
44-
})
44+
});
45+
4546
SocketConf.io.on('connect', async (socket) => {
4647
console.log('Client Connectted');
4748
socket.join(socket.handshake.query.loggedUser._id);
@@ -60,9 +61,9 @@ export class Socket {
6061
const message = await this.messageRepository.create(messageObject);
6162
io.to(messageObject.conversation!).emit('message', message);
6263
((messageObject.members as Array<UserModel>).filter(user => user._id !== messageObject.sender)).forEach(user => {
63-
if (io.sockets.adapter.rooms[user._id] && io.sockets.adapter.rooms[user._id].length) {
64-
io.to(user._id).emit('unseen-message', message);
65-
}
64+
// if (io.sockets.adapter.rooms[user._id] && io.sockets.adapter.rooms[user._id].length) {
65+
io.to(user._id).emit('new-message-trigger', message);
66+
// }
6667
});
6768
});
6869

@@ -78,7 +79,9 @@ export class Socket {
7879
"createdAt": { $lte: new Date(date).toISOString() }
7980
}, { "$addToSet": { seen: socket.handshake.query.loggedUser._id } }, { multi: true }
8081
);
82+
io.to(conversation!).emit('seen-trigger', socket.handshake.query.loggedUser._id);
8183
});
84+
8285
socket.on('disconnect', async () => {
8386
console.log('Disconnected socket');
8487
await this.userRepository.updateWithoutSet(

0 commit comments

Comments
 (0)