Fetch Messages returns Empty array

Hello,

When fetching all messages for a logged in user, the API returns an empty array. I have been sending messages successfully, I can see the messages in the Comet Chat dashboard. When I try and get all the messages for a user I just get an empty array.

Please note, the “getConversations” api is working fine for me.

Im using:
@cometchat-pro/react-native-calls”: “2.0.2”,
@cometchat-pro/react-native-chat”: “2.3.4”,

var limit = 50;

var messagesRequest = new CometChat.MessagesRequestBuilder()
  .setLimit(limit)
  .build();

messagesRequest.fetchPrevious().then(
  messages => {
    console.log("Message list fetched:", messages);
    // Handle the list of messages
  },
  error => {
    console.log("Message fetching failed with error:", error);
  }
);

Hello @densocial,

Currently, it is not possible to fetch messages from all the users. You need to specify the UID of a user or GUID of a group while fetching messages using the setUID(UID) or setGUID(GUID) method of the MessagesRequestBuilder.

Can you please let us know why are you fetching messages of all the users at once?

Warm Regards,

CometChat Pro
Mayur Bhandari

Hi Mayur,

Thanks for your response.

I do not want to fetch all the messages for all the users. I just want to fetch all the messages for the logged in user. Currently im fetching all the conversations, then looping through the conversations and getting the messages for those conversations. This is a little slow… Is there a better way to fetch all messages for the logged in user?

Thanks,

It’s still not possible to get messages from all users chats. As it’s presented in documentation https://prodocs.cometchat.com/docs/cordova-ionic-messaging-receive-messages#for-all-one-on-one–group-conversations-1
it returns just an empty array. So we can’t search through all users chats.

Hello @Tema,

Currently, it is not possible to fetch messages from all the users. You need to specify the UID of a user or GUID of a group while fetching messages using the setUID(UID) or setGUID(GUID) method of the MessagesRequestBuilder.

Can you please let us know why do you want to fetch messages of all the users & group chat at once?

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

Thanks for the reply.
We had a feature that allows our users to perform a search across all their chats. It was working as explained in documentation. Then you disable this feature although it’s still in documentation
So we had a feature and UX for this, and then you removed this, so that’s a problem for us.

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

Thank you very much for this thread, it was very helpful.