@@ -115,6 +115,7 @@ export class Federation<TContextData> {
115115 #kv: KvStore ;
116116 #kvPrefixes: FederationKvPrefixes ;
117117 #queue?: MessageQueue ;
118+ #queueStarted: boolean ;
118119 #router: Router ;
119120 #nodeInfoDispatcher?: NodeInfoDispatcher < TContextData > ;
120121 #actorCallbacks?: ActorCallbacks < TContextData > ;
@@ -155,6 +156,7 @@ export class Federation<TContextData> {
155156 ...( kvPrefixes ?? { } ) ,
156157 } ;
157158 this . #queue = queue ;
159+ this . #queueStarted = false ;
158160 this . #router = new Router ( ) ;
159161 this . #router. add ( "/.well-known/webfinger" , "webfinger" ) ;
160162 this . #router. add ( "/.well-known/nodeinfo" , "nodeInfoJrd" ) ;
@@ -175,8 +177,13 @@ export class Federation<TContextData> {
175177 15 * 60_000 ,
176178 60 * 60_000 ,
177179 ] . map ( ( ms ) => Temporal . Duration . from ( { milliseconds : ms } ) ) ;
180+ }
178181
179- queue ?. listen ( this . #listenQueue. bind ( this ) ) ;
182+ #startQueue( ) {
183+ if ( this . #queue != null && ! this . #queueStarted) {
184+ this . #queue?. listen ( this . #listenQueue. bind ( this ) ) ;
185+ this . #queueStarted = true ;
186+ }
180187 }
181188
182189 async #listenQueue( message : OutboxMessage ) : Promise < void > {
@@ -681,6 +688,7 @@ export class Federation<TContextData> {
681688 activity : Activity ,
682689 { preferSharedInbox, immediate } : SendActivityOptions = { } ,
683690 ) : Promise < void > {
691+ this . #startQueue( ) ;
684692 if ( activity . id == null ) {
685693 activity = activity . clone ( {
686694 id : new URL ( `urn:uuid:${ crypto . randomUUID ( ) } ` ) ,
@@ -741,6 +749,7 @@ export class Federation<TContextData> {
741749 contextData,
742750 } : FederationHandlerParameters < TContextData > ,
743751 ) : Promise < Response > {
752+ this . #startQueue( ) ;
744753 onNotFound ??= notFound ;
745754 onNotAcceptable ??= notAcceptable ;
746755 const url = new URL ( request . url ) ;
0 commit comments