mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-10 19:27:08 +00:00
mobile: don't show notifications for certain chat items (#1453)
This commit is contained in:
@@ -1065,30 +1065,39 @@ data class ChatItem (
|
||||
else -> false
|
||||
}
|
||||
|
||||
val isCall: Boolean get() =
|
||||
when (content) {
|
||||
is CIContent.SndCall -> true
|
||||
is CIContent.RcvCall -> true
|
||||
else -> false
|
||||
}
|
||||
private val showNtfDir: Boolean get() = !chatDir.sent
|
||||
|
||||
val isMutedMemberEvent: Boolean get() =
|
||||
val showNotification: Boolean get() =
|
||||
when (content) {
|
||||
is CIContent.RcvGroupEventContent ->
|
||||
when (content.rcvGroupEvent) {
|
||||
is RcvGroupEvent.GroupUpdated -> true
|
||||
is RcvGroupEvent.MemberConnected -> true
|
||||
is RcvGroupEvent.UserDeleted -> false
|
||||
is RcvGroupEvent.GroupDeleted -> false
|
||||
is RcvGroupEvent.MemberAdded -> false
|
||||
is RcvGroupEvent.MemberLeft -> false
|
||||
is RcvGroupEvent.MemberRole -> true
|
||||
is RcvGroupEvent.UserRole -> false
|
||||
is RcvGroupEvent.MemberDeleted -> false
|
||||
is RcvGroupEvent.InvitedViaGroupLink -> false
|
||||
}
|
||||
is CIContent.SndGroupEventContent -> true
|
||||
else -> false
|
||||
is CIContent.SndMsgContent -> showNtfDir
|
||||
is CIContent.RcvMsgContent -> showNtfDir
|
||||
is CIContent.SndDeleted -> showNtfDir
|
||||
is CIContent.RcvDeleted -> showNtfDir
|
||||
is CIContent.SndCall -> showNtfDir
|
||||
is CIContent.RcvCall -> false // notification is shown on CallInvitation instead
|
||||
is CIContent.RcvIntegrityError -> showNtfDir
|
||||
is CIContent.RcvGroupInvitation -> showNtfDir
|
||||
is CIContent.SndGroupInvitation -> showNtfDir
|
||||
is CIContent.RcvGroupEventContent -> when (content.rcvGroupEvent) {
|
||||
is RcvGroupEvent.MemberAdded -> false
|
||||
is RcvGroupEvent.MemberConnected -> false
|
||||
is RcvGroupEvent.MemberLeft -> false
|
||||
is RcvGroupEvent.MemberRole -> false
|
||||
is RcvGroupEvent.UserRole -> showNtfDir
|
||||
is RcvGroupEvent.MemberDeleted -> false
|
||||
is RcvGroupEvent.UserDeleted -> showNtfDir
|
||||
is RcvGroupEvent.GroupDeleted -> showNtfDir
|
||||
is RcvGroupEvent.GroupUpdated -> false
|
||||
is RcvGroupEvent.InvitedViaGroupLink -> false
|
||||
}
|
||||
is CIContent.SndGroupEventContent -> showNtfDir
|
||||
is CIContent.RcvConnEventContent -> false
|
||||
is CIContent.SndConnEventContent -> showNtfDir
|
||||
is CIContent.RcvChatFeature -> false
|
||||
is CIContent.SndChatFeature -> showNtfDir
|
||||
is CIContent.RcvGroupFeature -> false
|
||||
is CIContent.SndGroupFeature -> showNtfDir
|
||||
is CIContent.RcvChatFeatureRejected -> showNtfDir
|
||||
}
|
||||
|
||||
fun withStatus(status: CIStatus): ChatItem = this.copy(meta = meta.copy(itemStatus = status))
|
||||
|
||||
@@ -1064,7 +1064,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
} else if (cItem.content.msgContent is MsgContent.MCVoice && file != null && file.fileSize <= MAX_VOICE_SIZE_AUTO_RCV && file.fileSize > MAX_VOICE_SIZE_FOR_SENDING && appPrefs.privacyAcceptImages.get()) {
|
||||
withApi { receiveFile(file.fileId) } // TODO check inlineFileMode != IFMSent
|
||||
}
|
||||
if (!cItem.chatDir.sent && !cItem.isCall && !cItem.isMutedMemberEvent && (!isAppOnForeground(appContext) || chatModel.chatId.value != cInfo.id)) {
|
||||
if (cItem.showNotification && (!isAppOnForeground(appContext) || chatModel.chatId.value != cInfo.id)) {
|
||||
ntfManager.notifyMessageReceived(cInfo, cItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -988,7 +988,7 @@ func processReceivedMsg(_ res: ChatResponse) async {
|
||||
await receiveFile(fileId: file.fileId)
|
||||
}
|
||||
}
|
||||
if !cItem.chatDir.sent && !cItem.isCall && !cItem.isMutedMemberEvent {
|
||||
if cItem.showNotification {
|
||||
NtfManager.shared.notifyMessageReceived(cInfo, cItem)
|
||||
}
|
||||
case let .chatItemStatusUpdated(aChatItem):
|
||||
|
||||
@@ -232,7 +232,7 @@ func receivedMsgNtf(_ res: ChatResponse) async -> (String, UNMutableNotification
|
||||
cItem = apiReceiveFile(fileId: file.fileId, inline: inline)?.chatItem ?? cItem
|
||||
}
|
||||
}
|
||||
return cItem.isCall ? nil : (aChatItem.chatId, createMessageReceivedNtf(cInfo, cItem))
|
||||
return cItem.showMutableNotification ? (aChatItem.chatId, createMessageReceivedNtf(cInfo, cItem)) : nil
|
||||
case let .callInvitation(invitation):
|
||||
return (invitation.contact.id, createCallInvitationNtf(invitation))
|
||||
default:
|
||||
|
||||
@@ -1328,31 +1328,50 @@ public struct ChatItem: Identifiable, Decodable {
|
||||
}
|
||||
}
|
||||
|
||||
public var isCall: Bool {
|
||||
switch content {
|
||||
case .sndCall: return true
|
||||
case .rcvCall: return true
|
||||
default: return false
|
||||
}
|
||||
private var showNtfDir: Bool {
|
||||
return !chatDir.sent
|
||||
}
|
||||
|
||||
public var isMutedMemberEvent: Bool {
|
||||
public var showNotification: Bool {
|
||||
switch content {
|
||||
case let .rcvGroupEvent(event):
|
||||
switch event {
|
||||
case .groupUpdated: return true
|
||||
case .memberConnected: return true
|
||||
case .memberRole: return true
|
||||
case .userRole: return false
|
||||
case .userDeleted: return false
|
||||
case .groupDeleted: return false
|
||||
case .sndMsgContent: return showNtfDir
|
||||
case .rcvMsgContent: return showNtfDir
|
||||
case .sndDeleted: return showNtfDir
|
||||
case .rcvDeleted: return showNtfDir
|
||||
case .sndCall: return showNtfDir
|
||||
case .rcvCall: return false // notification is shown on .callInvitation instead
|
||||
case .rcvIntegrityError: return showNtfDir
|
||||
case .rcvGroupInvitation: return showNtfDir
|
||||
case .sndGroupInvitation: return showNtfDir
|
||||
case .rcvGroupEvent(rcvGroupEvent: let rcvGroupEvent):
|
||||
switch rcvGroupEvent {
|
||||
case .groupUpdated: return false
|
||||
case .memberConnected: return false
|
||||
case .memberRole: return false
|
||||
case .userRole: return showNtfDir
|
||||
case .userDeleted: return showNtfDir
|
||||
case .groupDeleted: return showNtfDir
|
||||
case .memberAdded: return false
|
||||
case .memberLeft: return false
|
||||
case .memberDeleted: return false
|
||||
case .invitedViaGroupLink: return false
|
||||
}
|
||||
case .sndGroupEvent: return true
|
||||
default: return false
|
||||
case .sndGroupEvent: return showNtfDir
|
||||
case .rcvConnEvent: return false
|
||||
case .sndConnEvent: return showNtfDir
|
||||
case .rcvChatFeature: return false
|
||||
case .sndChatFeature: return showNtfDir
|
||||
case .rcvGroupFeature: return false
|
||||
case .sndGroupFeature: return showNtfDir
|
||||
case .rcvChatFeatureRejected: return showNtfDir
|
||||
}
|
||||
}
|
||||
|
||||
public var showMutableNotification: Bool {
|
||||
switch content {
|
||||
case .rcvCall: return false
|
||||
case .rcvChatFeature: return false
|
||||
default: return showNtfDir
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user