浏览代码

Merge pull request #1217 from deltachat/notification_archived_chats

Notification archived chats
cyBerta 4 年之前
父节点
当前提交
aa64087c59

+ 1 - 0
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -420,6 +420,7 @@ class ContactDetailViewController: UITableViewController {
             return
             return
         }
         }
         viewModel.context.deleteChat(chatId: viewModel.chatId)
         viewModel.context.deleteChat(chatId: viewModel.chatId)
+        NotificationManager.removeNotificationsForChat(chatId: viewModel.chatId)
 
 
         // just pop to viewControllers - we've in chatlist or archive then
         // just pop to viewControllers - we've in chatlist or archive then
         // (no not use `navigationController?` here: popping self will make the reference becoming nil)
         // (no not use `navigationController?` here: popping self will make the reference becoming nil)

+ 4 - 0
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -255,6 +255,9 @@ class GroupChatDetailViewController: UIViewController {
 
 
     private func toggleArchiveChat() {
     private func toggleArchiveChat() {
         let archivedBefore = chat.isArchived
         let archivedBefore = chat.isArchived
+        if (!archivedBefore) {
+            NotificationManager.removeNotificationsForChat(chatId: chatId)
+        }
         dcContext.archiveChat(chatId: chat.id, archive: !archivedBefore)
         dcContext.archiveChat(chatId: chat.id, archive: !archivedBefore)
         if archivedBefore {
         if archivedBefore {
             archiveChatCell.actionTitle = String.localized("menu_archive_chat")
             archiveChatCell.actionTitle = String.localized("menu_archive_chat")
@@ -327,6 +330,7 @@ class GroupChatDetailViewController: UIViewController {
 
 
     private func deleteChat() {
     private func deleteChat() {
         dcContext.deleteChat(chatId: chatId)
         dcContext.deleteChat(chatId: chatId)
+        NotificationManager.removeNotificationsForChat(chatId: chatId)
 
 
         // just pop to viewControllers - we've in chatlist or archive then
         // just pop to viewControllers - we've in chatlist or archive then
         // (no not use `navigationController?` here: popping self will make the reference becoming nil)
         // (no not use `navigationController?` here: popping self will make the reference becoming nil)

+ 5 - 1
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -182,7 +182,11 @@ class ChatListViewModel: NSObject {
 
 
     func archiveChatToggle(chatId: Int) {
     func archiveChatToggle(chatId: Int) {
         let chat = dcContext.getChat(chatId: chatId)
         let chat = dcContext.getChat(chatId: chatId)
-        dcContext.archiveChat(chatId: chatId, archive: !chat.isArchived)
+        let isArchivedBefore = chat.isArchived
+        if (!isArchivedBefore) {
+            NotificationManager.removeNotificationsForChat(chatId: chatId)
+        }
+        dcContext.archiveChat(chatId: chatId, archive: !isArchivedBefore)
         updateChatList(notifyListener: false)
         updateChatList(notifyListener: false)
     }
     }
 
 

+ 5 - 1
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -164,7 +164,11 @@ class ContactDetailViewModel {
             safe_fatalError("there is no chatId - you are probably are calling this from ContactDetail - this should be only called from ChatDetail")
             safe_fatalError("there is no chatId - you are probably are calling this from ContactDetail - this should be only called from ChatDetail")
             return false
             return false
         }
         }
-        context.archiveChat(chatId: chatId, archive: !chatIsArchived)
+        let isArchivedBefore = chatIsArchived
+        if !isArchivedBefore {
+            NotificationManager.removeNotificationsForChat(chatId: chatId)
+        }
+        context.archiveChat(chatId: chatId, archive: !isArchivedBefore)
         return chatIsArchived
         return chatIsArchived
     }
     }
 }
 }