-
Notifications
You must be signed in to change notification settings - Fork 327
feat(sdk): LatestEventValue
implements Serialize
and Deserialize
#5561
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
base: main
Are you sure you want to change the base?
Conversation
The problem is: `LatestEventContent` cannot be serialized. It's annoying because it means we can't store a `LatestEventValue` (that wraps a `LatestEventContent`) in the database. This patch revisits `LatestEventValue`. Before we got: ```rust pub enum LatestEventValue { None, Remote(LatestEventContent), LocalIsSending(LatestEventContent), LocalCannotBeSent(LatestEventContent), } pub enum LatestEventContent { RoomMessage(RoomMessageEventContent), Sticker(StickerEventContent), Poll(UnstablePollStartEventContent), CallInvite(CallInviteEventContent), CallNotify(CallNotifyEventContent), KnockedStateEvent(RoomMemberEventContent), Redacted(AnySyncMessageLikeEvent), } ``` `LatestEventContent::Redacted` contains an `AnySyncMessageLikeEvent`. That's the part that is not serializable. It appears that `LatestEventContent` isn't necessary! The only thing we need is to _filter_ the events by their type, no need to _find and map_. The `LatestEventValue` can contain the entry event directly (e.g. a `TimelineEvent` for the event cache). Okay, let's do that. ```rust pub enum LatestEventValue { None, Remote(RemoteLatestEventValue), LocalIsSending(???), LocalCannotBeSent(???), } type RemoteLatestEventValue = TimelineEvent; ``` What about the `Local*` variants? We can't use a `TimelineEvent`. We need a new type for that: ```rust pub enum LatestEventValue { None, Remote(RemoteLatestEventValue), LocalIsSending(LocalLatestEventValue), LocalCannotBeSent(LocalLatestEventValue), } pub struct LocalLatestEventValue { pub timestamp: MilliSecondsSinceUnixEpoch, pub content: Raw<AnyMessageLikeEventContent>, pub event_type: String, } ``` We don't need the event ID nor the transaction ID in `LocalLatestEventValue`. That's the only change. All the other changes are about the tests.
This patch implements `Serialize` and `Deserialize` on `LatestEventValue`.
b30e23f
to
edd32f9
Compare
CodSpeed Performance ReportMerging #5561 will not alter performanceComparing Summary
Benchmarks breakdown
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5561 +/- ##
==========================================
- Coverage 88.65% 88.64% -0.02%
==========================================
Files 340 340
Lines 95083 95029 -54
Branches 95083 95029 -54
==========================================
- Hits 84292 84234 -58
+ Misses 6609 6608 -1
- Partials 4182 4187 +5 ☔ View full report in Codecov by Sentry. |
I think that instead of:
Could you use |
The problem is:
LatestEventContent
cannot be serialized. It's annoying because it means we can't store aLatestEventValue
(that wraps aLatestEventContent
) in the database.This patch revisits
LatestEventValue
. Before we got:LatestEventContent::Redacted
contains anAnySyncMessageLikeEvent
. That's the part that is not serializable.It appears that
LatestEventContent
isn't necessary! The only thing we need is to filter the events by their type, no need to find and map. TheLatestEventValue
can contain the entry event directly (e.g. aTimelineEvent
for the event cache). Okay, let's do that.What about the
Local*
variants? We can't use aTimelineEvent
. We need a new type for that:We don't need the event ID nor the transaction ID in
LocalLatestEventValue
.That's the only change. All the other changes are about the tests.