I have this requirement where i have to populate 1-1 channels on the left side . With the channels list I have to show the last sent message in the channel with each channel . How can I achieve this ?
I thought of a process where i would
- Generate the list of joined channels
- Fetch the last message of each channel by calling the history api
- Then associate the last message with the meta data of the channel
- Show it in the view
Is this the better approach or there are any other ways to do it better ?
Your approach sounds great, I followed similar steps when I put my chat demo together a few months ago: https://github.com/PubNubDevelopers/PubNub-Showcase/tree/main/web/chat. I'll copy the relevant code here:
This returns all channel members, you could filter for only channels you are a member of.
I associated the last read timetoken, but you could associate the last message in the same way