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

### Features

- Expose `Room.account_data()`, `Room.set_account_data()`, and `Room.get_state_event()`
through FFI bindings, allowing non-Rust clients to read/write room-scoped account data
and read room state events.
Comment on lines +44 to +46
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you apply the renamings here too, add the point about custom events, and include the PR number as done on other lines below?

- Added the `Client::import_secrets_bundle` method.
([#6212](https://github.com/matrix-org/matrix-rust-sdk/pull/6212))
- [**breaking**] Remove support for `native-tls` and remove all feature
Expand Down
52 changes: 52 additions & 0 deletions bindings/matrix-sdk-ffi/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use matrix_sdk::{
},
send_queue::RoomSendQueueUpdate as SdkRoomSendQueueUpdate,
};
use matrix_sdk_base::deserialized_responses::RawAnySyncOrStrippedState;
use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm};
use matrix_sdk_ui::{
timeline::{RoomExt, TimelineBuilder, default_event_filter},
Expand All @@ -38,13 +39,16 @@ use ruma::{
ServerName, UserId, assign,
events::{
AnyMessageLikeEventContent, AnySyncTimelineEvent,
RoomAccountDataEventType as RumaRoomAccountDataEventType,
StateEventType as RumaStateEventType,
receipt::ReceiptThread,
room::{
MediaSource as RumaMediaSource, avatar::ImageInfo as RumaAvatarImageInfo,
history_visibility::HistoryVisibility as RumaHistoryVisibility,
join_rules::JoinRule as RumaJoinRule, message::RoomMessageEventContentWithoutRelation,
},
},
serde::Raw,
};
use tracing::{error, warn};

Expand Down Expand Up @@ -699,6 +703,54 @@ impl Room {
Ok(self.inner.set_unread_flag(new_value).await?)
}

/// Get the content of the event of the given type out of the room's
/// account data store as a JSON string.
///
/// This is mostly useful for custom event types that are not modeled by
/// typed SDK APIs.
pub async fn account_data_json(
&self,
event_type: String,
) -> Result<Option<String>, ClientError> {
let event_type = RumaRoomAccountDataEventType::from(event_type);
let event = self.inner.account_data(event_type).await?;
Ok(event.map(|e| e.json().get().to_owned()))
}

/// Set the given account data content for the given event type in
/// this room, from a JSON string.
///
/// This is mostly useful for custom event types that are not modeled by
/// typed SDK APIs.
pub async fn set_account_data_json(
&self,
event_type: String,
content: String,
) -> Result<(), ClientError> {
let event_type = RumaRoomAccountDataEventType::from(event_type);
let raw_content = Raw::from_json_string(content)?;
self.inner.set_account_data_raw(event_type, raw_content).await?;
Ok(())
}

/// Get a specific state event in this room, from the local store, as a
/// JSON string.
///
/// This is mostly useful for custom event types that are not modeled by
/// typed SDK APIs. Returns `None` if no such state event exists.
pub async fn get_state_event_json(
&self,
event_type: String,
state_key: String,
) -> Result<Option<String>, ClientError> {
let event_type = RumaStateEventType::from(event_type);
let raw = self.inner.get_state_event(event_type, &state_key).await?;
Ok(raw.map(|e| match e {
RawAnySyncOrStrippedState::Sync(ev) => ev.json().get().to_owned(),
RawAnySyncOrStrippedState::Stripped(ev) => ev.json().get().to_owned(),
}))
}

/// Mark a room as read, by attaching a read receipt on the latest event.
///
/// Note: this does NOT unset the unread flag; it's the caller's
Expand Down
Loading