2022-05-23 22:21:14 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { ConversationAttributesType } from '../model-types.d';
|
|
|
|
import { isConversationMuted } from './isConversationMuted';
|
|
|
|
|
|
|
|
export function getConversationUnreadCountForAppBadge(
|
|
|
|
conversation: Readonly<
|
|
|
|
Pick<
|
|
|
|
ConversationAttributesType,
|
2022-06-01 01:26:57 +00:00
|
|
|
| 'active_at'
|
|
|
|
| 'isArchived'
|
|
|
|
| 'markedUnread'
|
|
|
|
| 'muteExpiresAt'
|
|
|
|
| 'unreadCount'
|
2022-05-23 22:21:14 +00:00
|
|
|
>
|
|
|
|
>,
|
|
|
|
canCountMutedConversations: boolean
|
|
|
|
): number {
|
|
|
|
const { isArchived, markedUnread, unreadCount } = conversation;
|
|
|
|
|
2022-06-01 01:26:57 +00:00
|
|
|
if (!conversation.active_at) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-23 22:21:14 +00:00
|
|
|
if (isArchived) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canCountMutedConversations && isConversationMuted(conversation)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unreadCount) {
|
|
|
|
return unreadCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (markedUnread) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|