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

Allow developers to filter message list

Open virbedi opened this issue 3 years ago • 6 comments

What are you trying to achieve?

We are trying to hide/show threaded replies sent to the main channel based on a boolean flag.

If possible, how can you achieve this currently?

We are checking the content of each message and passing empty layoutOptions for ones we should hide. This affects scroll performance and does not always provide clean hide/show views of the channel.

What would be the better way?

Making ChatMessageListVC > dataSource open so that we can override it or allow the ability for users to perform a query on the message list in order to decide which messages are rendered.

GetStream Environment

GetStream Chat version: 4.15 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: 16 Swift version: 5 Xcode version: 13.3 Device: iPhone 13 Pro Max

Additional context

This request was initially opened as a support ticket - 27570

virbedi avatar Sep 19 '22 16:09 virbedi

Hi @virbedi ,

As we discussed in a support ticket, this is not a functionality we currently have in the SDK. We will open a feature request and will prioritize it accordingly.

Will keep you updated

polqf avatar Sep 20 '22 09:09 polqf

Hi @virbedi,

You can try overriding the following methods from ChatChannelVC:

image

Your suggestion is already possible. The ChatMessageListVCDataSource is already open, but you need to override it in the ChatChannelVC, not ChatMessageListVC.

For your use case, we are not sure what could be the consequences of overriding this, so keep that in mind.

Let us know if this worked for you.

Best, Nuno

nuno-vieira avatar Sep 20 '22 10:09 nuno-vieira

Hello @nuno-vieira, Overriding these functions seem to lead to frequent crashes related to mismatched indexes.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 124 from section 0 which only contains 48 rows before the update'
terminating with uncaught exception of type NSException
CoreSimulator 802.6 - Device: iPhone 13 (E33F5BC3-4E30-40F1-B369-6FDF712889AC) - Runtime: iOS 15.4 (19E240) - DeviceType: iPhone 13

virbedi avatar Sep 20 '22 19:09 virbedi

Hi @virbedi!

Yes, that could be happening. Can you share how are you overriding all the methods above?

Best, Nuno

nuno-vieira avatar Sep 21 '22 10:09 nuno-vieira

Hi @virbedi!

I can confirm this is not possible right now, it will require us to open more APIs, or introduce a filter block that you could use to filter messages locally. We will discuss this internally and will let you know once we have more details and if this is something we want to support.

Best, Nuno

nuno-vieira avatar Sep 21 '22 11:09 nuno-vieira

Opening up the option to locally filter the list would really help with developing the threading UI we are working on. I'll keep an eye out for updates in the mean time.

Thank you!

virbedi avatar Sep 21 '22 17:09 virbedi

Hi @virbedi,

This feature will add a little bit of risk to the SDK, and since it is a low-priority task, it will be very unlikely we will provide this any time soon. Either way, there is an alternative that should work, and it should not impact the performance. The idea is to override ChatMessageListVC.heightForRowAt to return 0 when a certain condition happens, and also overrideChatMessageContentView.updateContent() to hide the views. Here is an example:

  // (ChatMessageListVC)
  override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        guard let message = dataSource?.chatMessageListVC(self, messageAt: indexPath) else {
            return UITableView.automaticDimension
        }

        if message.isShadowed {
           return 0
        }

        return UITableView.automaticDimension
  }

  // (ChatMessageContentView)
  override func updateContent() {
        super.updateContent()

        isHidden = content?.isShadowed == true
   }

Let us know if this works for you!

Best, Nuno

nuno-vieira avatar May 31 '23 15:05 nuno-vieira