From b51ce1b91bece0ae9c7d82bfa2196c511c6b36f4 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 8 May 2024 17:04:27 -0500 Subject: [PATCH] Clean up poll interval updates --- src/state/messages/convo/agent.ts | 27 +++++++++++++-------------- src/state/messages/events/agent.ts | 10 +++++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index c54321525f..a852934941 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -210,6 +210,7 @@ export class Convo { case ConvoDispatchEvent.Init: { this.status = ConvoStatus.Initializing this.setup() + this.requestPollInterval(ACTIVE_POLL_INTERVAL) break } } @@ -225,15 +226,18 @@ export class Convo { case ConvoDispatchEvent.Background: { this.status = ConvoStatus.Backgrounded this.fetchMessageHistory() + this.requestPollInterval(BACKGROUND_POLL_INTERVAL) break } case ConvoDispatchEvent.Suspend: { this.status = ConvoStatus.Suspended + this.withdrawRequestedPollInterval() break } case ConvoDispatchEvent.Error: { this.status = ConvoStatus.Error this.error = action.payload + this.withdrawRequestedPollInterval() break } } @@ -243,19 +247,23 @@ export class Convo { switch (action.event) { case ConvoDispatchEvent.Resume: { this.refreshConvo() + this.requestPollInterval(ACTIVE_POLL_INTERVAL) break } case ConvoDispatchEvent.Background: { this.status = ConvoStatus.Backgrounded + this.requestPollInterval(BACKGROUND_POLL_INTERVAL) break } case ConvoDispatchEvent.Suspend: { this.status = ConvoStatus.Suspended + this.withdrawRequestedPollInterval() break } case ConvoDispatchEvent.Error: { this.status = ConvoStatus.Error this.error = action.payload + this.withdrawRequestedPollInterval() break } } @@ -272,15 +280,18 @@ export class Convo { this.status = ConvoStatus.Initializing this.setup() } + this.requestPollInterval(ACTIVE_POLL_INTERVAL) break } case ConvoDispatchEvent.Suspend: { this.status = ConvoStatus.Suspended + this.withdrawRequestedPollInterval() break } case ConvoDispatchEvent.Error: { this.status = ConvoStatus.Error this.error = action.payload + this.withdrawRequestedPollInterval() break } } @@ -288,20 +299,12 @@ export class Convo { } case ConvoStatus.Suspended: { switch (action.event) { - // TODO truncate history if needed case ConvoDispatchEvent.Init: { - if (this.convo) { - this.status = ConvoStatus.Ready - this.refreshConvo() - } else { - this.status = ConvoStatus.Initializing - this.setup() - } + this.reset() break } case ConvoDispatchEvent.Resume: { - this.status = ConvoStatus.Ready - this.refreshConvo() + this.reset() break } case ConvoDispatchEvent.Error: { @@ -414,22 +417,18 @@ export class Convo { init() { this.dispatch({event: ConvoDispatchEvent.Init}) - this.requestPollInterval(ACTIVE_POLL_INTERVAL) } resume() { this.dispatch({event: ConvoDispatchEvent.Resume}) - this.requestPollInterval(ACTIVE_POLL_INTERVAL) } background() { this.dispatch({event: ConvoDispatchEvent.Background}) - this.requestPollInterval(BACKGROUND_POLL_INTERVAL) } suspend() { this.dispatch({event: ConvoDispatchEvent.Suspend}) - this.withdrawRequestedPollInterval() DEBUG_ACTIVE_CHAT = undefined } diff --git a/src/state/messages/events/agent.ts b/src/state/messages/events/agent.ts index f22cff9d96..71a3d21370 100644 --- a/src/state/messages/events/agent.ts +++ b/src/state/messages/events/agent.ts @@ -347,7 +347,15 @@ export class MessagesEventBus { this.isPolling = true - logger.debug(`${LOGGER_CONTEXT}: poll`, {}, logger.DebugContext.convo) + logger.debug( + `${LOGGER_CONTEXT}: poll`, + { + requestedPollIntervals: Array.from( + this.requestedPollIntervals.values(), + ), + }, + logger.DebugContext.convo, + ) try { const response = await this.agent.api.chat.bsky.convo.getLog(