Clean up poll interval updates

This commit is contained in:
Eric Bailey
2024-05-08 17:04:27 -05:00
parent b1e737d532
commit b51ce1b91b
2 changed files with 22 additions and 15 deletions
+13 -14
View File
@@ -210,6 +210,7 @@ export class Convo {
case ConvoDispatchEvent.Init: { case ConvoDispatchEvent.Init: {
this.status = ConvoStatus.Initializing this.status = ConvoStatus.Initializing
this.setup() this.setup()
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
break break
} }
} }
@@ -225,15 +226,18 @@ export class Convo {
case ConvoDispatchEvent.Background: { case ConvoDispatchEvent.Background: {
this.status = ConvoStatus.Backgrounded this.status = ConvoStatus.Backgrounded
this.fetchMessageHistory() this.fetchMessageHistory()
this.requestPollInterval(BACKGROUND_POLL_INTERVAL)
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
this.status = ConvoStatus.Suspended this.status = ConvoStatus.Suspended
this.withdrawRequestedPollInterval()
break break
} }
case ConvoDispatchEvent.Error: { case ConvoDispatchEvent.Error: {
this.status = ConvoStatus.Error this.status = ConvoStatus.Error
this.error = action.payload this.error = action.payload
this.withdrawRequestedPollInterval()
break break
} }
} }
@@ -243,19 +247,23 @@ export class Convo {
switch (action.event) { switch (action.event) {
case ConvoDispatchEvent.Resume: { case ConvoDispatchEvent.Resume: {
this.refreshConvo() this.refreshConvo()
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
break break
} }
case ConvoDispatchEvent.Background: { case ConvoDispatchEvent.Background: {
this.status = ConvoStatus.Backgrounded this.status = ConvoStatus.Backgrounded
this.requestPollInterval(BACKGROUND_POLL_INTERVAL)
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
this.status = ConvoStatus.Suspended this.status = ConvoStatus.Suspended
this.withdrawRequestedPollInterval()
break break
} }
case ConvoDispatchEvent.Error: { case ConvoDispatchEvent.Error: {
this.status = ConvoStatus.Error this.status = ConvoStatus.Error
this.error = action.payload this.error = action.payload
this.withdrawRequestedPollInterval()
break break
} }
} }
@@ -272,15 +280,18 @@ export class Convo {
this.status = ConvoStatus.Initializing this.status = ConvoStatus.Initializing
this.setup() this.setup()
} }
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
this.status = ConvoStatus.Suspended this.status = ConvoStatus.Suspended
this.withdrawRequestedPollInterval()
break break
} }
case ConvoDispatchEvent.Error: { case ConvoDispatchEvent.Error: {
this.status = ConvoStatus.Error this.status = ConvoStatus.Error
this.error = action.payload this.error = action.payload
this.withdrawRequestedPollInterval()
break break
} }
} }
@@ -288,20 +299,12 @@ export class Convo {
} }
case ConvoStatus.Suspended: { case ConvoStatus.Suspended: {
switch (action.event) { switch (action.event) {
// TODO truncate history if needed
case ConvoDispatchEvent.Init: { case ConvoDispatchEvent.Init: {
if (this.convo) { this.reset()
this.status = ConvoStatus.Ready
this.refreshConvo()
} else {
this.status = ConvoStatus.Initializing
this.setup()
}
break break
} }
case ConvoDispatchEvent.Resume: { case ConvoDispatchEvent.Resume: {
this.status = ConvoStatus.Ready this.reset()
this.refreshConvo()
break break
} }
case ConvoDispatchEvent.Error: { case ConvoDispatchEvent.Error: {
@@ -414,22 +417,18 @@ export class Convo {
init() { init() {
this.dispatch({event: ConvoDispatchEvent.Init}) this.dispatch({event: ConvoDispatchEvent.Init})
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
} }
resume() { resume() {
this.dispatch({event: ConvoDispatchEvent.Resume}) this.dispatch({event: ConvoDispatchEvent.Resume})
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
} }
background() { background() {
this.dispatch({event: ConvoDispatchEvent.Background}) this.dispatch({event: ConvoDispatchEvent.Background})
this.requestPollInterval(BACKGROUND_POLL_INTERVAL)
} }
suspend() { suspend() {
this.dispatch({event: ConvoDispatchEvent.Suspend}) this.dispatch({event: ConvoDispatchEvent.Suspend})
this.withdrawRequestedPollInterval()
DEBUG_ACTIVE_CHAT = undefined DEBUG_ACTIVE_CHAT = undefined
} }
+9 -1
View File
@@ -347,7 +347,15 @@ export class MessagesEventBus {
this.isPolling = true 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 { try {
const response = await this.agent.api.chat.bsky.convo.getLog( const response = await this.agent.api.chat.bsky.convo.getLog(