@@ -103,7 +103,7 @@ use crate::{
103103 notification:: NotificationClient ,
104104 notification_settings:: NotificationSettings ,
105105 qr_code:: LoginWithQrCodeHandler ,
106- room:: { RoomHistoryVisibility , RoomInfoListener } ,
106+ room:: { RoomHistoryVisibility , RoomInfoListener , RoomSendQueueUpdate } ,
107107 room_directory_search:: RoomDirectorySearch ,
108108 room_preview:: RoomPreview ,
109109 ruma:: {
@@ -195,6 +195,13 @@ pub trait ProgressWatcher: SyncOutsideWasm + SendOutsideWasm {
195195 fn transmission_progress ( & self , progress : TransmissionProgress ) ;
196196}
197197
198+ /// A listener to the global (client-wide) update reporter of the send queue.
199+ #[ matrix_sdk_ffi_macros:: export( callback_interface) ]
200+ pub trait SendQueueRoomUpdateListener : SyncOutsideWasm + SendOutsideWasm {
201+ /// Called every time the send queue emits an update for a given room.
202+ fn on_update ( & self , room_id : String , update : RoomSendQueueUpdate ) ;
203+ }
204+
198205/// A listener to the global (client-wide) error reporter of the send queue.
199206#[ matrix_sdk_ffi_macros:: export( callback_interface) ]
200207pub trait SendQueueRoomErrorListener : SyncOutsideWasm + SendOutsideWasm {
@@ -607,6 +614,49 @@ impl Client {
607614 self . inner . send_queue ( ) . enable_upload_progress ( enable) ;
608615 }
609616
617+ /// Subscribe to the global send queue update reporter, at the
618+ /// client-wide level.
619+ ///
620+ /// The given listener will be immediately called with
621+ /// `RoomSendQueueUpdate::NewLocalEvent` for each local echo existing in
622+ /// the queue.
623+ pub async fn subscribe_to_send_queue_updates (
624+ & self ,
625+ listener : Box < dyn SendQueueRoomUpdateListener > ,
626+ ) -> Result < Arc < TaskHandle > , ClientError > {
627+ let q = self . inner . send_queue ( ) ;
628+ let local_echoes = q. local_echoes ( ) . await ?;
629+ let mut subscriber = q. subscribe ( ) ;
630+
631+ for ( room_id, local_echoes) in local_echoes {
632+ for local_echo in local_echoes {
633+ listener. on_update (
634+ room_id. clone ( ) . into ( ) ,
635+ RoomSendQueueUpdate :: NewLocalEvent {
636+ transaction_id : local_echo. transaction_id . into ( ) ,
637+ } ,
638+ ) ;
639+ }
640+ }
641+
642+ Ok ( Arc :: new ( TaskHandle :: new ( get_runtime_handle ( ) . spawn ( async move {
643+ loop {
644+ match subscriber. recv ( ) . await {
645+ Ok ( update) => {
646+ let room_id = update. room_id . to_string ( ) ;
647+ match update. update . try_into ( ) {
648+ Ok ( update) => listener. on_update ( room_id, update) ,
649+ Err ( err) => error ! ( "error when converting send queue update: {err}" ) ,
650+ }
651+ }
652+ Err ( err) => {
653+ error ! ( "error when listening to the send queue update reporter: {err}" ) ;
654+ }
655+ }
656+ }
657+ } ) ) ) )
658+ }
659+
610660 /// Subscribe to the global enablement status of the send queue, at the
611661 /// client-wide level.
612662 ///
0 commit comments