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

Distinguish room state and timeline events in embedded clients #4574

Merged
merged 4 commits into from
Jan 15, 2025

Conversation

robintown
Copy link
Member

@robintown robintown commented Dec 6, 2024

This change enables room widget clients to take advantage of the more reliable method of communicating room state over the widget API provided by this update to MSC2762.

Depends on matrix-org/matrix-widget-api#116

This change enables room widget clients to take advantage of the more reliable method of communicating room state over the widget API provided by a recent update to MSC2762.
@robintown robintown marked this pull request as ready for review December 17, 2024 21:31
@robintown robintown requested a review from a team as a code owner December 17, 2024 21:31
@robintown robintown requested review from dbkr and t3chguy December 17, 2024 21:31
Copy link
Contributor

@toger5 toger5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this already. Can you still explain me why we don't need the await (or add it in case we need it)

src/embedded.ts Outdated Show resolved Hide resolved
@robintown robintown requested a review from a team as a code owner January 15, 2025 18:04
@robintown robintown added this pull request to the merge queue Jan 15, 2025
Merged via the queue into matrix-org:develop with commit bdd4d82 Jan 15, 2025
30 of 31 checks passed
@robintown robintown deleted the embedded-state branch January 15, 2025 18:30
robintown added a commit that referenced this pull request Jan 22, 2025
Copy link
Contributor

@toger5 toger5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robintown Do you think those changes could make it work without needing changes on the rust sdk?

Comment on lines -279 to -299
// Backfill the requested events
// We only get the most recent event for every type + state key combo,
// so it doesn't really matter what order we inject them in
await Promise.all(
this.capabilities.receiveState?.map(async ({ eventType, stateKey }) => {
const rawEvents = await this.widgetApi.readStateEvents(eventType, undefined, stateKey, [this.roomId]);
const events = rawEvents.map((rawEvent) => new MatrixEvent(rawEvent as Partial<IEvent>));

if (this.syncApi instanceof SyncApi) {
// Passing undefined for `stateAfterEventList` allows will make `injectRoomEvents` run in legacy mode
// -> state events in `timelineEventList` will update the state.
await this.syncApi.injectRoomEvents(this.room!, undefined, events);
} else {
await this.syncApi!.injectRoomEvents(this.room!, events); // Sliding Sync
}
events.forEach((event) => {
this.emit(ClientEvent.Event, event);
logger.info(`Backfilled event ${event.getId()} ${event.getType()} ${event.getStateKey()}`);
});
}) ?? [],
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could add this code back in case the driver does not support the update_state (or state_after) version.


// Passing undefined for `stateAfterEventList` allows will make `injectRoomEvents` run in legacy mode
// -> state events in `timelineEventList` will update the state.
await this.syncApi.injectRoomEvents(this.room!, [], undefined, [event]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the state_after version is not supported use:
await this.syncApi.injectRoomEvents(this.room!, [], undefined, [event]); as before.

// this.injectRoomEvents(this.room!, params.addToState ? [event] : [], params.addToTimeline ? [event] : []);
// }
// ```
await this.syncApi!.injectRoomEvents(this.room!, [], [event]); // Sliding Sync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use this if the version is not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants