git » sdk » commit e49dbaf

Do not return for chats we weren't passed

author Stephen Paul Weber
2025-09-29 13:37:50 UTC
committer Stephen Paul Weber
2025-09-29 13:37:50 UTC
parent 3046320d0f995ced5e3b97b431e5eb95a0e63fc5

Do not return for chats we weren't passed

snikket/persistence/IDB.js +17 -15

diff --git a/snikket/persistence/IDB.js b/snikket/persistence/IDB.js
index 80eabd9..61e9b4b 100644
--- a/snikket/persistence/IDB.js
+++ b/snikket/persistence/IDB.js
@@ -287,22 +287,24 @@ export default (dbname, media, tokenize, stemmer) => {
 				if (cresult && rowCount < 40000) {
 					rowCount++;
 					const value = cresult.value;
-					if (result[value.chatId]) {
-						result[value.chatId] = result[value.chatId].then((details) => {
-							if (!details.foundAll) {
-								const readUpTo = chats[value.chatId]?.readUpTo();
-								if (readUpTo === value.serverId || readUpTo === value.localId || value.direction == enums.MessageDirection.MessageSent) {
-									details.foundAll = true;
-								} else {
-									details.unreadCount++;
+					if (chats[value.chatId]) {
+						if (result[value.chatId]) {
+							result[value.chatId] = result[value.chatId].then((details) => {
+								if (!details.foundAll) {
+									const readUpTo = chats[value.chatId]?.readUpTo();
+									if (readUpTo === value.serverId || readUpTo === value.localId || value.direction == enums.MessageDirection.MessageSent) {
+										details.foundAll = true;
+									} else {
+										details.unreadCount++;
+									}
 								}
-							}
-							return details;
-						});
-					} else {
-						const readUpTo = chats[value.chatId]?.readUpTo();
-						const haveRead = readUpTo === value.serverId || readUpTo === value.localId || value.direction == enums.MessageDirection.MessageSent;
-						result[value.chatId] = hydrateMessage(value).then((m) => ({ chatId: value.chatId, message: m, unreadCount: haveRead ? 0 : 1, foundAll: haveRead }));
+								return details;
+							});
+						} else {
+							const readUpTo = chats[value.chatId]?.readUpTo();
+							const haveRead = readUpTo === value.serverId || readUpTo === value.localId || value.direction == enums.MessageDirection.MessageSent;
+							result[value.chatId] = hydrateMessage(value).then((m) => ({ chatId: value.chatId, message: m, unreadCount: haveRead ? 0 : 1, foundAll: haveRead }));
+						}
 					}
 					cresult.continue();
 				} else {