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

timeline: factor out inner part of [Sync]TimelineEvent #4082

Merged
merged 9 commits into from
Oct 9, 2024

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 7, 2024

As previously discussed, we'd like to replace the innards of SyncTimelineEvent and TimelineEvent with a new enum, so that we can accurately represent the three possible states of (Unencrypted, Decrypted, UnableToDecrypt).

This PR lays the groundwork for that change by pulling out the enum. For now it only supports the Decrypted and PlainText cases: the UTD case is still mapped onto PlainText, and will change in a followup PR. It is essentially a reworking of #4053.

One potential point of contention is that I've used the same inner type for both TimelineEvent and SyncTimelineEvent: it seems to me that we never rely on the different type information, so having two implementations felt redundant. (It does mean that TimelineEvent and SyncTimelineEvent become essentially identical, but replacing one with the other felt like a job for another day.) Anyway, I'm happy to revisit this and add a separate SyncTimelineEventKind or somesuch instead.

Speaking of which, I'm also not entirely happy with the name TimelineEventInner. When we discussed this, poljar spoke of TimelineFoo and I've not felt much more inspired since. If we could think of a decent name, I think the struct could usefully be exposed as a public type which might clean up some other bits of code. Suggestions welcome. Now renamed to TimelineEventKind.

Unfortunately, this PR is necessarily somewhat large. I've tried to structure it in a way to make it easily reviewable, but let me know if I can help with review.

Part of #4048.

I found it hard to understand what these two structs were for, so let's start
by giving them some documentation.
I'm going to change the internal structure of `SyncTimelineEvent`, and since
it implements `Deserialize`, we need to not break it. Let's add a test for the
current format.
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 85.29412% with 15 lines in your changes missing coverage. Please review.

Project coverage is 84.68%. Comparing base (351fbf6) to head (2401837).
Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
...es/matrix-sdk-common/src/deserialized_responses.rs 83.33% 10 Missing ⚠️
crates/matrix-sdk-ui/src/notification_client.rs 62.50% 3 Missing ⚠️
crates/matrix-sdk-base/src/client.rs 88.88% 1 Missing ⚠️
crates/matrix-sdk/src/room/edit.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4082      +/-   ##
==========================================
+ Coverage   84.66%   84.68%   +0.01%     
==========================================
  Files         269      269              
  Lines       28694    28749      +55     
==========================================
+ Hits        24294    24346      +52     
- Misses       4400     4403       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richvdh richvdh marked this pull request as ready for review October 7, 2024 11:38
@richvdh richvdh requested a review from a team as a code owner October 7, 2024 11:38
@richvdh richvdh requested review from bnjbvr and removed request for a team October 7, 2024 11:38
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Looks good; I'm rather unsure about some of the implicit conversion to a plain text event. Good job on the custom deserializer, too bad we couldn't use an untagged enum (I seem to recall this worked in the past…).

crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-common/src/deserialized_responses.rs Outdated Show resolved Hide resolved
@richvdh richvdh force-pushed the rav/timeline_event_inner branch 7 times, most recently from feca893 to ba762a8 Compare October 8, 2024 16:43
@richvdh richvdh requested a review from bnjbvr October 8, 2024 21:06
@richvdh
Copy link
Member Author

richvdh commented Oct 8, 2024

@bnjbvr please take another look?

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! Maybe worth a note in a CHANGELOG, or a Changelog trailer in the commits (see also our future awesome release process for details).

... and add accessors instead.

I'm going to change the inner structure of `SyncTimelineEvent`, meaning that
access will have to be via an accessor in future. Let's start by making the
fields private, and use accessors where we previously used direct access.
... and add accessors instead.

Give `TimelineEvent` the same treatment we just gave `SyncTimelineEvent`: make
the fields private, and use accessors where we previously used direct access.
I'm going to be replacing the inner structure of `TimelineEvent` with an
implementation that holds a `Raw<AnySyncTimelineEvent>`, rather than a
`Raw<AnyTimelineEvent>`. Prepare for that by changing the accessors to return
`Raw<AnySyncTimelineEvent>`.
…eEvent>`

Give `Timeline::into_raw()` the same treatmeant we just gave `Timeline::ra()`.
Pull out the bits of these classes which are dependent on success or otherwise
of decrypting an event to a new enum.
These are no longer required now that the event itself lives in an inner class.
This is only used in one place, and is much better inlined anyway.
@richvdh richvdh force-pushed the rav/timeline_event_inner branch from ba762a8 to 2401837 Compare October 9, 2024 14:04
@richvdh richvdh enabled auto-merge (rebase) October 9, 2024 14:09
@richvdh richvdh merged commit 9c64135 into main Oct 9, 2024
40 checks passed
@richvdh richvdh deleted the rav/timeline_event_inner branch October 9, 2024 14:19
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.

3 participants