Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIS-2184] Ignore channel.created events #2314

Merged
merged 5 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Do not mark channels as read when the controller is not on screen [#2288](https://github.com/GetStream/stream-chat-swift/pull/2288)
- Do not show old messages not belonging to the history when paginating [#2298](https://github.com/GetStream/stream-chat-swift/pull/2298)). Caveat: [Explained here](https://github.com/GetStream/stream-chat-swift/pull/2298)
- Fix logic to determine errors related to connectivity [#2311](https://github.com/GetStream/stream-chat-swift/pull/2311)
- Stop logging false positive errors for 'channel.created' events [#2314](https://github.com/GetStream/stream-chat-swift/pull/2314)

## StreamChatUI
### ✅ Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct EventDecoder {
return try decoder.decode(UnknownChannelEvent.self, from: data)
} catch is ClientError.UnknownUserEvent {
return try decoder.decode(UnknownUserEvent.self, from: data)
} catch let error as ClientError.UnsupportedEventType {
throw error
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ extension Array where Element == EventPayload {
do {
return try $0.event()
} catch {
log.error("Failed to decode event from event payload: \($0), error: \(error)")
if error is ClientError.UnsupportedEventType {
log.info("Skipping unsupported event type: \($0.eventType)")
} else {
log.error("Failed to decode event from event payload: \($0), error: \(error)")
}
return nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/StreamChat/WebSocketClient/Events/EventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public extension EventType {

// MARK: Channel Events

/// When a channel was updated.
static let channelCreated: Self = "channel.created"
/// When a channel was updated.
static let channelUpdated: Self = "channel.updated"
/// When a channel was deleted.
Expand Down Expand Up @@ -120,6 +122,7 @@ extension EventType {
case .userBanned: return try UserBannedEventDTO(from: response)
case .userUnbanned: return try UserUnbannedEventDTO(from: response)

case .channelCreated: throw ClientError.UnsupportedEventType()
polqf marked this conversation as resolved.
Show resolved Hide resolved
case .channelUpdated: return try ChannelUpdatedEventDTO(from: response)
case .channelDeleted: return try ChannelDeletedEventDTO(from: response)
case .channelHidden: return try ChannelHiddenEventDTO(from: response)
Expand Down
1 change: 0 additions & 1 deletion Sources/StreamChat/WebSocketClient/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ extension WebSocketClient: WebSocketEngineDelegate {
}
} catch is ClientError.UnsupportedEventType {
log.info("Skipping unsupported event type with payload: \(message)", subsystems: .webSocket)

} catch {
// Check if the message contains an error object from the server
let webSocketError = message
Expand Down
4 changes: 4 additions & 0 deletions StreamChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@
C152F5FE27C65C18003B4805 /* MessageRepository_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C152F5FD27C65C18003B4805 /* MessageRepository_Tests.swift */; };
C15C8838286C7BF300E6A72C /* BackgroundListDatabaseObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C15C8837286C7BF300E6A72C /* BackgroundListDatabaseObserver.swift */; };
C15C8839286C7BF300E6A72C /* BackgroundListDatabaseObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C15C8837286C7BF300E6A72C /* BackgroundListDatabaseObserver.swift */; };
C1616DB428DC9F0B00FF993B /* ChannelCreated.json in Resources */ = {isa = PBXBuildFile; fileRef = C1616DB328DC9F0B00FF993B /* ChannelCreated.json */; };
C171041E2768C34E008FB3F2 /* Array+SafeSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = C171041D2768C34E008FB3F2 /* Array+SafeSubscript.swift */; };
C171041F2768C34E008FB3F2 /* Array+SafeSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = C171041D2768C34E008FB3F2 /* Array+SafeSubscript.swift */; };
C173538E27D9F804008AC412 /* KeyedDecodingContainer+Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = C173538D27D9F804008AC412 /* KeyedDecodingContainer+Array.swift */; };
Expand Down Expand Up @@ -3348,6 +3349,7 @@
C152F5FB27C3DC53003B4805 /* MessageRepository_Spy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRepository_Spy.swift; sourceTree = "<group>"; };
C152F5FD27C65C18003B4805 /* MessageRepository_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRepository_Tests.swift; sourceTree = "<group>"; };
C15C8837286C7BF300E6A72C /* BackgroundListDatabaseObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundListDatabaseObserver.swift; sourceTree = "<group>"; };
C1616DB328DC9F0B00FF993B /* ChannelCreated.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ChannelCreated.json; sourceTree = "<group>"; };
C171041D2768C34E008FB3F2 /* Array+SafeSubscript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SafeSubscript.swift"; sourceTree = "<group>"; };
C173538D27D9F804008AC412 /* KeyedDecodingContainer+Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyedDecodingContainer+Array.swift"; sourceTree = "<group>"; };
C174E0F5284DFA5A0040B936 /* IdentifiablePayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiablePayload.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4919,6 +4921,7 @@
A3B0CFA327BCF66A00F352F9 /* ChannelTruncated_with_message.json */,
79158CE125F0E9DF00186102 /* ChannelTruncated.json */,
79433799260E04AF0094471F /* ChannelUpdated_ServerSide.json */,
C1616DB328DC9F0B00FF993B /* ChannelCreated.json */,
8A0C3BCB24C1C6AB00CAFD19 /* ChannelUpdated.json */,
E7DB9F372632B6500090D9C7 /* ChannelVisible.json */,
);
Expand Down Expand Up @@ -8246,6 +8249,7 @@
A311B42427E8B9CE00CFCF6D /* MessageReactionPayload+NoExtraData.json in Resources */,
A311B41E27E8B9C400CFCF6D /* FlagUserPayload+DefaultExtraData.json in Resources */,
A311B41927E8B9B900CFCF6D /* UserUpdated.json in Resources */,
C1616DB428DC9F0B00FF993B /* ChannelCreated.json in Resources */,
A311B3F927E8B9A800CFCF6D /* MessageRead+MissingUnreadCount.json in Resources */,
A311B40927E8B9AD00CFCF6D /* NotificationChannelMutesUpdatedWithNoMutedChannels.json in Resources */,
A311B3CF27E8B98C00CFCF6D /* MutedChannelPayload.json in Resources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type" : "channel.created",
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ final class ChannelEvents_Tests: XCTestCase {
super.tearDown()
eventDecoder = nil
}

func test_created() throws {
let json = XCTestCase.mockData(fromJSONFile: "ChannelCreated")
do {
_ = try eventDecoder.decode(from: json)
XCTFail("Should not be able to decode it")
} catch {
XCTAssertTrue(error is ClientError.UnsupportedEventType)
}
}

func test_updated() throws {
let json = XCTestCase.mockData(fromJSONFile: "ChannelUpdated")
Expand Down