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

refactor: Use Event instead of EventUpdate for storing in db #1992

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

krille-chan
Copy link
Contributor

@krille-chan krille-chan commented Jan 2, 2025

@krille-chan krille-chan force-pushed the krille/remove-event-update-type branch from 1bb5044 to d4091cf Compare January 2, 2025 08:10
@krille-chan krille-chan marked this pull request as ready for review January 2, 2025 08:10
@krille-chan krille-chan requested a review from a team as a code owner January 2, 2025 08:10
@krille-chan krille-chan force-pushed the krille/remove-event-update-type branch 2 times, most recently from 82aedbf to 43d9254 Compare January 2, 2025 08:23
content: event.toJson(),
),
);
if (event is MatrixEvent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have an onInviteStateEvent stream too? It's the only case where the event is not MatrixEvent but a StrippedStateEvent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because this would be a duplication of onSync where you can just filter. This is for events after potential decryption

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but we use onEvent for local notifications. If there's no onInviteStateEvent then we would miss inviteState updates to show local notifications.

@krille-chan krille-chan force-pushed the krille/remove-event-update-type branch from 43d9254 to ea18f23 Compare January 3, 2025 07:59
if (event != null) {
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
if (redactedEvent != null) {
redactedEvent.setRedactionEvent(redactionEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
redactedEvent.setRedactionEvent(redactionEvent);
redactedEvent.setRedactionEvent(event);

Comment on lines -1086 to -1099

if (tmpRoom.lastEvent?.eventId == event.eventId) {
if (client.importantStateEvents.contains(event.type)) {
await _preloadRoomStateBox.put(
TupleKey(eventUpdate.roomID, event.type, '').toString(),
event.toJson(),
);
} else {
await _nonPreloadRoomStateBox.put(
TupleKey(eventUpdate.roomID, event.type, '').toString(),
event.toJson(),
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just confirming. We removed it because it's already handled below right?

    // Store a common state event
    if (stateKey != null &&
        // Don't store events as state updates when paginating backwards.
        (eventUpdate.type == EventUpdateType.timeline ||
            eventUpdate.type == EventUpdateType.state ||
            eventUpdate.type == EventUpdateType.inviteState)) {
      if (eventUpdate.content['type'] == EventTypes.RoomMember) {
        await _roomMembersBox.put(
          TupleKey(
            eventUpdate.roomID,
            eventUpdate.content['state_key'],
          ).toString(),
          eventUpdate.content,
        );
      } else {
        final type = eventUpdate.content['type'] as String;
        final roomStateBox = client.importantStateEvents.contains(type)
            ? _preloadRoomStateBox
            : _nonPreloadRoomStateBox;
        final key = TupleKey(
          eventUpdate.roomID,
          type,
          stateKey,
        ).toString();

        await roomStateBox.put(key, eventUpdate.content);
      }
    }

Comment on lines +1183 to +1185
(type == EventUpdateType.timeline ||
type == EventUpdateType.state ||
type == EventUpdateType.inviteState)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(type == EventUpdateType.timeline ||
type == EventUpdateType.state ||
type == EventUpdateType.inviteState)) {
{EventUpdateType.timeline, EventUpdateType.state, EventUpdateType.inviteState}.contains(type)) {

? eventUpdate.content['unsigned']['transaction_id']
: null,
event_id: event.eventId,
unsigned_txid: event.unsigned?.tryGet<String>('transaction_id'),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's enough usage of event.unsigned?.tryGet<String>('transaction_id') to create a getter txid in the Event class. Should we create one? I can open a separate PR for that if you agree.

expect(eventUpdateList[0].roomID, '!726s6s6q:example.com');
expect(eventUpdateList[0].type, EventUpdateType.state);
expect(eventUpdateList[0].type, 'm.room.member');
expect(eventUpdateList[0].roomId, '!726s6s6q:example.com');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could also have a event.type check here for all these 3 cases (just like before)

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

Successfully merging this pull request may close these issues.

2 participants