-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincomingMessageNotify.ts
More file actions
38 lines (34 loc) · 950 Bytes
/
Copy pathincomingMessageNotify.ts
File metadata and controls
38 lines (34 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { RoomNotificationLevel } from '~/utils/matrixNotificationRules'
import type { RoomUnreadState } from '~/utils/roomUnread'
export function shouldNotifyIncomingMessage(options: {
roomId: string
selectedRoomId: string | null
notificationLevel: RoomNotificationLevel
current: RoomUnreadState
previous?: RoomUnreadState
soundEnabled: boolean
}): boolean {
if (!options.soundEnabled) {
return false
}
if (options.notificationLevel === 'mute') {
return false
}
if (options.roomId === options.selectedRoomId) {
return false
}
if (!options.previous) {
return false
}
const { current, previous, notificationLevel } = options
if (notificationLevel === 'mentions') {
return (
current.hasMentionUnread &&
current.highlightCount > previous.highlightCount
)
}
return (
current.totalCount > previous.totalCount ||
current.highlightCount > previous.highlightCount
)
}