Skip to content
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
7 changes: 7 additions & 0 deletions bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - ReleaseDate

### Bug Fixes

- [**breaking**] `LatestEventValue::Local { is_sending: bool }` is replaced
by [`state: LatestEventValueLocalState`] to represent 3 states: `IsSending`,
`HasBeenSent` and `CannotBeSent`.
([#5968](https://github.com/matrix-org/matrix-rust-sdk/pull/5968/))

### Features

- Add `SpaceService::get_space_room` to get a space given its id from the space graph if available.
Expand Down
13 changes: 7 additions & 6 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ use matrix_sdk_common::{
};
use matrix_sdk_ui::timeline::{
self, AttachmentConfig, AttachmentSource, EventItemOrigin,
LatestEventValue as UiLatestEventValue, MediaUploadProgress as SdkMediaUploadProgress, Profile,
TimelineDetails, TimelineUniqueId as SdkTimelineUniqueId,
LatestEventValue as UiLatestEventValue, LatestEventValueLocalState,
MediaUploadProgress as SdkMediaUploadProgress, Profile, TimelineDetails,
TimelineUniqueId as SdkTimelineUniqueId,
};
use mime::Mime;
use reply::{EmbeddedEventDetails, InReplyToDetails};
Expand Down Expand Up @@ -1301,7 +1302,7 @@ impl LazyTimelineItemProvider {
}

/// Mimic the [`UiLatestEventValue`] type.
#[derive(Clone, uniffi::Enum)]
#[derive(uniffi::Enum)]
pub enum LatestEventValue {
None,
Remote {
Expand All @@ -1316,7 +1317,7 @@ pub enum LatestEventValue {
sender: String,
profile: ProfileDetails,
content: TimelineItemContent,
is_sending: bool,
state: LatestEventValueLocalState,
},
}

Expand All @@ -1333,13 +1334,13 @@ impl From<UiLatestEventValue> for LatestEventValue {
content: content.into(),
}
}
UiLatestEventValue::Local { timestamp, sender, profile, content, is_sending } => {
UiLatestEventValue::Local { timestamp, sender, profile, content, state } => {
Self::Local {
timestamp: timestamp.into(),
sender: sender.to_string(),
profile: profile.into(),
content: content.into(),
is_sending,
state,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/matrix-sdk-base/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - ReleaseDate

### Bug Fixes

- [**breaking**] New `LatestEventValue::LocalHasBeenSent` variant to represent
a local event that has been sent successfully.
([#5968](https://github.com/matrix-org/matrix-rust-sdk/pull/5968))

### Refactor

- [**breaking**] The `message-ids` feature has been removed. It was already a no-op and has now
Expand Down
39 changes: 36 additions & 3 deletions crates/matrix-sdk-base/src/latest_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub enum LatestEventValue {
/// The latest event represents a local event that is sending.
LocalIsSending(LocalLatestEventValue),

/// The latest event represents a local event that has been sent
/// successfully. It should come quickly as a [`Self::Remote`].
LocalHasBeenSent(LocalLatestEventValue),

/// The latest event represents a local event that cannot be sent, either
/// because a previous local event, or this local event cannot be sent.
LocalCannotBeSent(LocalLatestEventValue),
Expand All @@ -28,19 +32,21 @@ impl LatestEventValue {
/// Get the timestamp of the [`LatestEventValue`].
///
/// If it's [`None`], it returns `None`. If it's [`Remote`], it returns the
/// [`TimelineEvent::timestamp`]. If it's [`LocalIsSending`] or
/// [`LocalCannotBeSent`], it returns the
/// [`TimelineEvent::timestamp`]. If it's [`LocalIsSending`],
/// [`LocalHasBeenSent`] or [`LocalCannotBeSent`], it returns the
/// [`LocalLatestEventValue::timestamp`] value.
///
/// [`None`]: LatestEventValue::None
/// [`Remote`]: LatestEventValue::Remote
/// [`LocalIsSending`]: LatestEventValue::LocalIsSending
/// [`LocalHasBeenSent`]: LatestEventValue::LocalHasBeenSent
/// [`LocalCannotBeSent`]: LatestEventValue::LocalCannotBeSent
pub fn timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
match self {
Self::None => None,
Self::Remote(remote_latest_event_value) => remote_latest_event_value.timestamp(),
Self::LocalIsSending(LocalLatestEventValue { timestamp, .. })
| Self::LocalHasBeenSent(LocalLatestEventValue { timestamp, .. })
| Self::LocalCannotBeSent(LocalLatestEventValue { timestamp, .. }) => Some(*timestamp),
}
}
Expand All @@ -52,11 +58,25 @@ impl LatestEventValue {
/// [`LocalCannotBeSent`]: LatestEventValue::LocalCannotBeSent
pub fn is_local(&self) -> bool {
match self {
Self::LocalIsSending(_) | Self::LocalCannotBeSent(_) => true,
Self::LocalIsSending(_) | Self::LocalHasBeenSent(_) | Self::LocalCannotBeSent(_) => {
true
}
Self::None | Self::Remote(_) => false,
}
}

/// Check whether the [`LatestEventValue`] represents an unsent event, i.e.
/// is [`LocalIsSending`] nor [`LocalCannotBeSent`].
///
/// [`LocalIsSending`]: LatestEventValue::LocalIsSending
/// [`LocalCannotBeSent`]: LatestEventValue::LocalCannotBeSent
pub fn is_unsent(&self) -> bool {
match self {
Self::LocalIsSending(_) | Self::LocalCannotBeSent(_) => true,
Self::LocalHasBeenSent(_) | Self::Remote(_) | Self::None => false,
}
}

/// Check whether the [`LatestEventValue`] is not set, i.e. [`None`].
///
/// [`None`]: LatestEventValue::None
Expand Down Expand Up @@ -132,6 +152,19 @@ mod tests_latest_event_value {
assert_eq!(value.timestamp(), Some(MilliSecondsSinceUnixEpoch(uint!(42))));
}

#[test]
fn test_timestamp_with_local_has_been_sent() {
let value = LatestEventValue::LocalHasBeenSent(LocalLatestEventValue {
timestamp: MilliSecondsSinceUnixEpoch(uint!(42)),
content: SerializableEventContent::new(&AnyMessageLikeEventContent::RoomMessage(
RoomMessageEventContent::text_plain("raclette"),
))
.unwrap(),
});

assert_eq!(value.timestamp(), Some(MilliSecondsSinceUnixEpoch(uint!(42))));
}

#[test]
fn test_timestamp_with_local_cannot_be_sent() {
let value = LatestEventValue::LocalCannotBeSent(LocalLatestEventValue {
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/room/latest_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl Room {
self.info.read().latest_event_value.timestamp()
}

/// Return the value of [`LatestEventValue::is_local`].
pub fn latest_event_is_local(&self) -> bool {
self.info.read().latest_event_value.is_local()
/// Return the value of [`LatestEventValue::is_unsent`].
pub fn latest_event_is_unsent(&self) -> bool {
self.info.read().latest_event_value.is_unsent()
}
}
14 changes: 11 additions & 3 deletions crates/matrix-sdk-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - ReleaseDate

### Bug Fixes

- [**breaking**] `LatestEventValue::Local { is_sending: bool }` is replaced
by [`state: LatestEventValueLocalState`] to represent 3 states: `IsSending`,
`HasBeenSent` and `CannotBeSent`.
([#5968](https://github.com/matrix-org/matrix-rust-sdk/pull/5968/))

### Features

- Add `SpaceService::get_space_room` to get a space given its id from the space graph if available.
[#5944](https://github.com/matrix-org/matrix-rust-sdk/pull/5944)
- Add `SpaceService::get_space_room` to get a space
given its id from the space graph if available.
([#5944](https://github.com/matrix-org/matrix-rust-sdk/pull/5944))
- [**breaking**]: The new Latest Event API replaces the old API. All the
`new_` prefixes have been removed. The following methods are removed:
`EventTimelineItem::from_latest_event`, and `Timeline::latest_event`. See the
documentation of `matrix_sdk::latest_event` to learn about the new API.
[#5624](https://github.com/matrix-org/matrix-rust-sdk/pull/5624/)
([#5624](https://github.com/matrix-org/matrix-rust-sdk/pull/5624/))
- `Room::load_event_with_relations` now also calls `/relations` to fetch related events when falling back
to network mode after a cache miss.
([#5930](https://github.com/matrix-org/matrix-rust-sdk/pull/5930))
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk-ui/src/room_list_service/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ pub struct RoomListItem {
/// Cache of `Room::latest_event_timestamp`.
pub(super) cached_latest_event_timestamp: Option<MilliSecondsSinceUnixEpoch>,

/// Cache of `Room::latest_event_is_local`.
pub(super) cached_latest_event_is_local: bool,
/// Cache of `Room::latest_event_is_unsent`.
pub(super) cached_latest_event_is_unsent: bool,

/// Cache of `Room::recency_stamp`.
pub(super) cached_recency_stamp: Option<RoomRecencyStamp>,
Expand All @@ -448,7 +448,7 @@ impl RoomListItem {
/// Refresh the cached data.
pub(super) fn refresh_cached_data(&mut self) {
self.cached_latest_event_timestamp = self.inner.latest_event_timestamp();
self.cached_latest_event_is_local = self.inner.latest_event_is_local();
self.cached_latest_event_is_unsent = self.inner.latest_event_is_unsent();
self.cached_recency_stamp = self.inner.recency_stamp();
self.cached_display_name = self.inner.cached_display_name().map(|name| name.to_string());
self.cached_is_space = self.inner.is_space();
Expand All @@ -459,7 +459,7 @@ impl RoomListItem {
impl From<Room> for RoomListItem {
fn from(inner: Room) -> Self {
let cached_latest_event_timestamp = inner.latest_event_timestamp();
let cached_latest_event_is_local = inner.latest_event_is_local();
let cached_latest_event_is_unsent = inner.latest_event_is_unsent();
let cached_recency_stamp = inner.recency_stamp();
let cached_display_name = inner.cached_display_name().map(|name| name.to_string());
let cached_is_space = inner.is_space();
Expand All @@ -468,7 +468,7 @@ impl From<Room> for RoomListItem {
Self {
inner,
cached_latest_event_timestamp,
cached_latest_event_is_local,
cached_latest_event_is_unsent,
cached_recency_stamp,
cached_display_name,
cached_is_space,
Expand Down
Loading
Loading