GetStream / stream-chat-swiftui

SwiftUI Chat SDK ➜ Stream Chat 💬
https://getstream.io/chat/sdk/swiftui/
Other
346 stars 86 forks source link

Default delete action for channel is looking up wrong ID #310

Closed mkhandium closed 1 year ago

mkhandium commented 1 year ago

What did you do?

Swiped left on a channel. Tapped the delete button.

What did you expect to happen?

Delete the channel.

What happened instead?

Got an error with the message

API request failed with status code: 404, code: 16 response:
{
  "code" : 16,
  "message" : "DeleteChannel failed with error: \"Can't find channel with id messaging:3601A866-9E03-4624-8959-588CFDF84A9C\"",
  "more_info" : "https:\/\/getstream.io\/chat\/docs\/api_errors_response",
  "details" : [

  ],
  "StatusCode" : 404,
  "duration" : "0.00ms"
})

This channel was created with type .livestream so I am not sure why the id has messaging in it.

GetStream Environment

GetStream Chat version: Latest main GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 16.4 Swift version: 5 Xcode version: 14.3 Device: iPhone 14 Pro Simulator

Additional context

The UUID string here is correct, but the appended type to the id is wrong when deleting a channel with the default delete action.

FYI Deleting a conversation uses the proper cid if you access it from the more menu, instead of using the trailing delete action button.

Found the related code in the ChatChannelListViewModel

public func delete(channel: ChatChannel) {
        let controller = chatClient.channelController(
            for: .init(type: .messaging, id: channel.cid.id)
        )

        controller.deleteChannel { [weak self] error in
            if error != nil {
                // handle error
                self?.channelAlertType = .error
            }
        }
    }

The type is hardcoded to be messaging instead of the channel's actual ChannelType. Opening up a PR for this

martinmitrevski commented 1 year ago

Thanks again for the PR that solves this issue 👍