@@ -9,7 +9,8 @@ use matrix_sdk::{
9
9
Client , Room , RoomState ,
10
10
locks:: Mutex ,
11
11
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 ,
13
14
events:: room:: message:: RoomMessageEventContent ,
14
15
} ,
15
16
} ;
@@ -52,6 +53,7 @@ enum TimelineKind {
52
53
53
54
Thread {
54
55
room : OwnedRoomId ,
56
+ thread_root : OwnedEventId ,
55
57
/// The threaded-focused timeline for this thread.
56
58
timeline : Arc < OnceCell < Arc < Timeline > > > ,
57
59
/// Items in the thread timeline (to avoid recomputing them every single
@@ -145,10 +147,11 @@ impl RoomView {
145
147
let i = items. clone ( ) ;
146
148
let t = thread_timeline. clone ( ) ;
147
149
let root = root_event_id;
150
+ let cloned_root = root. clone ( ) ;
148
151
let r = room. clone ( ) ;
149
152
let task = spawn ( async move {
150
153
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 } )
152
155
. track_read_marker_and_receipts ( )
153
156
. build ( )
154
157
. await
@@ -171,6 +174,7 @@ impl RoomView {
171
174
self . timeline_list . unselect ( ) ;
172
175
173
176
self . kind = TimelineKind :: Thread {
177
+ thread_root : root,
174
178
room : room. room_id ( ) . to_owned ( ) ,
175
179
timeline : thread_timeline,
176
180
items,
@@ -225,6 +229,12 @@ impl RoomView {
225
229
self . switch_to_room_timeline ( None ) ;
226
230
}
227
231
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
+
228
238
( KeyModifiers :: CONTROL , Char ( 'l' ) ) => {
229
239
self . toggle_reaction_to_latest_msg ( ) . await
230
240
}
@@ -477,10 +487,67 @@ impl RoomView {
477
487
self . input . clear ( ) ;
478
488
}
479
489
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
+
480
545
async fn handle_command ( & mut self , command : input:: Command ) {
481
546
match command {
482
547
input:: Command :: Invite { user_id } => self . invite_member ( & user_id) . await ,
483
548
input:: Command :: Leave => self . leave_room ( ) . await ,
549
+ input:: Command :: Subscribe => self . subscribe_thread ( ) . await ,
550
+ input:: Command :: Unsubscribe => self . unsubscribe_thread ( ) . await ,
484
551
}
485
552
}
486
553
0 commit comments