Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Cannot cast between TCHChannelDescriptor and TCHChannel as code does #32

Open
kornha opened this issue Nov 27, 2018 · 4 comments
Open

Comments

@kornha
Copy link

kornha commented Nov 27, 2018

Hello,

I have followed the code closely and noticed what appears to me to be a problem, but I could be wrong and would love to be shown why. Specifically, in ChannelManager.swift

        channelsList?.userChannelDescriptors { result, paginator in
            self.channels?.addObjects(from: paginator!.items())
            self.sortChannels()
        }

Adds a list of TCHChannelDescriptor to self.channels.
However, if on this same list in MenuViewController.swift the following casts get called:

let channel = ChannelManager.sharedManager.channels![indexPath.row] as! AnyObject //works
let channel = ChannelManager.sharedManager.channels![indexPath.row] as! TCHChannelDescriptor //works
if let channel = ChannelManager.sharedManager.channels?.object(at: indexPath.row) as? TCHChannel // does NOT work unless a TCHChannel was independently added to the list!!

Furthermore, in ChannelManager.swift the following is called:

    func chatClient(_ client: TwilioChatClient, channelDeleted channel: TCHChannel) {
        DispatchQueue.main.async {
            if self.channels != nil {
                self.channels?.remove(channel)
            }
            self.delegate?.chatClient(client, channelDeleted: channel)
        }
        
    }

This will also NOT work if the channel in channels is of type TCHChannelDescriptor (which it will be if it is added from populateChannels())

I certainly hope I am missing something and this is not an enormous code oversight, so please let me know what I missed.

Thank you tons.

@jefflinwood
Copy link
Contributor

The code is unclear, and incorrect - I think what would make this much more approachable would be to rename the ChannelManager.sharedManager.channels as ChannelManager.sharedManager.channelDescriptors, to make the distinction between the TCHChannel and the TCHChannelDescriptor much more clear in the code.

@kornha
Copy link
Author

kornha commented Nov 28, 2018

Thank you for your reply.

I can make the distinction between the TCHChannel and TCHDescriptor set. However, in my (and my guess, most any) 'MenuTableView' cells, we need to fetch the most recent message to display on the cell. Furthermore, when deleting a channel from the Table, we will delete the TCHChannel, not the descriptor. Which means that, in a general use case we must fetch the TCHChannel. However, we cannot fetch the channels directly from the channelsList. Therefore, each time we fetch channels we must make 2 hops, which is unnecessary latency and slows down our app.

This is my assumption and I would love to be corrected so I can correct my approach.

@devlove1C
Copy link

devlove1C commented May 8, 2019

Hello @kwhinnery
I am facing a issue In chat implementation. My code is working properly but when i am sending message or receiving message the delegate method

func chatClient(_ client: TwilioChatClient, channel: TCHChannel, messageAdded message: TCHMessage) { 
}

called two times (Except this all delegate method called once)
Can you let me know the reason for this
Why its happening
Please Let me know if you have any idea about this issue

Thanks

@jefflinwood
Copy link
Contributor

@devlove1C - can you open another issue for this, and include some more code from your application that shows how you set the delegate?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants