How to hide messages from blocked users - CometChat.ConversationsRequestBuilder()

We have a recent conversations feature in our app but would like to hide messages from blocked users.

Currently, whenever we use the below method it shows messages from blocked users.

this.conversationsRequest = new CometChat.ConversationsRequestBuilder()

How can we hide messages from blocked users?

Hello @kl2000,

The conversation of users whom the logged-in user has blocked is not fetched while fetching the Conversation List. Can you please elaborate more on the issue you are facing?

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

Hi Mayur, for the MessagesRequestBuilder method you can set "hideMessagesFromBlockedUsers flag.

this.messagesRequest = new CometChat.MessagesRequestBuilder()
.setLimit(limit)
.setGUID(this.currentData.clickedVentID)
.hideMessagesFromBlockedUsers(true)
.build();

For the ConversationsRequestBuilder method this flag doesn’t seem to be available.

I believe we have resolved our issue though.

We display the lastMessage of a conversation in a custom Recent Chats component.
In a recent group chat for a user it would display the lastMessage from blocked users.

We ended up writing our own filter to remove any lastMessage that was sent from blocked users.

Hello @kl2000,

So, If I block a user using CometChat.blockUser() and if that user sends a message in a Group. Then while fetching the Conversations using the ConversationsRequestBuilder the last message would be a message sent from a user whom the logged-in user has blocked. If yes, then you would have to add a custom filter and hide the last message.

Can you please let us know what exactly are you doing to remove the last message if it was sent from a blocked user? We would like to know so that if a better solution is possible, we’ll be glad to let you know.

Currently, it is not possible to hide the last message if that user is blocked by the logged-in user. I have created a feature request and added your email to the list of subscribers. You will get an update via email if/when the product team decides to take this up for development.

You can check the feature request here.

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi Mayur, we have a user service that provides a “blockedusers” array with blocked user’s IDs for the currently logged-in user. Then when we request the conversations we just filter out any blocked user’s last message by comparing the newly requested conversations user “lastMessage.sender.uid” to the “blockedusers” array.

BTW. Thank you for adding the feature request. :grinning:

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