mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: messaging unread
dont mark chat room unread and then read right away for the user sending the message
This commit is contained in:
@@ -57,14 +57,10 @@ module.exports = function (Messaging) {
|
|||||||
await Promise.all([
|
await Promise.all([
|
||||||
Messaging.addRoomToUsers(data.roomId, uids, timestamp),
|
Messaging.addRoomToUsers(data.roomId, uids, timestamp),
|
||||||
Messaging.addMessageToUsers(data.roomId, uids, mid, timestamp),
|
Messaging.addMessageToUsers(data.roomId, uids, mid, timestamp),
|
||||||
Messaging.markUnread(uids, data.roomId),
|
Messaging.markUnread(uids.filter(uid => uid !== String(data.uid)), data.roomId),
|
||||||
]);
|
|
||||||
|
|
||||||
const [, messages] = await Promise.all([
|
|
||||||
await Messaging.markRead(data.uid, data.roomId),
|
|
||||||
await Messaging.getMessagesData([mid], data.uid, data.roomId, true),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const messages = await Messaging.getMessagesData([mid], data.uid, data.roomId, true);
|
||||||
if (!messages || !messages[0]) {
|
if (!messages || !messages[0]) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,20 @@ module.exports = function (Messaging) {
|
|||||||
sockets.in('uid_' + uid).emit('event:unread.updateChatCount', unreadCount);
|
sockets.in('uid_' + uid).emit('event:unread.updateChatCount', unreadCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
Messaging.markRead = async (uid, roomId) => db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId);
|
Messaging.markRead = async (uid, roomId) => {
|
||||||
Messaging.markAllRead = async uid => db.delete('uid:' + uid + ':chat:rooms:unread');
|
await db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId);
|
||||||
|
};
|
||||||
|
|
||||||
|
Messaging.markAllRead = async (uid) => {
|
||||||
|
await db.delete('uid:' + uid + ':chat:rooms:unread');
|
||||||
|
};
|
||||||
|
|
||||||
Messaging.markUnread = async (uids, roomId) => {
|
Messaging.markUnread = async (uids, roomId) => {
|
||||||
const exists = await Messaging.roomExists(roomId);
|
const exists = await Messaging.roomExists(roomId);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
throw new Error('[[error:chat-room-does-not-exist]]');
|
throw new Error('[[error:chat-room-does-not-exist]]');
|
||||||
}
|
}
|
||||||
var keys = uids.map(function (uid) {
|
const keys = uids.map(uid => 'uid:' + uid + ':chat:rooms:unread');
|
||||||
return 'uid:' + uid + ':chat:rooms:unread';
|
|
||||||
});
|
|
||||||
|
|
||||||
return await db.sortedSetsAdd(keys, Date.now(), roomId);
|
return await db.sortedSetsAdd(keys, Date.now(), roomId);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user