Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit 0bf836e

Browse files
authored
Merge pull request #2034 from Sameesunkaria/1982-sorting-should-not-repeat-subscriptions
[FIX] Subscriptions should not repeat when they are grouped by type
2 parents 8c9d840 + 7de4f5a commit 0bf836e

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

Rocket.Chat/Controllers/Subscriptions/SubscriptionsList/SubscriptionsViewModel.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,37 @@ class SubscriptionsViewModel {
7777

7878
API.current()?.client(SpotlightClient.self).search(query: query) { _, _ in }
7979
case .notSearching:
80+
var queryItems = queryBase
81+
82+
func filtered(using predicateFormat: String) -> Results<Subscription> {
83+
let predicate = NSPredicate(format: predicateFormat)
84+
let filteredResult = queryItems.filter(predicate)
85+
queryItems = queryItems.filter(predicate.negation)
86+
return filteredResult
87+
}
88+
8089
if SubscriptionsSortingManager.selectedGroupingOptions.contains(.unread) {
81-
let queryData = queryBase.filter("alert == true")
90+
let queryData = filtered(using: "alert == true")
8291
assorter.registerSection(name: localized("subscriptions.unreads"), objects: queryData)
8392
}
8493

8594
if SubscriptionsSortingManager.selectedGroupingOptions.contains(.favorites) {
86-
let queryData = queryBase.filter("favorite == true")
95+
let queryData = filtered(using: "favorite == true")
8796
assorter.registerSection(name: localized("subscriptions.favorites"), objects: queryData)
8897
}
8998

9099
if SubscriptionsSortingManager.selectedGroupingOptions.contains(.type) {
91-
let queryDataChannels = queryBase.filter("privateType == 'c'")
100+
let queryDataChannels = filtered(using: "privateType == 'c'")
92101
assorter.registerSection(name: localized("subscriptions.channels"), objects: queryDataChannels)
93102

94-
let queryDataGroups = queryBase.filter("privateType == 'p'")
103+
let queryDataGroups = filtered(using: "privateType == 'p'")
95104
assorter.registerSection(name: localized("subscriptions.groups"), objects: queryDataGroups)
96105

97-
let queryDataDirectMessages = queryBase.filter("privateType == 'd'")
106+
let queryDataDirectMessages = filtered(using: "privateType == 'd'")
98107
assorter.registerSection(name: localized("subscriptions.direct_messages"), objects: queryDataDirectMessages)
99108
} else {
100109
let title = assorter.numberOfSections > 0 ? localized("subscriptions.conversations") : ""
101-
assorter.registerSection(name: title, objects: queryBase)
110+
assorter.registerSection(name: title, objects: queryItems)
102111
}
103112
}
104113
}
@@ -139,3 +148,9 @@ extension SubscriptionsViewModel {
139148
}
140149

141150
}
151+
152+
private extension NSPredicate {
153+
var negation: NSPredicate {
154+
return NSCompoundPredicate(notPredicateWithSubpredicate: self)
155+
}
156+
}

0 commit comments

Comments
 (0)