stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

Pinnned Channels like whatsApp

Open SSaleemSSI opened this issue 3 years ago • 1 comments

What are you trying to achieve?

I am trying to pin channels i am able to pin them with custom extra data logic but i am unable to sort them to show them on top.

If possible, how can you achieve this currently?

I am maintaining a list of pinned channels in user extradata, we can also create a channel property if its is pinned or not like messages.

What would be the better way?

Creating a propert in channelDTO for pinned channel

GetStream Environment

GetStream Chat version: GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: Swift version: Xcode version: Device:

Additional context

SSaleemSSI avatar Aug 12 '22 10:08 SSaleemSSI

Hi @SSaleemSSI,

Thanks for reaching out. Currently we don't support sorting with parameters from the extraData as you can see from this discussion which would make that difficult. One quick approach that comes to mind would be in your custom implementation of ChatChannelListVC after having the channel controller loaded with the channels and before the collectionView loads, try to manually sort the channels into a new property defined by if they are pinned or not. Something like:

// have your custom way to extract that a channel is pinned from the extraData for instance in a property isPinned.

sortedChannels = controller.channels.sorted(by: { $0.isPinned && !$1.isPinned })

That way you should get a new array with the channels that are pinned at the beginning of the array and use this new array as your dataSource. You might have to be careful to properly sort the array again whenever the channel changes in the didChangeChannels delegate.

This is what quickly comes to mind that you could try.

Regards, Hugo

hugobernalstream avatar Aug 12 '22 19:08 hugobernalstream

Hi @SSaleemSSI,

As Hugo mentioned, this has already been answered here: https://github.com/GetStream/stream-chat-swift/discussions/2157#discussioncomment-3261262. The Chat API doesn't officially support this, but as mentioned in the comment, there is a workaround you can do if you are fine with exposing that information publicly.

Best, Nuno

nuno-vieira avatar Aug 16 '22 14:08 nuno-vieira

@hugobernalstream when you say "custom implementation of ChatChannelListVC after having the channel controller loaded with the channels and before the collectionView loads, try to manually sort the channels into a new property defined by if they are pinned or not"

In which function do i do this because i want to have my own array of channels so i can manipulate them? but i cant get an idea where do i assign this array to my custom array

muaviyaijaz123 avatar Sep 09 '22 08:09 muaviyaijaz123

Hi @muaviyaijaz123, for that you need to override the UICollectionViewDataSource protocol implementation and use your own array.

nuno-vieira avatar Sep 09 '22 13:09 nuno-vieira