Add retry to pending-message

This commit is contained in:
Eric Bailey
2024-05-15 10:44:27 -05:00
parent 693fb151e9
commit 8aec7b0d04
2 changed files with 28 additions and 21 deletions
+14 -20
View File
@@ -735,6 +735,8 @@ export class Convo {
}
}
private pendingFailed = false
async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) {
// Ignore empty messages for now since they have no other purpose atm
if (!message.text.trim()) return
@@ -748,9 +750,12 @@ export class Convo {
message,
})
// remove on each send, it might go through now without user having to click
// TODO do need htis?
this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit()
// TODO maybe ignore if failed?
if (!this.isProcessingPendingMessages) {
this.processPendingMessages()
}
@@ -805,16 +810,7 @@ export class Convo {
this.commit()
} catch (e: any) {
logger.error(e, {context: `Convo: failed to send message`})
this.footerItems.set(ConvoItemError.PendingFailed, {
type: 'error-recoverable',
key: ConvoItemError.PendingFailed,
code: ConvoItemError.PendingFailed,
retry: () => {
this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit()
this.batchRetryPendingMessages()
},
})
this.pendingFailed = true
this.commit()
} finally {
this.isProcessingPendingMessages = false
@@ -868,16 +864,7 @@ export class Convo {
)
} catch (e: any) {
logger.error(e, {context: `Convo: failed to batch retry messages`})
this.footerItems.set(ConvoItemError.PendingFailed, {
type: 'error-recoverable',
key: ConvoItemError.PendingFailed,
code: ConvoItemError.PendingFailed,
retry: () => {
this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit()
this.batchRetryPendingMessages()
},
})
this.pendingFailed = true
this.commit()
}
}
@@ -968,6 +955,13 @@ export class Convo {
sender: this.sender!,
},
nextMessage: null,
retry: this.pendingFailed
? () => {
this.pendingFailed = false
this.commit()
this.batchRetryPendingMessages()
}
: undefined,
})
})
+14 -1
View File
@@ -83,7 +83,7 @@ export type ConvoDispatch =
export type ConvoItem =
| {
type: 'message' | 'pending-message'
type: 'message'
key: string
message: ChatBskyConvoDefs.MessageView
nextMessage:
@@ -91,6 +91,19 @@ export type ConvoItem =
| ChatBskyConvoDefs.DeletedMessageView
| null
}
| {
type: 'pending-message'
key: string
message: ChatBskyConvoDefs.MessageView
nextMessage:
| ChatBskyConvoDefs.MessageView
| ChatBskyConvoDefs.DeletedMessageView
| null
/**
* Retry sending the message. If present, the message is in a failed state.
*/
retry?: () => void
}
| {
type: 'deleted-message'
key: string