Improve logic for app badge count
This commit is contained in:
parent
95de40662b
commit
59b45399e4
4 changed files with 150 additions and 30 deletions
35
ts/util/getConversationUnreadCountForAppBadge.ts
Normal file
35
ts/util/getConversationUnreadCountForAppBadge.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
// 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,
|
||||
'isArchived' | 'markedUnread' | 'muteExpiresAt' | 'unreadCount'
|
||||
>
|
||||
>,
|
||||
canCountMutedConversations: boolean
|
||||
): number {
|
||||
const { isArchived, markedUnread, unreadCount } = conversation;
|
||||
|
||||
if (isArchived) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!canCountMutedConversations && isConversationMuted(conversation)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (unreadCount) {
|
||||
return unreadCount;
|
||||
}
|
||||
|
||||
if (markedUnread) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue