From d0b66dd33bd3ad2b61feab9a09a7aafb1921182a Mon Sep 17 00:00:00 2001 From: Pavel Anokhov Date: Thu, 28 Jun 2018 14:41:14 +0300 Subject: [PATCH] Filtering out hidden chatrooms. --- .../Services/DataProviders/AdamantChatsProvider.swift | 9 +++++++-- Adamant/Stories/Chats/ChatListViewController.swift | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Adamant/Services/DataProviders/AdamantChatsProvider.swift b/Adamant/Services/DataProviders/AdamantChatsProvider.swift index 3f6a4152c..7072e5f4e 100644 --- a/Adamant/Services/DataProviders/AdamantChatsProvider.swift +++ b/Adamant/Services/DataProviders/AdamantChatsProvider.swift @@ -553,7 +553,9 @@ extension AdamantChatsProvider { let request: NSFetchRequest = NSFetchRequest(entityName: Chatroom.entityName) request.sortDescriptors = [NSSortDescriptor(key: "updatedAt", ascending: false), NSSortDescriptor(key: "title", ascending: true)] - request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [NSPredicate(format: "partner!=nil"), NSPredicate(format: "isHidden = false")]) + request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [ + NSPredicate(format: "partner!=nil"), + NSPredicate(format: "isHidden = false")]) let controller = NSFetchedResultsController(fetchRequest: request, managedObjectContext: stack.container.viewContext, sectionNameKeyPath: nil, cacheName: nil) return controller @@ -575,7 +577,10 @@ extension AdamantChatsProvider { func getUnreadMessagesController() -> NSFetchedResultsController { let request = NSFetchRequest(entityName: "ChatTransaction") - request.predicate = NSPredicate(format: "isUnread == true") + request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [ + NSPredicate(format: "isUnread == true"), + NSPredicate(format: "chatroom.isHidden == false")]) + request.sortDescriptors = [NSSortDescriptor.init(key: "date", ascending: false), NSSortDescriptor(key: "transactionId", ascending: false)] diff --git a/Adamant/Stories/Chats/ChatListViewController.swift b/Adamant/Stories/Chats/ChatListViewController.swift index 12a993852..b88b7a938 100644 --- a/Adamant/Stories/Chats/ChatListViewController.swift +++ b/Adamant/Stories/Chats/ChatListViewController.swift @@ -417,7 +417,7 @@ extension ChatListViewController { private func showNotification(for transaction: ChatTransaction) { // MARK: 1. Show notification only for incomming transactions guard !transaction.silentNotification, !transaction.isOutgoing, - let chatroom = transaction.chatroom, chatroom != presentedChatroom(), + let chatroom = transaction.chatroom, chatroom != presentedChatroom(), !chatroom.isHidden, let partner = chatroom.partner else { return }