Get rid of ad-hoc status checks

This commit is contained in:
Eric Bailey
2024-05-07 11:27:25 -05:00
parent 3baaa94f0e
commit d8682d4a5f
+17 -20
View File
@@ -372,15 +372,16 @@ export class Convo {
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.pollInterval = ACTIVE_POLL_INTERVAL this.pollInterval = ACTIVE_POLL_INTERVAL
this.fetchMessageHistory().then(() => { this.fetchMessageHistory().then(() => {
this.initiatePoll() this.restartPoll()
}) })
break break
} }
case ConvoDispatchEvent.Background: { case ConvoDispatchEvent.Background: {
this.status = ConvoStatus.Backgrounded this.status = ConvoStatus.Backgrounded
this.pollInterval = BACKGROUND_POLL_INTERVAL this.pollInterval = BACKGROUND_POLL_INTERVAL
// TODO truncate history, then poll again this.fetchMessageHistory().then(() => {
this.initiatePoll() this.restartPoll()
})
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
@@ -399,21 +400,24 @@ export class Convo {
switch (action.event) { switch (action.event) {
case ConvoDispatchEvent.Resume: { case ConvoDispatchEvent.Resume: {
this.refreshConvo() this.refreshConvo()
this.initiatePoll() this.restartPoll()
break break
} }
case ConvoDispatchEvent.Background: { case ConvoDispatchEvent.Background: {
this.status = ConvoStatus.Backgrounded this.status = ConvoStatus.Backgrounded
this.pollInterval = BACKGROUND_POLL_INTERVAL this.pollInterval = BACKGROUND_POLL_INTERVAL
this.restartPoll()
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
this.status = ConvoStatus.Suspended this.status = ConvoStatus.Suspended
this.cancelNextPoll()
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.cancelNextPoll()
break break
} }
} }
@@ -425,16 +429,19 @@ export class Convo {
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.pollInterval = ACTIVE_POLL_INTERVAL this.pollInterval = ACTIVE_POLL_INTERVAL
this.refreshConvo() this.refreshConvo()
this.initiatePoll() // TODO truncate history if needed
this.restartPoll()
break break
} }
case ConvoDispatchEvent.Suspend: { case ConvoDispatchEvent.Suspend: {
this.status = ConvoStatus.Suspended this.status = ConvoStatus.Suspended
this.cancelNextPoll()
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.cancelNextPoll()
break break
} }
} }
@@ -446,14 +453,15 @@ export class Convo {
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.pollInterval = ACTIVE_POLL_INTERVAL this.pollInterval = ACTIVE_POLL_INTERVAL
this.refreshConvo() this.refreshConvo()
this.initiatePoll() // TODO truncate history if needed
this.restartPoll()
break break
} }
case ConvoDispatchEvent.Resume: { case ConvoDispatchEvent.Resume: {
this.status = ConvoStatus.Ready this.status = ConvoStatus.Ready
this.pollInterval = ACTIVE_POLL_INTERVAL this.pollInterval = ACTIVE_POLL_INTERVAL
this.refreshConvo() this.refreshConvo()
this.initiatePoll() this.restartPoll()
break break
} }
case ConvoDispatchEvent.Error: { case ConvoDispatchEvent.Error: {
@@ -731,7 +739,7 @@ export class Convo {
} }
} }
private initiatePoll() { private restartPoll() {
this.cancelNextPoll() this.cancelNextPoll()
this.pollLatestEvents() this.pollLatestEvents()
} }
@@ -741,18 +749,10 @@ export class Convo {
} }
private pollLatestEvents() { private pollLatestEvents() {
if (
this.status === ConvoStatus.Ready ||
this.status === ConvoStatus.Backgrounded
) {
/* /*
* Uncomment to view poll events * Uncomment to view poll events
*/ */
logger.debug( logger.debug('Convo: poll events', {id: this.id}, logger.DebugContext.convo)
'Convo: poll events',
{id: this.id},
logger.DebugContext.convo,
)
try { try {
this.fetchLatestEvents().then(({events}) => { this.fetchLatestEvents().then(({events}) => {
@@ -781,9 +781,6 @@ export class Convo {
} }
} }
return
}
private pendingFetchLatestEvents: private pendingFetchLatestEvents:
| Promise<{ | Promise<{
events: ChatBskyConvoGetLog.OutputSchema['logs'] events: ChatBskyConvoGetLog.OutputSchema['logs']