Generalize keepMutedChatsArchived check

This commit is contained in:
Fedor Indutny 2023-02-06 10:08:53 -08:00 committed by GitHub
parent f3b68677b3
commit dff924c0c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions

View file

@ -71,6 +71,7 @@ import {
import { missingCaseError } from '../util/missingCaseError';
import { sniffImageMimeType } from '../util/sniffImageMimeType';
import { isValidE164 } from '../util/isValidE164';
import { canConversationBeUnarchived } from '../util/canConversationBeUnarchived';
import type { MIMEType } from '../types/MIME';
import { IMAGE_JPEG, IMAGE_GIF, IMAGE_WEBP } from '../types/MIME';
import { UUID, UUIDKind } from '../types/UUID';
@ -3274,7 +3275,7 @@ export class ConversationModel extends window.Backbone
this.trigger('newmessage', model);
void this.updateUnread();
if (this.get('isArchived')) {
if (canConversationBeUnarchived(this.attributes)) {
this.setArchived(false);
}
}

View file

@ -90,6 +90,7 @@ import {
import { handleMessageSend } from '../util/handleMessageSend';
import { getSendOptions } from '../util/getSendOptions';
import { findAndFormatContact } from '../util/findAndFormatContact';
import { canConversationBeUnarchived } from '../util/canConversationBeUnarchived';
import {
getAttachmentsForMessage,
getMessagePropStatus,
@ -3167,11 +3168,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const isGroupStoryReply =
isGroup(conversation.attributes) && message.get('storyId');
const keepMutedChatsArchived =
window.storage.get('keepMutedChatsArchived') ?? false;
const keepThisConversationArchived =
keepMutedChatsArchived && conversation.isMuted();
if (readSyncs.length !== 0 || viewSyncs.length !== 0) {
const markReadAt = Math.min(
Date.now(),
@ -3214,7 +3210,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
} else if (
isFirstRun &&
!isGroupStoryReply &&
!keepThisConversationArchived
canConversationBeUnarchived(conversation.attributes)
) {
conversation.setArchived(false);
}

View file

@ -0,0 +1,23 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationAttributesType } from '../model-types.d';
import { isConversationMuted } from './isConversationMuted';
export function canConversationBeUnarchived(
attrs: ConversationAttributesType
): boolean {
if (!attrs.isArchived) {
return false;
}
if (!isConversationMuted(attrs)) {
return true;
}
if (window.storage.get('keepMutedChatsArchived') ?? false) {
return false;
}
return true;
}