Skip to content

Commit

Permalink
feat(room): Add missing timestamp field and mark_as_seen FFI method
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Dec 10, 2024
1 parent 84c2c1b commit 848142a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
11 changes: 11 additions & 0 deletions bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ impl From<matrix_sdk::room::request_to_join::RequestToJoinRoom> 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 }),
}
Expand Down Expand Up @@ -942,6 +943,8 @@ pub struct RequestToJoin {
pub avatar_url: Option<String>,
/// An optional reason why the user wants join the room.
pub reason: Option<String>,
/// The timestamp when this request was created.
pub timestamp: Option<u64>,
/// Whether the request to join has been marked as `seen` so it can be
/// filtered by the client.
pub is_seen: bool,
Expand Down Expand Up @@ -973,6 +976,14 @@ impl RequestToJoinActions {
pub async fn decline_and_ban(&self, reason: Option<String>) -> 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.
Expand Down
10 changes: 9 additions & 1 deletion crates/matrix-sdk-base/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -485,6 +485,14 @@ impl MemberEvent {
_ => None,
}
}

/// The optional timestamp for this member event.
pub fn timestamp(&self) -> Option<UInt> {
match self {
MemberEvent::Sync(SyncStateEvent::Original(c)) => Some(c.origin_server_ts.0),
_ => None,
}
}
}

impl SyncOrStrippedState<RoomPowerLevelsEventContent> {
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,7 @@ impl Room {
Some(RequestToJoinRoom::new(
self.clone(),
&event_id,
member.event().timestamp(),
member.into(),
seen_request_ids.contains(&event_id),
))
Expand Down
6 changes: 5 additions & 1 deletion crates/matrix-sdk/src/room/request_to_join.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use js_int::UInt;
use ruma::{EventId, OwnedEventId, OwnedMxcUri, OwnedUserId, RoomId};

use crate::{room::RoomMember, Error, Room};
Expand All @@ -10,6 +11,8 @@ pub struct RequestToJoinRoom {
room: Arc<Room>,
/// The event id of the event containing knock membership change.
pub event_id: OwnedEventId,
/// The timestamp when this request was created.
pub timestamp: Option<UInt>,
/// Some general room member info to display.
pub member_info: RequestToJoinMemberInfo,
/// Whether it's been marked as 'seen' by the client.
Expand All @@ -20,10 +23,11 @@ impl RequestToJoinRoom {
pub(crate) fn new(
room: Arc<Room>,
event_id: &EventId,
timestamp: Option<UInt>,
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.
Expand Down

0 comments on commit 848142a

Please sign in to comment.