Filter action messages

Hi CometChat Team,

I noticed that if you delete or edit a message, the next time you fetch the messages, there’s a new action message added to the list.

That said, is there any way to avoid that. If there’s no way, I would like to know how to filter messages to remove deleted or edited action messages.

I checked the sample app and it looks you are using message property of ActionMessage, to check whether the ActionMessage is deleted or edited. Is there any better approach for this?

Filter Message

Any idea? @jeet.kapadia
Thank you in advance :grinning:

Hello @srbalan,

You’ll be able to hide Action messages for the edited and deleted messages using the below filter.

 guard let messages = fetchedMessages?.filter({
                    ($0 as? ActionMessage != nil && (($0 as? ActionMessage)?.message != "Message is deleted." && ($0 as? ActionMessage)?.message != "Message is edited."))
            }) else { return } 

I hope this will resolve your issue.

Thanks.

Hi @pushpsen.airekar
Thanks for your prompt response. However, is there any other way to filter the deleted and edited messages aside from using hard coded strings?

Hello @srbalan,

Yes! You can hide such message like this as well.

 guard let messages = fetchedMessages?.filter({
                    ($0 as? ActionMessage != nil && (($0 as? ActionMessage)?.action == .messageEdited && ($0 as? ActionMessage)?.action != messageDeleted))
            }) else { return }
3 Likes

Thanks so much @pushpsen.airekar

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.