@@ -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,42 @@ 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
+ 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
+
228
268
( KeyModifiers :: CONTROL , Char ( 'l' ) ) => {
229
269
self . toggle_reaction_to_latest_msg ( ) . await
230
270
}
@@ -477,10 +517,39 @@ impl RoomView {
477
517
self . input . clear ( ) ;
478
518
}
479
519
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
+
480
547
async fn handle_command ( & mut self , command : input:: Command ) {
481
548
match command {
482
549
input:: Command :: Invite { user_id } => self . invite_member ( & user_id) . await ,
483
550
input:: Command :: Leave => self . leave_room ( ) . await ,
551
+ input:: Command :: SubscribeThread => self . subscribe_thread ( ) . await ,
552
+ input:: Command :: UnsubscribeThread => self . unsubscribe_thread ( ) . await ,
484
553
}
485
554
}
486
555
0 commit comments