@@ -9,7 +9,8 @@ use matrix_sdk::{
99 Client , Room , RoomState ,
1010 locks:: Mutex ,
1111 ruma:: {
12- OwnedRoomId , RoomId , UserId , api:: client:: receipt:: create_receipt:: v3:: ReceiptType ,
12+ OwnedEventId , OwnedRoomId , RoomId , UserId ,
13+ api:: client:: receipt:: create_receipt:: v3:: ReceiptType ,
1314 events:: room:: message:: RoomMessageEventContent ,
1415 } ,
1516} ;
@@ -52,6 +53,7 @@ enum TimelineKind {
5253
5354 Thread {
5455 room : OwnedRoomId ,
56+ thread_root : OwnedEventId ,
5557 /// The threaded-focused timeline for this thread.
5658 timeline : Arc < OnceCell < Arc < Timeline > > > ,
5759 /// Items in the thread timeline (to avoid recomputing them every single
@@ -145,10 +147,11 @@ impl RoomView {
145147 let i = items. clone ( ) ;
146148 let t = thread_timeline. clone ( ) ;
147149 let root = root_event_id;
150+ let cloned_root = root. clone ( ) ;
148151 let r = room. clone ( ) ;
149152 let task = spawn ( async move {
150153 let timeline = TimelineBuilder :: new ( & r)
151- . with_focus ( TimelineFocus :: Thread { root_event_id : root . clone ( ) } )
154+ . with_focus ( TimelineFocus :: Thread { root_event_id : cloned_root } )
152155 . track_read_marker_and_receipts ( )
153156 . build ( )
154157 . await
@@ -171,6 +174,7 @@ impl RoomView {
171174 self . timeline_list . unselect ( ) ;
172175
173176 self . kind = TimelineKind :: Thread {
177+ thread_root : root,
174178 room : room. room_id ( ) . to_owned ( ) ,
175179 timeline : thread_timeline,
176180 items,
@@ -225,6 +229,42 @@ impl RoomView {
225229 self . switch_to_room_timeline ( None ) ;
226230 }
227231
232+ // Pressing 'Alt+s' on a threaded timeline will print the current
233+ // subscription status.
234+ ( KeyModifiers :: ALT , Char ( 's' ) ) => {
235+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
236+ if let Some ( room) = self . room ( ) {
237+ match room. get_thread_subscription ( thread_root. clone ( ) ) . await {
238+ Ok ( Some ( subscription) ) => {
239+ self . status_handle . set_message ( format ! (
240+ "Thread subscription status: {}" ,
241+ if subscription. automatic {
242+ "automatic"
243+ } else {
244+ "manual"
245+ }
246+ ) ) ;
247+ }
248+ Ok ( None ) => {
249+ self . status_handle . set_message (
250+ "Thread is not subscribed or does not exist"
251+ . to_owned ( ) ,
252+ ) ;
253+ }
254+ Err ( err) => {
255+ self . status_handle . set_message ( format ! (
256+ "Error getting thread subscription: {err}"
257+ ) ) ;
258+ }
259+ }
260+ } else {
261+ self . status_handle . set_message (
262+ "No room selected for thread subscription" . to_owned ( ) ,
263+ ) ;
264+ }
265+ }
266+ }
267+
228268 ( KeyModifiers :: CONTROL , Char ( 'l' ) ) => {
229269 self . toggle_reaction_to_latest_msg ( ) . await
230270 }
@@ -477,10 +517,39 @@ impl RoomView {
477517 self . input . clear ( ) ;
478518 }
479519
520+ async fn subscribe_thread ( & mut self ) {
521+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
522+ self . call_with_room ( async |room, status_handle| {
523+ if let Err ( err) = room. subscribe_thread ( thread_root. clone ( ) , false ) . await {
524+ status_handle. set_message ( format ! ( "error when subscribing to a thread: {err}" ) ) ;
525+ }
526+ } )
527+ . await ;
528+
529+ self . input . clear ( ) ;
530+ }
531+ }
532+
533+ async fn unsubscribe_thread ( & mut self ) {
534+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
535+ self . call_with_room ( async |room, status_handle| {
536+ if let Err ( err) = room. unsubscribe_thread ( thread_root. clone ( ) ) . await {
537+ status_handle
538+ . set_message ( format ! ( "error when unsubscribing to a thread: {err}" ) ) ;
539+ }
540+ } )
541+ . await ;
542+
543+ self . input . clear ( ) ;
544+ }
545+ }
546+
480547 async fn handle_command ( & mut self , command : input:: Command ) {
481548 match command {
482549 input:: Command :: Invite { user_id } => self . invite_member ( & user_id) . await ,
483550 input:: Command :: Leave => self . leave_room ( ) . await ,
551+ input:: Command :: SubscribeThread => self . subscribe_thread ( ) . await ,
552+ input:: Command :: UnsubscribeThread => self . unsubscribe_thread ( ) . await ,
484553 }
485554 }
486555
0 commit comments