diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 4e453e73a..236515892 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -1,4 +1,4 @@ -/* global _, Whisper, Backbone, storage, textsecure, libsignal, log */ +/* global Whisper, Backbone, textsecure, libsignal, log */ /* eslint-disable more/no-then */ @@ -15,10 +15,6 @@ this.listenTo(conversations, 'reset', () => this.reset([])); this.listenTo(conversations, 'remove', this.remove); - this.on( - 'add remove change:unreadCount', - _.debounce(this.updateUnreadCount.bind(this), 1000) - ); this.startPruning(); }, addActive(model) { @@ -29,23 +25,6 @@ this.remove(model); } }, - updateUnreadCount() { - const newUnreadCount = _.reduce( - this.map(m => m.get('unreadCount')), - (item, memo) => item + memo, - 0 - ); - storage.put('unreadCount', newUnreadCount); - - if (newUnreadCount > 0) { - window.setBadgeCount(newUnreadCount); - window.document.title = `${window.getTitle()} (${newUnreadCount})`; - } else { - window.setBadgeCount(0); - window.document.title = window.getTitle(); - } - window.updateTrayIcon(newUnreadCount); - }, startPruning() { const halfHour = 30 * 60 * 1000; this.interval = setInterval(() => { diff --git a/js/models/conversations.js b/js/models/conversations.js index be3b0aa6b..e958588fc 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1047,7 +1047,7 @@ ); }, - getUnread() { + async getUnread() { return window.Signal.Data.getUnreadByConversation(this.id, { MessageCollection: Whisper.MessageCollection, }); @@ -1741,6 +1741,7 @@ await window.Signal.Data.updateConversation(this.id, this.attributes, { Conversation: Whisper.Conversation, }); + await this.trigger('change', this); }, async addMessage(messageAttributes) { @@ -1866,7 +1867,6 @@ conversationId, }) ); - let unreadMessages = await this.getUnread(); const oldUnread = unreadMessages.filter( message => message.get('received_at') <= newestUnreadDate @@ -1898,7 +1898,7 @@ unreadMessages = unreadMessages.filter(m => Boolean(m.isIncoming())); const unreadCount = unreadMessages.length - read.length; - this.set({ unreadCount }); + this.set('unreadCount', unreadCount); const mentionRead = (() => { const stillUnread = unreadMessages.filter( diff --git a/js/views/message_list_view.js b/js/views/message_list_view.js index 84a8d58bc..13ac989d5 100644 --- a/js/views/message_list_view.js +++ b/js/views/message_list_view.js @@ -55,7 +55,7 @@ this.triggerLazyScroll(); }, atBottom() { - return this.bottomOffset < 30; + return this.bottomOffset ? this.bottomOffset < 30 : true; }, measureScrollPosition() { if (this.el.scrollHeight === 0) { diff --git a/ts/receiver/mediumGroups.ts b/ts/receiver/mediumGroups.ts index 49f19e0f6..1265a35ba 100644 --- a/ts/receiver/mediumGroups.ts +++ b/ts/receiver/mediumGroups.ts @@ -207,7 +207,10 @@ async function handleNewGroup( // We only set group admins on group creation convo.set('groupAdmins', admins); - + // update the unreadCount for this convo + convo.set({ + unreadCount: Number(convo.get('unreadCount')) + 1, + }); convo.commit(); const secretKeyHex = toHex(groupPrivateKey);