Skip to content

Commit

Permalink
Update unread count when marking as unread
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Svenningsen <chris@carbonfive.com>
  • Loading branch information
2 people authored and EvanHahn-Signal committed Nov 4, 2020
1 parent 8bfaf59 commit cfc3c12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ts/ConversationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,27 @@ export function start(): void {
const canCountMutedConversations = window.storage.get(
'badge-count-muted-conversations'
);

const canCount = (m: ConversationModel) =>
!m.isMuted() || canCountMutedConversations;

const getUnreadCount = (m: ConversationModel) => {
const unreadCount = m.get('unreadCount');

if (unreadCount) {
return unreadCount;
}

if (m.get('markedUnread')) {
return 1;
}

return 0;
};

const newUnreadCount = reduce(
this.map((m: ConversationModel) =>
!canCountMutedConversations && m.isMuted() ? 0 : m.get('unreadCount')
canCount(m) ? getUnreadCount(m) : 0
),
(item: number, memo: number) => (item || 0) + memo,
0
Expand Down
1 change: 1 addition & 0 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,7 @@ export class ConversationModel extends window.Backbone.Model<
this.set({ markedUnread });
window.Signal.Data.updateConversation(this.attributes);
this.captureChange('markedUnread');
window.Whisper.events.trigger('updateUnreadCount');
}

async updateExpirationTimer(
Expand Down

0 comments on commit cfc3c12

Please sign in to comment.