Skip to content

Commit

Permalink
Add ChatChannel.isDisabled and disabled channel filtering key (#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
laevandus authored Jan 2, 2025
1 parent ffdeb91 commit be21a9e
Show file tree
Hide file tree
Showing 47 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

## StreamChat
### ✅ Added
- Add `FilterKey.disabled` and `ChatChannel.isDisabled` [#3546](https://github.com/GetStream/stream-chat-swift/pull/3546)
### 🐞 Fixed
- Remove the main thread requirement from the `DataStore` [#3541](https://github.com/GetStream/stream-chat-swift/pull/3541)
### ⚡ Performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public enum ChannelCodingKeys: String, CodingKey, CaseIterable {
case ownCapabilities = "own_capabilities"
/// A frozen flag.
case frozen
/// A disabled flag.
case disabled
/// Members.
case members
/// Invites.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ struct ChannelDetailPayload {
/// The list of actions that the current user can perform in a channel.
/// It is optional, since not all events contain the own capabilities property for performance reasons.
let ownCapabilities: [String]?
/// Checks if the channel is disabled.
let isDisabled: Bool
/// Checks if the channel is frozen.
let isFrozen: Bool
/// Checks if the channel is blocked.
Expand Down Expand Up @@ -173,6 +175,7 @@ extension ChannelDetailPayload: Decodable {
createdBy: try container.decodeIfPresent(UserPayload.self, forKey: .createdBy),
config: try container.decode(ChannelConfig.self, forKey: .config),
ownCapabilities: try container.decodeIfPresent([String].self, forKey: .ownCapabilities),
isDisabled: try container.decode(Bool.self, forKey: .disabled),
isFrozen: try container.decode(Bool.self, forKey: .frozen),
isBlocked: try container.decodeIfPresent(Bool.self, forKey: .blocked),
// For `hidden`, we don't fallback to `false`
Expand Down
3 changes: 3 additions & 0 deletions Sources/StreamChat/Database/DTOs/ChannelDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ChannelDTO: NSManagedObject {
// This field is also used to implement the `clearHistory` option when hiding the channel.
@NSManaged var truncatedAt: DBDate?

@NSManaged var isDisabled: Bool
@NSManaged var isHidden: Bool

@NSManaged var watcherCount: Int64
Expand Down Expand Up @@ -265,6 +266,7 @@ extension NSManagedObjectContext {
}
}

dto.isDisabled = payload.isDisabled
dto.isFrozen = payload.isFrozen

// Backend only returns a boolean
Expand Down Expand Up @@ -583,6 +585,7 @@ extension ChatChannel {
config: dto.config.asModel(),
ownCapabilities: Set(dto.ownCapabilities.compactMap(ChannelCapability.init(rawValue:))),
isFrozen: dto.isFrozen,
isDisabled: dto.isDisabled,
isBlocked: dto.isBlocked,
lastActiveMembers: members,
membership: membership,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B91" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24C101" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="AttachmentDTO" representedClassName="AttachmentDTO" syncable="YES">
<attribute name="data" attributeType="Binary"/>
<attribute name="id" attributeType="String"/>
Expand Down Expand Up @@ -46,6 +46,7 @@
<attribute name="extraData" attributeType="Binary"/>
<attribute name="imageURL" optional="YES" attributeType="URI"/>
<attribute name="isBlocked" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isDisabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isFrozen" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isHidden" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="lastMessageAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
Expand Down
6 changes: 6 additions & 0 deletions Sources/StreamChat/Models/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public struct ChatChannel {
///
public let isFrozen: Bool

/// Returns `true` if the channel is disabled.
public let isDisabled: Bool

/// Returns `true` if the channel is blocked.
///
/// It's not possible to send new messages to a blocked channel.
Expand Down Expand Up @@ -174,6 +177,7 @@ public struct ChatChannel {
config: ChannelConfig = .init(),
ownCapabilities: Set<ChannelCapability> = [],
isFrozen: Bool = false,
isDisabled: Bool = false,
isBlocked: Bool = false,
lastActiveMembers: [ChatChannelMember],
membership: ChatChannelMember? = nil,
Expand Down Expand Up @@ -204,6 +208,7 @@ public struct ChatChannel {
self.config = config
self.ownCapabilities = ownCapabilities
self.isFrozen = isFrozen
self.isDisabled = isDisabled
self.isBlocked = isBlocked
self.membership = membership
self.team = team
Expand Down Expand Up @@ -262,6 +267,7 @@ extension ChatChannel: Hashable {
guard lhs.extraData == rhs.extraData else { return false }
guard lhs.imageURL == rhs.imageURL else { return false }
guard lhs.isFrozen == rhs.isFrozen else { return false }
guard lhs.isDisabled == rhs.isDisabled else { return false }
guard lhs.isHidden == rhs.isHidden else { return false }
guard lhs.memberCount == rhs.memberCount else { return false }
guard lhs.membership == rhs.membership else { return false }
Expand Down
4 changes: 4 additions & 0 deletions Sources/StreamChat/Query/ChannelListQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public extension FilterKey where Scope: AnyChannelListFilterScope {
/// Supported operators: `equal`
static var frozen: FilterKey<Scope, Bool> { .init(rawValue: "frozen", keyPathString: #keyPath(ChannelDTO.isFrozen)) }

/// A filter key for querying disabled channels.
/// Supported operators: `equal`
static var disabled: FilterKey<Scope, Bool> { .init(rawValue: "disabled", keyPathString: #keyPath(ChannelDTO.isDisabled)) }

/// A filter key for matching the `blocked` value.
/// Supported operators: `equal`
static var blocked: FilterKey<Scope, Bool> { .init(rawValue: "blocked", keyPathString: #keyPath(ChannelDTO.isBlocked)) }
Expand Down
1 change: 1 addition & 0 deletions TestTools/StreamChatTestTools/Fixtures/JSONs/Channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@
"type" : "messaging",
"cid" : "messaging:general",
"frozen" : true,
"disabled" : true,
"cooldown" : 10,
"member_count" : 4,
"updated_at" : "2019-05-10T14:03:49.505006Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"type":"messaging",
"cid":"messaging:general",
"disabled" : false,
"frozen":true,
"cooldown":10,
"member_count":4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"type":"messaging",
"cid":"messaging:general",
"disabled" : false,
"frozen":true,
"cooldown":10,
"member_count":4,
Expand Down
20 changes: 20 additions & 0 deletions TestTools/StreamChatTestTools/Fixtures/JSONs/ChannelsQuery.json
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@
},
"type" : "messaging",
"cid" : "messaging:general",
"disabled" : false,
"frozen" : false,
"member_count" : 4,
"updated_at" : "2019-05-10T14:03:49.505006Z",
Expand Down Expand Up @@ -2349,6 +2350,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_8884",
"created_at" : "2019-12-12T15:41:05.022206Z",
Expand Down Expand Up @@ -3253,6 +3255,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_7487",
"created_at" : "2020-06-05T12:53:09.857739Z",
Expand Down Expand Up @@ -4262,6 +4265,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_1751",
"created_at" : "2020-06-08T11:57:36.660818Z",
Expand Down Expand Up @@ -5007,6 +5011,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_5000",
"created_at" : "2020-06-08T11:52:39.731147Z",
Expand Down Expand Up @@ -5355,6 +5360,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_3124",
"created_at" : "2020-06-08T11:51:12.271858Z",
Expand Down Expand Up @@ -5666,6 +5672,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_6264",
"created_at" : "2020-06-08T11:50:51.389239Z",
Expand Down Expand Up @@ -5983,6 +5990,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_7940",
"created_at" : "2020-06-08T11:49:28.886904Z",
Expand Down Expand Up @@ -6300,6 +6308,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "CD2595FE-985E-47A6-9E35-79F1A1AA7394",
"created_at" : "2020-06-06T02:32:06.86138Z",
Expand Down Expand Up @@ -7619,6 +7628,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_1877",
"created_at" : "2019-12-13T14:29:33.347005Z",
Expand Down Expand Up @@ -8033,6 +8043,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "31149B30-87CC-4FBF-B374-E9FFF3A044F6",
"created_at" : "2020-06-04T14:53:35.136401Z",
Expand Down Expand Up @@ -9369,6 +9380,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "new_channel_4371",
"created_at" : "2019-12-16T15:19:47.266902Z",
Expand Down Expand Up @@ -11146,6 +11158,7 @@
},
"type" : "messaging",
"cid" : "messaging:test-channel-3011",
"disabled" : false,
"frozen" : false,
"member_count" : 2,
"updated_at" : "2019-12-12T20:41:06.189203Z",
Expand Down Expand Up @@ -11599,6 +11612,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "7E76CBEF-BAD6-4713-BF3A-18FE4F4A750F",
"created_at" : "2020-05-18T02:33:45.567418Z",
Expand Down Expand Up @@ -11914,6 +11928,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "3713C2BC-F865-44FE-807F-85CD7175FCB2",
"created_at" : "2020-05-17T02:33:45.579961Z",
Expand Down Expand Up @@ -12126,6 +12141,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "ACAE4EC2-046C-4298-85EA-5A7E41C9CB6F",
"created_at" : "2020-05-17T02:33:12.370551Z",
Expand Down Expand Up @@ -12338,6 +12354,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "9E38A3E7-315C-441E-87CE-D65DEE26D390",
"created_at" : "2020-05-17T02:32:06.961529Z",
Expand Down Expand Up @@ -12653,6 +12670,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "F6756D54-1EB2-4075-9AB0-F3E4AA2A5EC6",
"created_at" : "2020-05-17T02:30:58.02951Z",
Expand Down Expand Up @@ -12987,6 +13005,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "A5DC9B6A-AB4A-493F-95A1-73409019F9EF",
"created_at" : "2020-05-15T12:15:28.677874Z",
Expand Down Expand Up @@ -13346,6 +13365,7 @@
"online" : true,
"name" : "broken-waterfall-5"
},
"disabled" : false,
"frozen" : false,
"id" : "BCC7555C-C3BE-438A-9791-CDB9B7B04C8E",
"created_at" : "2020-05-15T02:42:18.260686Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"type": "messaging",
"cid": "messaging:B1DFF9C5-E6A6-4BFA-9375-DC5E8C6852FF",
"created_by": null,
"disabled": false,
"frozen": false,
"config": {
"created_at": "2021-03-01T19:26:18.406502Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"type": "messaging",
"cid": "messaging:B1DFF9C5-E6A6-4BFA-9375-DC5E8C6852FF",
"created_by": null,
"disabled": false,
"frozen": false,
"config": {
"created_at": "2021-03-01T19:26:18.406502Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"type": "messaging",
"cid": "messaging:B1DFF9C5-E6A6-4BFA-9375-DC5E8C6852FF",
"created_by": null,
"disabled": false,
"frozen": false,
"config": {
"created_at": "2021-03-01T19:26:18.406502Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"type": "messaging",
"cid": "messaging:B1DFF9C5-E6A6-4BFA-9375-DC5E8C6852FF",
"created_by": null,
"disabled": false,
"frozen": false,
"config": {
"created_at": "2021-03-01T19:26:18.406502Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"type": "messaging",
"cid": "messaging:B1DFF9C5-E6A6-4BFA-9375-DC5E8C6852FF",
"created_by": null,
"disabled": false,
"frozen": false,
"config": {
"created_at": "2021-03-01T19:26:18.406502Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"updated_at": "2021-04-15T11:23:42.167781Z",
"deleted_at": "2021-04-23T09:38:47.125555Z",
"created_by": null,
"disabled" : false,
"frozen": false,
"members": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"created_by" : null,
"type" : "messaging",
"cid" : "messaging:default-channel-6",
"disabled" : false,
"frozen" : false,
"member_count" : 16,
"updated_at" : "2021-04-15T11:26:37.184658Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
"created_by" : null,
"type" : "messaging",
"cid" : "messaging:default-channel-6",
"disabled" : false,
"frozen" : false,
"member_count" : 16,
"updated_at" : "2021-04-15T11:26:37.184658Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"channel" : {
"created_by" : null,
"truncated_at" : "2022-02-16T08:20:13.862494Z",
"disabled" : false,
"frozen" : false,
"config" : {
"typing_events" : true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"disabled" : false,
"type" : "messaging",
"cid" : "messaging:8372DE11-E",
"disabled" : false,
"frozen" : false,
"member_count" : 2,
"updated_at" : "2022-02-16T08:20:13.865089Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
},
"type" : "messaging",
"cid" : "messaging:new_channel_7070",
"disabled" : false,
"frozen" : false,
"member_count" : 2,
"updated_at" : "2020-07-17T11:44:16.63728Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
},
"type" : "messaging",
"cid" : "messaging:new_channel_7070",
"disabled" : false,
"frozen" : false,
"member_count" : 2,
"updated_at" : "2020-07-17T11:44:16.63728Z",
Expand Down
Loading

0 comments on commit be21a9e

Please sign in to comment.