mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-20 07:01:40 +00:00
android: multiuser-notifications (#1846)
This commit is contained in:
@@ -1160,6 +1160,8 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
chatModel.updateContact(r.contact)
|
||||
chatModel.dismissConnReqView(r.contact.activeConn.id)
|
||||
chatModel.removeChat(r.contact.activeConn.id)
|
||||
}
|
||||
if (r.contact.directOrUsed) {
|
||||
ntfManager.notifyContactConnected(r.user, r.contact)
|
||||
}
|
||||
chatModel.setContactNetworkStatus(r.contact, NetworkStatus.Connected())
|
||||
@@ -1215,22 +1217,20 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
}
|
||||
}
|
||||
is CR.NewChatItem -> {
|
||||
if (!active(r.user)) {
|
||||
if (r.chatItem.chatItem.isRcvNew && r.chatItem.chatInfo.ntfsEnabled) {
|
||||
chatModel.increaseUnreadCounter(r.user)
|
||||
}
|
||||
return
|
||||
}
|
||||
val cInfo = r.chatItem.chatInfo
|
||||
val cItem = r.chatItem.chatItem
|
||||
chatModel.addChatItem(cInfo, cItem)
|
||||
if (active(r.user)) {
|
||||
chatModel.addChatItem(cInfo, cItem)
|
||||
} else if (cItem.isRcvNew && cInfo.ntfsEnabled) {
|
||||
chatModel.increaseUnreadCounter(r.user)
|
||||
}
|
||||
val file = cItem.file
|
||||
val mc = cItem.content.msgContent
|
||||
if (file != null && file.fileSize <= MAX_IMAGE_SIZE_AUTO_RCV) {
|
||||
val acceptImages = appPrefs.privacyAcceptImages.get()
|
||||
if ((mc is MsgContent.MCImage && acceptImages)
|
||||
|| (mc is MsgContent.MCVoice && ((file.fileSize > MAX_VOICE_SIZE_FOR_SENDING && acceptImages) || cInfo is ChatInfo.Group))) {
|
||||
withApi { receiveFile(file.fileId) } // TODO check inlineFileMode != IFMSent
|
||||
withApi { receiveFile(r.user, file.fileId) } // TODO check inlineFileMode != IFMSent
|
||||
}
|
||||
}
|
||||
if (cItem.showNotification && (!SimplexApp.context.isAppOnForeground || chatModel.chatId.value != cInfo.id)) {
|
||||
@@ -1238,22 +1238,17 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
}
|
||||
}
|
||||
is CR.ChatItemStatusUpdated -> {
|
||||
if (!active(r.user)) return
|
||||
|
||||
val cInfo = r.chatItem.chatInfo
|
||||
val cItem = r.chatItem.chatItem
|
||||
var res = false
|
||||
if (!cItem.isDeletedContent) {
|
||||
res = chatModel.upsertChatItem(cInfo, cItem)
|
||||
if (active(r.user) && !cItem.isDeletedContent && chatModel.upsertChatItem(cInfo, cItem)) {
|
||||
ntfManager.notifyMessageReceived(r.user, cInfo, cItem)
|
||||
}
|
||||
if (res) {
|
||||
if (!active(r.user) && !cItem.isDeletedContent) {
|
||||
ntfManager.notifyMessageReceived(r.user, cInfo, cItem)
|
||||
}
|
||||
}
|
||||
is CR.ChatItemUpdated ->
|
||||
if (active(r.user)) {
|
||||
chatItemSimpleUpdate(r.chatItem)
|
||||
}
|
||||
chatItemSimpleUpdate(r.user, r.chatItem)
|
||||
is CR.ChatItemDeleted -> {
|
||||
if (!active(r.user)) {
|
||||
if (r.toChatItem == null && r.deletedChatItem.chatItem.isRcvNew && r.deletedChatItem.chatInfo.ntfsEnabled) {
|
||||
@@ -1341,21 +1336,13 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
chatModel.updateGroup(r.toGroup)
|
||||
}
|
||||
is CR.RcvFileStart ->
|
||||
if (active(r.user)) {
|
||||
chatItemSimpleUpdate(r.chatItem)
|
||||
}
|
||||
chatItemSimpleUpdate(r.user, r.chatItem)
|
||||
is CR.RcvFileComplete ->
|
||||
if (active(r.user)) {
|
||||
chatItemSimpleUpdate(r.chatItem)
|
||||
}
|
||||
chatItemSimpleUpdate(r.user, r.chatItem)
|
||||
is CR.SndFileStart ->
|
||||
if (active(r.user)) {
|
||||
chatItemSimpleUpdate(r.chatItem)
|
||||
}
|
||||
chatItemSimpleUpdate(r.user, r.chatItem)
|
||||
is CR.SndFileComplete -> {
|
||||
if (!active(r.user)) return
|
||||
|
||||
chatItemSimpleUpdate(r.chatItem)
|
||||
chatItemSimpleUpdate(r.user, r.chatItem)
|
||||
val cItem = r.chatItem.chatItem
|
||||
val mc = cItem.content.msgContent
|
||||
val fileName = cItem.file?.fileName
|
||||
@@ -1427,11 +1414,11 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun receiveFile(fileId: Long) {
|
||||
suspend fun receiveFile(user: User, fileId: Long) {
|
||||
val inline = appPrefs.privacyTransferImagesInline.get()
|
||||
val chatItem = apiReceiveFile(fileId, inline)
|
||||
if (chatItem != null) {
|
||||
chatItemSimpleUpdate(chatItem)
|
||||
chatItemSimpleUpdate(user, chatItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1442,10 +1429,10 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun chatItemSimpleUpdate(aChatItem: AChatItem) {
|
||||
private suspend fun chatItemSimpleUpdate(user: User, aChatItem: AChatItem) {
|
||||
val cInfo = aChatItem.chatInfo
|
||||
val cItem = aChatItem.chatItem
|
||||
if (chatModel.upsertChatItem(cInfo, cItem)) {
|
||||
if (!active(user) || chatModel.upsertChatItem(cInfo, cItem)) {
|
||||
ntfManager.notifyMessageReceived(chatModel.currentUser.value!!, cInfo, cItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,10 @@ fun ChatView(chatId: String, chatModel: ChatModel, onComposed: () -> Unit) {
|
||||
}
|
||||
},
|
||||
receiveFile = { fileId ->
|
||||
withApi { chatModel.controller.receiveFile(fileId) }
|
||||
val user = chatModel.currentUser.value
|
||||
if (user != null) {
|
||||
withApi { chatModel.controller.receiveFile(user, fileId) }
|
||||
}
|
||||
},
|
||||
joinGroup = { groupId ->
|
||||
withApi { chatModel.controller.apiJoinGroup(groupId) }
|
||||
|
||||
Reference in New Issue
Block a user