@@ -119,9 +119,27 @@ class ThreadService extends BaseService {
119119 }
120120 } ) ) ;
121121
122+ await this . init_event_listeners_ ( ) ;
122123 await this . init_socket_subs_ ( ) ;
123124 }
124125
126+ async init_event_listeners_ ( ) {
127+ const svc_event = this . services . get ( 'event' ) ;
128+ svc_event . on ( 'outer.thread.notify-subscribers' , async ( _ , {
129+ uid, action, data,
130+ } ) => {
131+
132+ if ( ! this . socket_subs_ [ uid ] ) return ;
133+
134+ const svc_socketio = this . services . get ( 'socketio' ) ;
135+ await svc_socketio . send (
136+ Array . from ( this . socket_subs_ [ uid ] ) . map ( socket => ( { socket } ) ) ,
137+ 'thread.' + action ,
138+ { ...data , subscription : uid } ,
139+ ) ;
140+ } )
141+ }
142+
125143 async init_socket_subs_ ( ) {
126144 this . socket_subs_ = { } ;
127145
@@ -150,14 +168,8 @@ class ThreadService extends BaseService {
150168 }
151169
152170 async notify_subscribers ( uid , action , data ) {
153- if ( ! this . socket_subs_ [ uid ] ) return ;
154-
155- const svc_socketio = this . services . get ( 'socketio' ) ;
156- await svc_socketio . send (
157- Array . from ( this . socket_subs_ [ uid ] ) . map ( socket => ( { socket } ) ) ,
158- 'thread.' + action ,
159- { ...data , subscription : uid } ,
160- ) ;
171+ const svc_event = this . services . get ( 'event' ) ;
172+ svc_event . emit ( 'outer.thread.notify-subscribers' , { uid, action, data } ) ;
161173 }
162174
163175 async [ '__on_install.routes' ] ( _ , { app } ) {
0 commit comments