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!(all the things): fuse SyncTimelineEvent into TimelineEvent #4568

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/matrix-sdk-base/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ All notable changes to this project will be documented in this file.
- Replaced `Room::compute_display_name` with the reintroduced `Room::display_name()`. The new
method computes a display name, or return a cached value from the previous successful computation.
If you need a sync variant, consider using `Room::cached_display_name()`.
- [**breaking**]: The reexported types `SyncTimelineEvent` and `TimelineEvent` have been fused into a single type
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
- [**breaking**]: The reexported types `SyncTimelineEvent` and `TimelineEvent` have been fused into a single type
- [**breaking**]: The reexported types `SyncTimelineEvent` and `TimelineEvent` have been fused into a single type

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not against this change, but can I ask why we should do it like this? This will break the list into two lists, now, which seems counter to the point of having a list of changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't particularly care, but if you prefer the rendering without the extra newlines, then we shouldn't have them in the other changelog either.

`TimelineEvent`, and its field `push_actions` has been made `Option`al (it is set to `None` when
we couldn't compute the push actions, because we lacked some information).
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a link to the PR introducing this change.

([#4568](https://github.com/matrix-org/matrix-rust-sdk/pull/4568))

### Features

Expand Down
16 changes: 8 additions & 8 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::latest_event::{is_suitable_for_latest_event, LatestEvent, PossibleLat
#[cfg(feature = "e2e-encryption")]
use crate::RoomMemberships;
use crate::{
deserialized_responses::{DisplayName, RawAnySyncOrStrippedTimelineEvent, SyncTimelineEvent},
deserialized_responses::{DisplayName, RawAnySyncOrStrippedTimelineEvent, TimelineEvent},
error::{Error, Result},
event_cache::store::EventCacheStoreLock,
response_processors::AccountDataProcessor,
Expand Down Expand Up @@ -347,9 +347,9 @@ impl BaseClient {
Ok(())
}

/// Attempt to decrypt the given raw event into a `SyncTimelineEvent`.
/// Attempt to decrypt the given raw event into a [`TimelineEvent`].
///
/// In the case of a decryption error, returns a `SyncTimelineEvent`
/// In the case of a decryption error, returns a [`TimelineEvent`]
/// representing the decryption error; in the case of problems with our
/// application, returns `Err`.
///
Expand All @@ -359,7 +359,7 @@ impl BaseClient {
&self,
event: &Raw<AnySyncTimelineEvent>,
room_id: &RoomId,
) -> Result<Option<SyncTimelineEvent>> {
) -> Result<Option<TimelineEvent>> {
let olm = self.olm_machine().await;
let Some(olm) = olm.as_ref() else { return Ok(None) };

Expand All @@ -372,7 +372,7 @@ impl BaseClient {
.await?
{
RoomEventDecryptionResult::Decrypted(decrypted) => {
let event: SyncTimelineEvent = decrypted.into();
let event: TimelineEvent = decrypted.into();

if let Ok(AnySyncTimelineEvent::MessageLike(e)) = event.raw().deserialize() {
match &e {
Expand All @@ -394,7 +394,7 @@ impl BaseClient {
event
}
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
SyncTimelineEvent::new_utd_event(event.clone(), utd_info)
TimelineEvent::new_utd_event(event.clone(), utd_info)
}
};

Expand Down Expand Up @@ -423,7 +423,7 @@ impl BaseClient {
for raw_event in events {
// Start by assuming we have a plaintext event. We'll replace it with a
// decrypted or UTD event below if necessary.
let mut event = SyncTimelineEvent::new(raw_event);
let mut event = TimelineEvent::new(raw_event);

match event.raw().deserialize() {
Ok(e) => {
Expand Down Expand Up @@ -535,7 +535,7 @@ impl BaseClient {
},
);
}
event.push_actions = actions.to_owned();
event.push_actions = Some(actions.to_owned());
}
}
Err(e) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

//! Event cache store and common types shared with `matrix_sdk::event_cache`.

use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_common::deserialized_responses::TimelineEvent;

pub mod store;

/// The kind of event the event storage holds.
pub type Event = SyncTimelineEvent;
pub type Event = TimelineEvent;

/// The kind of gap the event storage holds.
#[derive(Clone, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use assert_matches::assert_matches;
use async_trait::async_trait;
use matrix_sdk_common::{
deserialized_responses::{
AlgorithmInfo, DecryptedRoomEvent, EncryptionInfo, SyncTimelineEvent, TimelineEventKind,
AlgorithmInfo, DecryptedRoomEvent, EncryptionInfo, TimelineEvent, TimelineEventKind,
VerificationState,
},
linked_chunk::{
Expand All @@ -42,7 +42,7 @@ use crate::{
/// correctly stores event data.
///
/// Keep in sync with [`check_test_event`].
pub fn make_test_event(room_id: &RoomId, content: &str) -> SyncTimelineEvent {
pub fn make_test_event(room_id: &RoomId, content: &str) -> TimelineEvent {
let encryption_info = EncryptionInfo {
sender: (*ALICE).into(),
sender_device: None,
Expand All @@ -60,13 +60,13 @@ pub fn make_test_event(room_id: &RoomId, content: &str) -> SyncTimelineEvent {
.into_raw_timeline()
.cast();

SyncTimelineEvent {
TimelineEvent {
kind: TimelineEventKind::Decrypted(DecryptedRoomEvent {
event,
encryption_info,
unsigned_encryption_info: None,
}),
push_actions: vec![Action::Notify],
push_actions: Some(vec![Action::Notify]),
}
}

Expand All @@ -75,9 +75,9 @@ pub fn make_test_event(room_id: &RoomId, content: &str) -> SyncTimelineEvent {
///
/// Keep in sync with [`make_test_event`].
#[track_caller]
pub fn check_test_event(event: &SyncTimelineEvent, text: &str) {
pub fn check_test_event(event: &TimelineEvent, text: &str) {
// Check push actions.
let actions = &event.push_actions;
let actions = event.push_actions.as_ref().unwrap();
assert_eq!(actions.len(), 1);
assert_matches!(&actions[0], Action::Notify);

Expand Down
22 changes: 11 additions & 11 deletions crates/matrix-sdk-base/src/latest_event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Utilities for working with events to decide whether they are suitable for
//! use as a [crate::Room::latest_event].

use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_common::deserialized_responses::TimelineEvent;
#[cfg(feature = "e2e-encryption")]
use ruma::{
events::{
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn is_suitable_for_latest_event<'a>(
#[derive(Clone, Debug, Serialize)]
pub struct LatestEvent {
/// The actual event.
event: SyncTimelineEvent,
event: TimelineEvent,

/// The member profile of the event' sender.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -178,7 +178,7 @@ pub struct LatestEvent {
#[derive(Deserialize)]
struct SerializedLatestEvent {
/// The actual event.
event: SyncTimelineEvent,
event: TimelineEvent,

/// The member profile of the event' sender.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'de> Deserialize<'de> for LatestEvent {
Err(err) => variant_errors.push(err),
}

match serde_json::from_str::<SyncTimelineEvent>(raw.get()) {
match serde_json::from_str::<TimelineEvent>(raw.get()) {
Ok(value) => {
return Ok(LatestEvent {
event: value,
Expand All @@ -230,31 +230,31 @@ impl<'de> Deserialize<'de> for LatestEvent {

impl LatestEvent {
/// Create a new [`LatestEvent`] without the sender's profile.
pub fn new(event: SyncTimelineEvent) -> Self {
pub fn new(event: TimelineEvent) -> Self {
Self { event, sender_profile: None, sender_name_is_ambiguous: None }
}

/// Create a new [`LatestEvent`] with maybe the sender's profile.
pub fn new_with_sender_details(
event: SyncTimelineEvent,
event: TimelineEvent,
sender_profile: Option<MinimalRoomMemberEvent>,
sender_name_is_ambiguous: Option<bool>,
) -> Self {
Self { event, sender_profile, sender_name_is_ambiguous }
}

/// Transform [`Self`] into an event.
pub fn into_event(self) -> SyncTimelineEvent {
pub fn into_event(self) -> TimelineEvent {
self.event
}

/// Get a reference to the event.
pub fn event(&self) -> &SyncTimelineEvent {
pub fn event(&self) -> &TimelineEvent {
&self.event
}

/// Get a mutable reference to the event.
pub fn event_mut(&mut self) -> &mut SyncTimelineEvent {
pub fn event_mut(&mut self) -> &mut TimelineEvent {
&mut self.event
}

Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {
use assert_matches::assert_matches;
#[cfg(feature = "e2e-encryption")]
use assert_matches2::assert_let;
use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_common::deserialized_responses::TimelineEvent;
use ruma::serde::Raw;
#[cfg(feature = "e2e-encryption")]
use ruma::{
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
latest_event: LatestEvent,
}

let event = SyncTimelineEvent::new(
let event = TimelineEvent::new(
Raw::from_json_string(json!({ "event_id": "$1" }).to_string()).unwrap(),
);

Expand Down
Loading
Loading