Skip to content

Commit c93af79

Browse files
committed
feat(ffi): add support for MSC4036 thread subscriptions
1 parent 509a45e commit c93af79

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file.
88

99
### Features:
1010

11+
- Add experimental support for
12+
[MSC4306](https://github.com/matrix-org/matrix-spec-proposals/pull/4306), with the
13+
`Room::fetch_thread_subscription()` and `Room::toggle_thread_subscription()` methods.
14+
([#5442](https://github.com/matrix-org/matrix-rust-sdk/pull/5442))
1115
- [**breaking**] [`GalleryUploadParameters::reply`] and [`UploadParameters::reply`] have been both
1216
replaced with a new optional `in_reply_to` field, that's a string which will be parsed into an
1317
`OwnedEventId` when sending the event. The thread relationship will be automatically filled in,

bindings/matrix-sdk-ffi/src/room/mod.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,59 @@ impl Room {
11391139

11401140
Ok(Arc::new(RoomPreview::new(AsyncRuntimeDropped::new(client), room_preview)))
11411141
}
1142+
1143+
/// Toggle a MSC4306 subscription to a thread in this room, based on the
1144+
/// thread root event id.
1145+
///
1146+
/// If `subscribed` is `true`, it will subscribe to the thread, with a
1147+
/// precision that the subscription was manually requested by the user
1148+
/// (i.e. not automatic).
1149+
///
1150+
/// If the thread was already subscribed to (resp. unsubscribed from), while
1151+
/// trying to subscribe to it (resp. unsubscribe from it), it will do
1152+
/// nothing, i.e. subscribing (resp. unsubscribing) to a thread is an
1153+
/// idempotent operation.
1154+
pub async fn toggle_thread_subscription(
1155+
&self,
1156+
thread_root_event_id: String,
1157+
subscribed: bool,
1158+
) -> Result<(), ClientError> {
1159+
let thread_root = EventId::parse(thread_root_event_id)?;
1160+
if subscribed {
1161+
// This is a manual subscription.
1162+
let automatic = false;
1163+
self.inner.subscribe_thread(thread_root, automatic).await?;
1164+
} else {
1165+
self.inner.unsubscribe_thread(thread_root).await?;
1166+
}
1167+
Ok(())
1168+
}
1169+
1170+
/// Return the current MSC4306 thread subscription for the given thread root
1171+
/// in this room.
1172+
///
1173+
/// Returns `None` if the thread doesn't exist, or isn't subscribed to, or
1174+
/// the server can't handle MSC4306; otherwise, returns the thread
1175+
/// subscription status.
1176+
pub async fn fetch_thread_subscription(
1177+
&self,
1178+
thread_root_event_id: String,
1179+
) -> Result<Option<ThreadSubscription>, ClientError> {
1180+
let thread_root = EventId::parse(thread_root_event_id)?;
1181+
Ok(self
1182+
.inner
1183+
.fetch_thread_subscription(thread_root)
1184+
.await?
1185+
.map(|sub| ThreadSubscription { automatic: sub.automatic }))
1186+
}
1187+
}
1188+
1189+
/// Status of a thread subscription (MSC4306).
1190+
#[derive(uniffi::Record)]
1191+
pub struct ThreadSubscription {
1192+
/// Whether the thread subscription happened automatically (e.g. after a
1193+
/// mention) or if it was manually requested by the user.
1194+
automatic: bool,
11421195
}
11431196

11441197
/// A listener for receiving new live location shares in a room.

0 commit comments

Comments
 (0)