mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +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([ | ||||
| 			Messaging.addRoomToUsers(data.roomId, uids, timestamp), | ||||
| 			Messaging.addMessageToUsers(data.roomId, uids, mid, timestamp), | ||||
| 			Messaging.markUnread(uids, data.roomId), | ||||
| 		]); | ||||
|  | ||||
| 		const [, messages] = await Promise.all([ | ||||
| 			await Messaging.markRead(data.uid, data.roomId), | ||||
| 			await Messaging.getMessagesData([mid], data.uid, data.roomId, true), | ||||
| 			Messaging.markUnread(uids.filter(uid => uid !== String(data.uid)), data.roomId), | ||||
| 		]); | ||||
|  | ||||
| 		const messages = await Messaging.getMessagesData([mid], data.uid, data.roomId, true); | ||||
| 		if (!messages || !messages[0]) { | ||||
| 			return null; | ||||
| 		} | ||||
|   | ||||
| @@ -20,18 +20,20 @@ module.exports = function (Messaging) { | ||||
| 		sockets.in('uid_' + uid).emit('event:unread.updateChatCount', unreadCount); | ||||
| 	}; | ||||
|  | ||||
| 	Messaging.markRead = async (uid, roomId) => db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId); | ||||
| 	Messaging.markAllRead = async uid => db.delete('uid:' + uid + ':chat:rooms:unread'); | ||||
| 	Messaging.markRead = async (uid, roomId) => { | ||||
| 		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) => { | ||||
| 		const exists = await Messaging.roomExists(roomId); | ||||
| 		if (!exists) { | ||||
| 			throw new Error('[[error:chat-room-does-not-exist]]'); | ||||
| 		} | ||||
| 		var keys = uids.map(function (uid) { | ||||
| 			return 'uid:' + uid + ':chat:rooms:unread'; | ||||
| 		}); | ||||
|  | ||||
| 		const keys = uids.map(uid => 'uid:' + uid + ':chat:rooms:unread'); | ||||
| 		return await db.sortedSetsAdd(keys, Date.now(), roomId); | ||||
| 	}; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user