| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2024-06-24 20:24:49 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2024-06-24 20:24:49 UTC |
| parent | 3918bfd9b50f0798a3737d9ccf6c47df1c345f58 |
| snikket/persistence/browser.js | +12 | -9 |
diff --git a/snikket/persistence/browser.js b/snikket/persistence/browser.js index d4ac934..ba0075e 100644 --- a/snikket/persistence/browser.js +++ b/snikket/persistence/browser.js @@ -69,8 +69,8 @@ const browser = (dbname) => { message.serverId = value.serverId ? value.serverId : null; message.serverIdBy = value.serverIdBy ? value.serverIdBy : null; message.syncPoint = !!value.syncPoint; - message.direction = value.direction; - message.status = value.status; + message.direction = value.direction; + message.status = value.status; message.timestamp = value.timestamp && value.timestamp.toISOString(); message.to = value.to && snikket.JID.parse(value.to); message.from = value.from && snikket.JID.parse(value.from); @@ -230,14 +230,17 @@ const browser = (dbname) => { rowCount++; const value = event.target.result.value; if (result[value.chatId]) { - if (!result[value.chatId].foundAll) { - const readUpTo = chats[value.chatId]?.readUpTo(); - if (readUpTo === value.serverId || readUpTo === value.localId || value.direction == enums.MessageDirection.MessageSent) { - result[value.chatId].foundAll = true; - } else { - result[value.chatId] = result[value.chatId].then((details) => { details.unreadCount++; return details; }); + 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;