@@ -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,12 @@ 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+ self . print_thread_subscription_status ( ) . await ;
236+ }
237+
228238 ( KeyModifiers :: CONTROL , Char ( 'l' ) ) => {
229239 self . toggle_reaction_to_latest_msg ( ) . await
230240 }
@@ -477,10 +487,67 @@ impl RoomView {
477487 self . input . clear ( ) ;
478488 }
479489
490+ async fn subscribe_thread ( & mut self ) {
491+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
492+ self . call_with_room ( async |room, status_handle| {
493+ if let Err ( err) = room. subscribe_thread ( thread_root. clone ( ) , false ) . await {
494+ status_handle. set_message ( format ! ( "error when subscribing to a thread: {err}" ) ) ;
495+ } else {
496+ status_handle. set_message ( "Subscribed to thread!" . to_owned ( ) ) ;
497+ }
498+ } )
499+ . await ;
500+
501+ self . input . clear ( ) ;
502+ }
503+ }
504+
505+ async fn unsubscribe_thread ( & mut self ) {
506+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
507+ self . call_with_room ( async |room, status_handle| {
508+ if let Err ( err) = room. unsubscribe_thread ( thread_root. clone ( ) ) . await {
509+ status_handle
510+ . set_message ( format ! ( "error when unsubscribing to a thread: {err}" ) ) ;
511+ } else {
512+ status_handle. set_message ( "Unsubscribed from thread!" . to_owned ( ) ) ;
513+ }
514+ } )
515+ . await ;
516+
517+ self . input . clear ( ) ;
518+ }
519+ }
520+
521+ async fn print_thread_subscription_status ( & mut self ) {
522+ if let TimelineKind :: Thread { thread_root, .. } = & self . kind {
523+ self . call_with_room ( async |room, status_handle| {
524+ match room. fetch_thread_subscription ( thread_root. clone ( ) ) . await {
525+ Ok ( Some ( subscription) ) => {
526+ status_handle. set_message ( format ! (
527+ "Thread subscription status: {}" ,
528+ if subscription. automatic { "automatic" } else { "manual" }
529+ ) ) ;
530+ }
531+ Ok ( None ) => {
532+ status_handle
533+ . set_message ( "Thread is not subscribed or does not exist" . to_owned ( ) ) ;
534+ }
535+ Err ( err) => {
536+ status_handle
537+ . set_message ( format ! ( "Error getting thread subscription: {err}" ) ) ;
538+ }
539+ }
540+ } )
541+ . await ;
542+ }
543+ }
544+
480545 async fn handle_command ( & mut self , command : input:: Command ) {
481546 match command {
482547 input:: Command :: Invite { user_id } => self . invite_member ( & user_id) . await ,
483548 input:: Command :: Leave => self . leave_room ( ) . await ,
549+ input:: Command :: Subscribe => self . subscribe_thread ( ) . await ,
550+ input:: Command :: Unsubscribe => self . unsubscribe_thread ( ) . await ,
484551 }
485552 }
486553
0 commit comments