GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
849 stars 204 forks source link

notification.removed_from_channel fails to decode event from event payload #2251

Closed AdamAexol closed 2 years ago

AdamAexol commented 2 years ago

What did you do?

I removed user from channel when that user was disconnected and logged out of the app.

What did you expect to happen?

After connecting that user again stream-chat should get event about removal from that channel and that channel should also disappear from that user's channel list.

What happened instead?

Stream-chat receives event about removal from the channel, but cannot handle that event. It fails on decoding event object

2022-08-23 15:39:47.646 [INFO] [com.apple.NSURLSession-delegate] [SyncRepository.swift:243] [syncMissingEvents(using:channelIds:isRecoveryRequest:completion:)] > Processing pending events. Count 1
2022-08-23 15:39:47.654 [ERROR] [com.apple.NSURLSession-delegate] [EventPayload.swift:176] [asEvents()] > Failed to decode event from event payload: 
-----EventPayload-----
     eventType: EventType(rawValue: "notification.removed_from_channel")
     connectionId: nil
     cid: Optional(group_chat:fZiaIB4w_group)
     currentUser: nil
     user: Optional(StreamChat.UserPayload)
     createdBy: nil
     memberContainer: Optional(StreamChat.MemberContainerPayload(member: nil, invite: nil, memberRole: nil))
     channel: nil
     message: nil
     reaction: nil
     watcherCount: nil
     unreadCount: nil
     createdAt: Optional(2022-08-23 13:30:32 +0000)
     isChannelHistoryCleared: nil
     banReason: nil
     banExpiredAt: nil
     parentId: nil
     hardDelete: false
, error: Error EventDecoding in /Users/adamgrabowski/Projects/ios-parlorsocial/ParlorSocial/Pods/StreamChat/Sources/StreamChat/WebSocketClient/Events/EventPayload.swift:160 -> `Swift.KeyPath<StreamChat.EventPayload, Swift.Optional<StreamChat.MemberPayload>>` field can't be `nil` for the `notification.removed_from_channel` event.
2022-08-23 15:39:47.668 [INFO] [NSManagedObjectContext 0x2827852b0] [SyncRepository.swift:277] [processMissingEventsPayload(_:completion:)] > Successfully processed pending events. Count 1

Probably member field in memberContainer is required and in this event it's nil. Also after launching app again, above message is still in logs, as if this event was hanging on the pending events list. Channel that user was removed from is still on user's channel list even after refreshing it manually, but trying to load messages from that channel returns error about missing permissions to that channel.

GetStream Environment

GetStream Chat version:4.20.0 GetStream Chat frameworks: StreamChat iOS version: 15.5 Swift version: 5 Xcode version: 13.4.1 **Device: iPhone 7 Plus

Additional context

nuno-vieira commented 2 years ago

Hi @AdamAexol!

Thanks for the issue report! I will investigate and get back to you as soon as possible 👍

Best, Nuno

nuno-vieira commented 2 years ago

Hi @AdamAexol,

It looks that indeed the member field is there, but it is not with the structure that the SDK is expecting, so the parsing fails. The backend will fix this, but we don't have an ETA for this at the moment, so meanwhile we will be adding a fallback in the SDK that should fix the problem 👍

We will let you know once this is released!

Best, Nuno

nuno-vieira commented 2 years ago

Hi!

This issue is now solved in the 4.21.1 release.

Thank you for your patience!

Best, Nuno