diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 6692a5a1d44..b175af4c2fd 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -873,6 +873,7 @@ impl From for RequestToJoi display_name: request.member_info.display_name.clone(), avatar_url: request.member_info.avatar_url.as_ref().map(|url| url.to_string()), reason: request.member_info.reason.clone(), + timestamp: request.timestamp.map(|ts| ts.into()), is_seen: request.is_seen, actions: Arc::new(RequestToJoinActions { inner: request }), } @@ -900,6 +901,8 @@ pub struct RequestToJoin { pub avatar_url: Option, /// An optional reason why the user wants join the room. pub reason: Option, + /// The timestamp when this request was created. + pub timestamp: Option, /// Whether the request to join has been marked as `seen` so it can be /// filtered by the client. pub is_seen: bool, @@ -931,6 +934,14 @@ impl RequestToJoinActions { pub async fn decline_and_ban(&self, reason: Option) -> Result<(), ClientError> { self.inner.decline_and_ban(reason.as_deref()).await.map_err(Into::into) } + + /// Marks the request as 'seen'. + /// + /// **IMPORTANT**: this won't update the current reference to this request, + /// a new one with the updated value should be emitted instead. + pub async fn mark_as_seen(&self) -> Result<(), ClientError> { + self.inner.clone().mark_as_seen().await.map_err(Into::into) + } } /// Generates a `matrix.to` permalink to the given room alias. diff --git a/crates/matrix-sdk-base/src/deserialized_responses.rs b/crates/matrix-sdk-base/src/deserialized_responses.rs index 6761120d1b0..0774a66155f 100644 --- a/crates/matrix-sdk-base/src/deserialized_responses.rs +++ b/crates/matrix-sdk-base/src/deserialized_responses.rs @@ -30,7 +30,7 @@ use ruma::{ StateEventContent, StaticStateEventContent, StrippedStateEvent, SyncStateEvent, }, serde::Raw, - EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UserId, + EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt, UserId, }; use serde::Serialize; use unicode_normalization::UnicodeNormalization; @@ -485,6 +485,14 @@ impl MemberEvent { _ => None, } } + + /// The optional timestamp for this member event. + pub fn timestamp(&self) -> Option { + match self { + MemberEvent::Sync(SyncStateEvent::Original(c)) => Some(c.origin_server_ts.0), + _ => None, + } + } } impl SyncOrStrippedState { diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 5ada0c4c24e..93a9fed9fee 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -3280,6 +3280,7 @@ impl Room { Some(RequestToJoinRoom::new( self.clone(), &event_id, + member.event().timestamp(), member.into(), seen_request_ids.contains(&event_id), )) diff --git a/crates/matrix-sdk/src/room/request_to_join.rs b/crates/matrix-sdk/src/room/request_to_join.rs index cad417f6a49..8ad054418b7 100644 --- a/crates/matrix-sdk/src/room/request_to_join.rs +++ b/crates/matrix-sdk/src/room/request_to_join.rs @@ -1,9 +1,7 @@ use std::sync::Arc; -use ruma::{ - EventId, OwnedEventId, OwnedMxcUri, - OwnedUserId, RoomId, -}; +use js_int::UInt; +use ruma::{EventId, OwnedEventId, OwnedMxcUri, OwnedUserId, RoomId}; use crate::{room::RoomMember, Error, Room}; @@ -13,6 +11,8 @@ pub struct RequestToJoinRoom { room: Arc, /// The event id of the event containing knock membership change. pub event_id: OwnedEventId, + /// The timestamp when this request was created. + pub timestamp: Option, /// Some general room member info to display. pub member_info: RequestToJoinMemberInfo, /// Whether it's been marked as 'seen' by the client. @@ -23,10 +23,11 @@ impl RequestToJoinRoom { pub(crate) fn new( room: Arc, event_id: &EventId, + timestamp: Option, member: RequestToJoinMemberInfo, is_seen: bool, ) -> Self { - Self { room, event_id: event_id.to_owned(), member_info: member, is_seen } + Self { room, event_id: event_id.to_owned(), timestamp, member_info: member, is_seen } } /// The room id for the `Room` form whose access is requested.