Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep the unread badge on a chat marked unread

Yudhi Armyndharis646a868f9a79
diff --git a/dashboard/src/utils/chatList.test.ts b/dashboard/src/utils/chatList.test.ts
index bdd74252d..ee4adf718 100644
--- a/dashboard/src/utils/chatList.test.ts
+++ b/dashboard/src/utils/chatList.test.ts
@@ -67,6 +67,15 @@ test('unread increments only for an incoming message in a chat that is not open'
assert.equal(ownSend.chats[0].unreadCount, 2);
});
+test('a message into a chat marked unread counts as one unread, not zero', () => {
+ const { chats } = applyIncomingToChatList(
+ [chat('[email protected]', { unreadCount: -1 })],
+ { chatId: '[email protected]', body: 'hi', timestamp: 200 },
+ { activeChatId: '[email protected]', locationLabel: LOCATION },
+ );
+ assert.equal(chats[0].unreadCount, 1);
+});
+
test('an unknown chat asks for a refetch, and leaves the list alone', () => {
const before = [chat('[email protected]')];
diff --git a/dashboard/src/utils/chatList.ts b/dashboard/src/utils/chatList.ts
index adc7d18b1..a1268cc81 100644
--- a/dashboard/src/utils/chatList.ts
+++ b/dashboard/src/utils/chatList.ts
@@ -65,7 +65,8 @@ export function applyIncomingToChatList<T extends ChatListEntry>(
target.lastMessage = msg.type === 'location' ? opts.locationLabel : msg.body;
target.timestamp = msg.timestamp;
if (!msg.fromMe && opts.activeChatId !== target.id) {
- target.unreadCount = (target.unreadCount || 0) + 1;
+ // A chat marked unread carries -1; the first message into it counts as 1, not 0.
+ target.unreadCount = Math.max(target.unreadCount ?? 0, 0) + 1;
}
updated.splice(index, 1);
updated.unshift(target);