diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 410915343b6..8ab3590f045 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -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); } } diff --git a/ts/models/messages.ts b/ts/models/messages.ts index d9afec3ff0f..d4a1fbe15ed 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -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 { 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 { } else if ( isFirstRun && !isGroupStoryReply && - !keepThisConversationArchived + canConversationBeUnarchived(conversation.attributes) ) { conversation.setArchived(false); } diff --git a/ts/util/canConversationBeUnarchived.ts b/ts/util/canConversationBeUnarchived.ts new file mode 100644 index 00000000000..7c9643d46eb --- /dev/null +++ b/ts/util/canConversationBeUnarchived.ts @@ -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; +}