Cleans up mute state after mute expires

This commit is contained in:
Josh Perez 2020-09-30 20:43:24 -04:00 committed by Josh Perez
parent a581f6ea81
commit 9510fd1eec
7 changed files with 125 additions and 8 deletions

View file

@ -40,6 +40,9 @@ export function start(): void {
this.on('add remove change:unreadCount', debouncedUpdateUnreadCount);
window.Whisper.events.on('updateUnreadCount', debouncedUpdateUnreadCount);
this.on('add', (model: ConversationModel): void => {
this.initMuteExpirationTimer(model);
});
},
addActive(model: ConversationModel) {
if (model.get('active_at')) {
@ -48,6 +51,22 @@ export function start(): void {
this.remove(model);
}
},
// If the conversation is muted we set a timeout so when the mute expires
// we can reset the mute state on the model. If the mute has already expired
// then we reset the state right away.
initMuteExpirationTimer(model: ConversationModel): void {
if (model.isMuted()) {
window.Signal.Services.onTimeout(
model.get('muteExpiresAt'),
() => {
model.set({ muteExpiresAt: undefined });
},
model.getMuteTimeoutId()
);
} else if (model.get('muteExpiresAt')) {
model.set({ muteExpiresAt: undefined });
}
},
updateUnreadCount() {
const canCountMutedConversations = window.storage.get(
'badge-count-muted-conversations'