Skip to content

Commit fa38d7a

Browse files
authored
Add support for filter tags in channels (#3886)
1 parent 7e59297 commit fa38d7a

File tree

33 files changed

+261
-11
lines changed

33 files changed

+261
-11
lines changed

.swiftlint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ file_name_no_space:
6767

6868
cyclomatic_complexity:
6969
ignores_case_statements: true
70-
warning: 25
71-
error: 30
70+
warning: 30
71+
error: 35
7272

7373
custom_rules:
7474
regular_constraints_forbidden:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
- Add `ChatClient.deleteAttachment(remoteUrl:)` [#3883](https://github.com/GetStream/stream-chat-swift/pull/3883)
1010
- Add `CDNClient.deleteAttachment(remoteUrl:)` [#3883](https://github.com/GetStream/stream-chat-swift/pull/3883)
1111
- Add `heic`, `heif` and `svg` formats to the supported image file types [#3883](https://github.com/GetStream/stream-chat-swift/pull/3883)
12+
- Add support for filter tags in channels [#3886](https://github.com/GetStream/stream-chat-swift/pull/3886)
13+
- Add `ChatChannel.filterTags`
14+
- Add `filterTags` channel list filtering key
15+
- Add `filterTags` argument to `ChatChannelController` and `Chat` factory methods in `ChatClient`
16+
- Add `filterTags` argument to `ChatChannelController.updateChannel` and `ChatChannelController.partialUpdateChannel`
17+
- Add `filterTags` argument to `Chat.update` and `Chat.updatePartial`
1218
### 🐞 Fixed
1319
- Fix rare crash in `WebSocketClient.connectEndpoint` [#3882](https://github.com/GetStream/stream-chat-swift/pull/3882)
1420
- Fix audio recordings not playing from AirPods automatically [#3884](https://github.com/GetStream/stream-chat-swift/pull/3884)

DemoApp/StreamChat/Components/DemoChatChannelListRouter.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ final class DemoChatChannelListRouter: ChatChannelListRouter {
477477
}
478478
}
479479
}),
480+
.init(title: "Add Premium Tag", isEnabled: canUpdateChannel, handler: { [unowned self] _ in
481+
channelController.partialChannelUpdate(filterTags: ["premium"]) { error in
482+
if let error = error {
483+
self.rootViewController.presentAlert(title: "Couldn't make the channel \(cid) premium", message: "\(error)")
484+
}
485+
}
486+
}),
487+
480488
.init(title: "Unmute channel", isEnabled: canMuteChannel, handler: { [unowned self] _ in
481489
channelController.unmuteChannel { error in
482490
if let error = error {

DemoApp/StreamChat/Components/DemoChatChannelListVC.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ final class DemoChatChannelListVC: ChatChannelListVC {
107107
lazy var equalMembersQuery: ChannelListQuery = .init(filter:
108108
.equal(.members, values: [currentUserId, "r2-d2"])
109109
)
110+
111+
lazy var premiumTaggedChannelsQuery: ChannelListQuery = .init(filter: .in(.filterTags, values: ["premium"]))
110112

111113
var demoRouter: DemoChatChannelListRouter? {
112114
router as? DemoChatChannelListRouter
@@ -256,6 +258,15 @@ final class DemoChatChannelListVC: ChatChannelListVC {
256258
self?.title = "R2-D2 Channels (Equal Members)"
257259
self?.setEqualMembersChannelsQuery()
258260
}
261+
262+
let taggedChannelsAction = UIAlertAction(
263+
title: "Premium Tagged Channels",
264+
style: .default,
265+
handler: { [weak self] _ in
266+
self?.title = "Premium Tagged Channels"
267+
self?.setPremiumTaggedChannelsQuery()
268+
}
269+
)
259270

260271
presentAlert(
261272
title: "Filter Channels",
@@ -271,7 +282,8 @@ final class DemoChatChannelListVC: ChatChannelListVC {
271282
pinnedChannelsAction,
272283
archivedChannelsAction,
273284
equalMembersAction,
274-
channelRoleChannelsAction
285+
channelRoleChannelsAction,
286+
taggedChannelsAction
275287
].sorted(by: { $0.title ?? "" < $1.title ?? "" }),
276288
preferredStyle: .actionSheet,
277289
sourceView: filterChannelsButton
@@ -327,6 +339,10 @@ final class DemoChatChannelListVC: ChatChannelListVC {
327339
func setEqualMembersChannelsQuery() {
328340
replaceQuery(equalMembersQuery)
329341
}
342+
343+
func setPremiumTaggedChannelsQuery() {
344+
replaceQuery(premiumTaggedChannelsQuery)
345+
}
330346

331347
func setInitialChannelsQuery() {
332348
replaceQuery(initialQuery)

Sources/StreamChat/APIClient/Endpoints/Payloads/ChannelCodingKeys.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public enum ChannelCodingKeys: String, CodingKey, CaseIterable {
4242
case members
4343
/// Invites.
4444
case invites
45+
case filterTags = "filter_tags"
4546
/// The team the channel belongs to.
4647
case team
4748
case memberCount = "member_count"

Sources/StreamChat/APIClient/Endpoints/Payloads/ChannelEditDetailPayload.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct ChannelEditDetailPayload: Encodable {
1212
let team: String?
1313
let members: Set<UserId>
1414
let invites: Set<UserId>
15+
let filterTags: Set<String>
1516
let extraData: [String: RawJSON]
1617

1718
init(
@@ -21,6 +22,7 @@ struct ChannelEditDetailPayload: Encodable {
2122
team: String?,
2223
members: Set<UserId>,
2324
invites: Set<UserId>,
25+
filterTags: Set<String>,
2426
extraData: [String: RawJSON]
2527
) {
2628
id = cid.id
@@ -30,6 +32,7 @@ struct ChannelEditDetailPayload: Encodable {
3032
self.team = team
3133
self.members = members
3234
self.invites = invites
35+
self.filterTags = filterTags
3336
self.extraData = extraData
3437
}
3538

@@ -40,6 +43,7 @@ struct ChannelEditDetailPayload: Encodable {
4043
team: String?,
4144
members: Set<UserId>,
4245
invites: Set<UserId>,
46+
filterTags: Set<String>,
4347
extraData: [String: RawJSON]
4448
) {
4549
id = nil
@@ -49,6 +53,7 @@ struct ChannelEditDetailPayload: Encodable {
4953
self.team = team
5054
self.members = members
5155
self.invites = invites
56+
self.filterTags = filterTags
5257
self.extraData = extraData
5358
}
5459

@@ -63,6 +68,10 @@ struct ChannelEditDetailPayload: Encodable {
6368
allMembers = allMembers.union(invites)
6469
try container.encode(invites, forKey: .invites)
6570
}
71+
72+
if !filterTags.isEmpty {
73+
try container.encode(filterTags, forKey: .filterTags)
74+
}
6675

6776
if !allMembers.isEmpty {
6877
try container.encode(allMembers, forKey: .members)

Sources/StreamChat/APIClient/Endpoints/Payloads/ChannelListPayload.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct ChannelDetailPayload {
127127
let createdBy: UserPayload?
128128
/// A config.
129129
let config: ChannelConfig
130+
let filterTags: [String]?
130131
/// The list of actions that the current user can perform in a channel.
131132
/// It is optional, since not all events contain the own capabilities property for performance reasons.
132133
let ownCapabilities: [String]?
@@ -188,6 +189,7 @@ extension ChannelDetailPayload: Decodable {
188189
truncatedAt: try container.decodeIfPresent(Date.self, forKey: .truncatedAt),
189190
createdBy: try container.decodeIfPresent(UserPayload.self, forKey: .createdBy),
190191
config: try container.decode(ChannelConfig.self, forKey: .config),
192+
filterTags: try container.decodeIfPresent([String].self, forKey: .filterTags),
191193
ownCapabilities: try container.decodeIfPresent([String].self, forKey: .ownCapabilities),
192194
isDisabled: try container.decode(Bool.self, forKey: .disabled),
193195
isFrozen: try container.decode(Bool.self, forKey: .frozen),

Sources/StreamChat/Controllers/ChannelController/ChannelController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
253253
/// - team: New team.
254254
/// - members: New members.
255255
/// - invites: New invites.
256+
/// - filterTags: A list of tags to add to the channel.
256257
/// - extraData: New `ExtraData`.
257258
/// - completion: The completion. Will be called on a **callbackQueue** when the network request is finished.
258259
/// If request fails, the completion will be called with an error.
@@ -263,6 +264,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
263264
team: String?,
264265
members: Set<UserId> = [],
265266
invites: Set<UserId> = [],
267+
filterTags: Set<String> = [],
266268
extraData: [String: RawJSON] = [:],
267269
completion: ((Error?) -> Void)? = nil
268270
) {
@@ -279,6 +281,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
279281
team: team,
280282
members: members,
281283
invites: invites,
284+
filterTags: filterTags,
282285
extraData: extraData
283286
)
284287

@@ -295,6 +298,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
295298
/// - team: New team.
296299
/// - members: New members.
297300
/// - invites: New invites.
301+
/// - filterTags: A list of tags to add to the channel.
298302
/// - extraData: New `ExtraData`.
299303
/// - unsetProperties: Properties from the channel that are going to be cleared/unset.
300304
/// - completion: The completion. Will be called on a **callbackQueue** when the network request is finished.
@@ -306,6 +310,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
306310
team: String? = nil,
307311
members: Set<UserId> = [],
308312
invites: Set<UserId> = [],
313+
filterTags: Set<String> = [],
309314
extraData: [String: RawJSON] = [:],
310315
unsetProperties: [String] = [],
311316
completion: ((Error?) -> Void)? = nil
@@ -323,6 +328,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
323328
team: team,
324329
members: members,
325330
invites: invites,
331+
filterTags: filterTags,
326332
extraData: extraData
327333
)
328334

Sources/StreamChat/Controllers/ChannelController/ChatClient+ChannelController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public extension ChatClient {
6565
/// - isCurrentUserMember: If set to `true` the current user will be included into the channel. Is `true` by default.
6666
/// - messageOrdering: Describes the ordering the messages are presented.
6767
/// - invites: IDs for the new channel invitees.
68+
/// - filterTags: A list of tags to add to the channel.
6869
/// - extraData: Extra data for the new channel.
6970
/// - channelListQuery: The channel list query the channel this controller represents is part of.
7071
/// - Throws: `ClientError.CurrentUserDoesNotExist` if there is no currently logged-in user.
@@ -78,6 +79,7 @@ public extension ChatClient {
7879
isCurrentUserMember: Bool = true,
7980
messageOrdering: MessageOrdering = .topToBottom,
8081
invites: Set<UserId> = [],
82+
filterTags: Set<String> = [],
8183
extraData: [String: RawJSON] = [:],
8284
channelListQuery: ChannelListQuery? = nil
8385
) throws -> ChatChannelController {
@@ -92,6 +94,7 @@ public extension ChatClient {
9294
team: team,
9395
members: members.union(isCurrentUserMember ? [currentUserId] : []),
9496
invites: invites,
97+
filterTags: filterTags,
9598
extraData: extraData
9699
)
97100

@@ -119,6 +122,7 @@ public extension ChatClient {
119122
/// - name: The new channel name.
120123
/// - imageURL: The new channel avatar URL.
121124
/// - team: Team for the new channel.
125+
/// - filterTags: A list of tags to add to the channel.
122126
/// - extraData: Extra data for the new channel.
123127
/// - channelListQuery: The channel list query the channel this controller represents is part of.
124128
///
@@ -134,6 +138,7 @@ public extension ChatClient {
134138
name: String? = nil,
135139
imageURL: URL? = nil,
136140
team: String? = nil,
141+
filterTags: Set<String> = [],
137142
extraData: [String: RawJSON],
138143
channelListQuery: ChannelListQuery? = nil
139144
) throws -> ChatChannelController {
@@ -147,6 +152,7 @@ public extension ChatClient {
147152
team: team,
148153
members: members.union(isCurrentUserMember ? [currentUserId] : []),
149154
invites: [],
155+
filterTags: filterTags,
150156
extraData: extraData
151157
)
152158
return .init(

Sources/StreamChat/Controllers/ChannelController/LivestreamChannelController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ public class LivestreamChannelController: DataStoreProvider, EventsControllerDel
11391139
isHidden: event.channel.isHidden,
11401140
createdBy: event.channel.createdBy,
11411141
config: event.channel.config,
1142+
filterTags: event.channel.filterTags,
11421143
ownCapabilities: event.channel.ownCapabilities,
11431144
isFrozen: event.channel.isFrozen,
11441145
isDisabled: event.channel.isDisabled,

0 commit comments

Comments
 (0)