@@ -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 set_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