Skip to content

Commit

Permalink
ffi: expose pin_event and unpin_event, also the currently pinned …
Browse files Browse the repository at this point in the history
…event ids in `RoomInfo`
  • Loading branch information
jmartinesp authored and andybalaam committed Jul 26, 2024
1 parent ab04945 commit 6fca1e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bindings/matrix-sdk-ffi/src/room_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct RoomInfo {
/// Events causing mentions/highlights for the user, according to their
/// notification settings.
num_unread_mentions: u64,
/// The currently pinned event ids
pinned_event_ids: Vec<String>,
}

impl RoomInfo {
Expand All @@ -64,6 +66,7 @@ impl RoomInfo {
for (id, level) in power_levels_map.iter() {
user_power_levels.insert(id.to_string(), *level);
}
let pinned_event_ids = room.pinned_events().iter().map(|id| id.to_string()).collect();

Ok(Self {
id: room.room_id().to_string(),
Expand Down Expand Up @@ -109,6 +112,7 @@ impl RoomInfo {
num_unread_messages: room.num_unread_messages(),
num_unread_notifications: room.num_unread_notifications(),
num_unread_mentions: room.num_unread_mentions(),
pinned_event_ids,
})
}
}
20 changes: 20 additions & 0 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,26 @@ impl Timeline {
)),
}
}

/// Adds a new pinned event by sending an updated `m.room.pinned_events`
/// event containing the new event id.
///
/// Returns `true` if we sent the request, `false` if the event was already
/// pinned.
async fn pin_event(&self, event_id: String) -> Result<bool, ClientError> {
let event_id = EventId::parse(event_id).map_err(ClientError::from)?;
self.inner.pin_event(&event_id).await.map_err(ClientError::from)
}

/// Adds a new pinned event by sending an updated `m.room.pinned_events`
/// event without the event id we want to remove.
///
/// Returns `true` if we sent the request, `false` if the event wasn't
/// pinned
async fn unpin_event(&self, event_id: String) -> Result<bool, ClientError> {
let event_id = EventId::parse(event_id).map_err(ClientError::from)?;
self.inner.unpin_event(&event_id).await.map_err(ClientError::from)
}
}

#[derive(uniffi::Object)]
Expand Down

0 comments on commit 6fca1e8

Please sign in to comment.