Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fetching room messages #250

Open
tadzik opened this issue Jul 28, 2022 · 1 comment · May be fixed by #265
Open

Add support for fetching room messages #250

tadzik opened this issue Jul 28, 2022 · 1 comment · May be fixed by #265
Labels
enhancement New feature or request

Comments

@tadzik
Copy link
Contributor

tadzik commented Jul 28, 2022

Is your feature request related to a problem? Please describe.

There is currently no wrapper around https://spec.matrix.org/v1.3/client-server-api/#get_matrixclientv3roomsroomidmessages to be able to load messages from a room.

Describe the solution you'd like

A nicely typed wrapper for that endpoint.

Describe alternatives you've considered

I'm currently doing this manually with doRequest but it's a bit of extra legwork that I'd rather not do:

        let from: string|undefined;
        for (;;) {
            const events = await this.matrixClient.doRequest(
                'GET',
                `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/messages`,
                { dir: 'b', limit: 100, from },
            );
            for (const ev of events.chunk) {
                if (ev.type === 'm.room.create') {
                    break;
                } else if (ev.type === interestingEventType) {
                    interestingEvents.push(ev.content);
                }
            }
            if (from === events.end) break;
            from = events.end;
        }
        // use interestingEvents

The above could serve as an inspiration for the PR.

@tadzik tadzik added the enhancement New feature or request label Jul 28, 2022
@turt2live turt2live linked a pull request Oct 7, 2022 that will close this issue
3 tasks
AndrewKvalheim added a commit to SeaGL/patch that referenced this issue Mar 28, 2023
@AndrewKvalheim
Copy link
Contributor

AndrewKvalheim commented Mar 30, 2023

I ended up adding an async generator with token management hidden from the public interface:

const pages = client.getRoomEvents(room, "reverse", { types: ["m.reaction"] });

for await (const page of pages) {
  for (const reaction of page) {
    console.log(reaction);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants