Closed brianmwadime closed 1 year ago
Hi @brianmwadime,
The ChatMessageListVC
is not meant to be used as a Searching functionality, so this will probably produce unexpected issues. The ChatMessageListVC
is meant to be used as a standalone component if, for some reason, you want to handle the composer yourself, and so the ChatChannelVC
and the ChatThreadVC
does not work for you.
Either way, can you share your implementation? Are you implementing the ChatMessageListVCDataSource
and ChatMessageListVCDelegate
?
You can ignore that console error for now, that is just a warning, and it won't have any impact on this one.
Best, Nuno
Hi @brianmwadime,
The
ChatMessageListVC
is not meant to be used as a Searching functionality, so this will probably produce unexpected issues. TheChatMessageListVC
is meant to be used as a standalone component if, for some reason, you want to handle the composer yourself, and so theChatChannelVC
and theChatThreadVC
does not work for you.Either way, can you share your implementation? Are you implementing the
ChatMessageListVCDataSource
andChatMessageListVCDelegate
?You can ignore that console error for now, that is just a warning, and it won't have any impact on this one.
Best, Nuno
Hey @nuno-vieira, we are using it as a standalone component since we don't need the composer.
I have also implemented both ChatMessageListVCDataSource
and ChatMessageListVCDelegate
.
I also noticed initially when performing a search on ViewDidLoad the messages aren't displayed but if I move the app to the background and them back to foreground the messages appear in the list.
@nuno-vieira does this mean if I wanted to create screens that show for example a list of only the attachments (media), I can't use the ChatStream components? I'll have to build out the UI?
Hi @brianmwadime,
And are you using the ChatMessageSearchControllerDelegate.didChangeMessages
to populate the ChatMessageListVC
and refresh the data? It is easier if you send your implementation so that we can review it. If you don't want to send it here, you can send it to nuno@getstream.io
Best, Nuno
Hi, @brianmwadime!
For the list of only the attachments, yes, you will need to build the UI yourself at the moment. We are constantly improving the SDK and adding new out-of-the-box components, but as of now, we don't have an ETA to provide a UI Component for showing the media files only. But, for the search functionality we will provide components out of the box very soon.
Best, Nuno
Sent via email @nuno-vieira
Hi @brianmwadime!
So looking at the code, I see 2 things that need to be changed.
messagesController.search(query: query, completion: { [weak self] _ in
guard let self = self else { return }
debugPrint("Messages Count: ", messagesController.messages.count, separator: "\n")
self.messages = Array(self.messagesController.messages)
})
This part should be changed to just this:
messagesController.search(query: query)
You only need the completion closure if you want to display an error. The data is only updated through the delegate.
Then, in the delegate, your current implementation does not do anything, unfortunately. This would be the correct implementation:
func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>]) {
messageListVC.setPreviousMessagesSnapshot(messages)
messageListVC.setNewMessagesSnapshot(Array(controller.messages))
messageListVC.listView.updateMessages(with: changes)
}
The problem is that all these APIs are private at the moment. So we might need to change this. But for now, as a workaround just to check if it works, you can do it like this:
func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>]) {
messages = Array(controller.messages)
messageListVC.listView.reloadData()
}
Let me know if, with this, you can see the data.
Best, Nuno
@nuno-vieira yes, accessing reloadData()
fixes the issue. Thank you.
Also is there a way to load the messages normally (from the top) not like the Chat message screen?
Hi @brianmwadime
What do you mean by that? Do you want the most recent messages to render at the top?
@nuno-vieira for example if I m displaying a single message, I want it to be at the top of the screen (like a regular list) not start from the bottom.
Ah, for that, you can do this:
Components.default.shouldMessagesStartAtTheTop = true
But keep in mind, if the message list is big, it will still display the bottom messages first. The shouldMessagesStartAtTheTop
applies only when the message list has a few messages.
Let me know if this is what you want
@nuno-vieira yes, but just for the knowledge how can I reverse the order as well?
Currently, we do not support this. The Chat UI is an inverted table view at the moment and is meant for rendering a conversation where newer messages are rendered at the bottom. For now, we are not planning on changing this.
This is why we do not recommend using ChatMessageListVC
for message search since it was not designed for that.
Usually, people render the message search in a regular Table View or Collection View, and then you click on that message and you jump to the conversation at that location. This is also how our built-in Search component will work. This searching functionality is usually done in the Channel List Screen, but it can be done also in other places.
@nuno-vieira yeah, thought we'd be able to reuse the message cell and all the logic it comes with out of the box by using the ChatMessageListVC
, but I haven't seen examples of this with a custom tableview/collectionview.
We don't have our own examples yet, since we will soon have built-in components for this. This is planned for the end of Q2. For now, we don't have any customers doing a search of messages with the ChatMessageCell
design. It is more with the Channel List Item View design. This is how our builtin search component will look like:
On the Search List View, the results are displayed like a Channel List, and then you click on the result and jump to the conversation.
Using the ChatMessageCell
for doing searches is not something we are supporting for now. If you want this to do a search like WhatsApp does, I believe this won't work very well. The reason is that WhatsApp has all messages available locally, so in this case, it is easy to implement this. But in our case, when doing a search, most of the messages are not available locally, only remotely. So there will be gaps if you render the search results in the message list.
I don't have access to your designs, so I'm not sure what you are trying to implement, but if it is to mimic WhatsApp search inside the conversation, I'm afraid that won't work very well.
@nuno-vieira got it.
I have one last question, is it possible to filter for just for lets say [.images, .video]
for a specific channel in the ChatChannelController
or that is just available on the ChatMessageSearchController
?
Yes that is correct, only ChatMessageSearchController
allows that
I'm closing this one for now; feel free to open new issues if you have any troubles 👍
Best, Nuno
What did you do?
Tried using the
ChatMessageListVC
in custom ViewController to displaymessages
from aChatMessageSearchController
What did you expect to happen?
The messages fetched from
ChatMessageSearchController
would be updated in the custom ChatMessageListVC and messages would be visible depending on the search parameters passed.What happened instead?
When using the breakpoint navigator, the
channelController( _ channelController: ChatChannelController, didUpdateMessages changes: [ListChange<ChatMessage>] )
gets called from theChatChannelVC
(even though it's not referenced in my custom view controller), then my attached delegate callsChatMessageSearchControllerDelegate.controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>])
then lastly the error below is thrown and the messages are not displayed
GetStream Environment
GetStream Chat version: 4.31.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: 16.3.1 Swift version: 5 Xcode version: Xcode 14.3 Device: Iphone 8
Additional context