matrix-js-sdk get all messages from room

Viewed 318

How do you get all the messages from a room in matrix?

I am following https://matrix.org/docs/guides/usage-of-the-matrix-js-sdk

I have the client started and synchronized.

Accessing room.timeline only gives the most recent messages. I want to get all of from the beginning of the chat.

Thanks for your help.

1 Answers

You can use the initialRoomSync function from the SDK and access the messages attribute to get the entire timeline of messages, then you can listen for new ones by listening to the Room.timeline event as described on the documentation you have provided.

Related