android, desktop: don't show unwanted notifications (#5328)

* android, desktop: don't show unwanted notifications

* format

* fix

* code style

---------

Co-authored-by: Avently <7953703+avently@users.noreply.github.com>
This commit is contained in:
spaced4ndy
2024-12-05 22:45:19 +04:00
committed by GitHub
parent e9bf229a9d
commit 69e23ad58f
2 changed files with 22 additions and 8 deletions
@@ -2436,9 +2436,7 @@ object ChatController {
) {
receiveFile(rhId, r.user, file.fileId, auto = true)
}
if (cItem.showNotification && (allowedToShowNotification() || chatModel.chatId.value != cInfo.id || chatModel.remoteHostId() != rhId)) {
ntfManager.notifyMessageReceived(r.user, cInfo, cItem)
}
ntfManager.notifyMessageReceived(rhId, r.user, cInfo, cItem)
}
}
is CR.ChatItemsStatusesUpdated ->
@@ -2452,7 +2450,7 @@ object ChatController {
}
}
is CR.ChatItemUpdated ->
chatItemSimpleUpdate(rhId, r.user, r.chatItem)
chatItemUpdateNotify(rhId, r.user, r.chatItem)
is CR.ChatItemReaction -> {
if (active(r.user)) {
withChats {
@@ -2950,9 +2948,17 @@ object ChatController {
}
private suspend fun chatItemSimpleUpdate(rh: Long?, user: UserLike, aChatItem: AChatItem) {
if (activeUser(rh, user)) {
val cInfo = aChatItem.chatInfo
val cItem = aChatItem.chatItem
withChats { upsertChatItem(rh, cInfo, cItem) }
}
}
private suspend fun chatItemUpdateNotify(rh: Long?, user: UserLike, aChatItem: AChatItem) {
val cInfo = aChatItem.chatInfo
val cItem = aChatItem.chatItem
val notify = { ntfManager.notifyMessageReceived(user, cInfo, cItem) }
val notify = { ntfManager.notifyMessageReceived(rh, user, cInfo, cItem) }
if (!activeUser(rh, user)) {
notify()
} else if (withChats { upsertChatItem(rh, cInfo, cItem) }) {
@@ -36,9 +36,17 @@ abstract class NtfManager {
)
)
fun notifyMessageReceived(user: UserLike, cInfo: ChatInfo, cItem: ChatItem) {
if (!cInfo.ntfsEnabled) return
displayNotification(user = user, chatId = cInfo.id, displayName = cInfo.displayName, msgText = hideSecrets(cItem))
fun notifyMessageReceived(rhId: Long?, user: UserLike, cInfo: ChatInfo, cItem: ChatItem) {
if (
cItem.showNotification &&
cInfo.ntfsEnabled &&
(
allowedToShowNotification() ||
chatModel.chatId.value != cInfo.id ||
chatModel.remoteHostId() != rhId)
) {
displayNotification(user = user, chatId = cInfo.id, displayName = cInfo.displayName, msgText = hideSecrets(cItem))
}
}
fun acceptContactRequestAction(userId: Long?, incognito: Boolean, chatId: ChatId) {