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']) { async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) {
// Ignore empty messages for now since they have no other purpose atm // Ignore empty messages for now since they have no other purpose atm
if (!message.text.trim()) return if (!message.text.trim()) return
@@ -748,9 +750,12 @@ export class Convo {
message, message,
}) })
// remove on each send, it might go through now without user having to click // remove on each send, it might go through now without user having to click
// TODO do need htis?
this.footerItems.delete(ConvoItemError.PendingFailed) this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit() this.commit()
// TODO maybe ignore if failed?
if (!this.isProcessingPendingMessages) { if (!this.isProcessingPendingMessages) {
this.processPendingMessages() this.processPendingMessages()
} }
@@ -805,16 +810,7 @@ export class Convo {
this.commit() this.commit()
} catch (e: any) { } catch (e: any) {
logger.error(e, {context: `Convo: failed to send message`}) logger.error(e, {context: `Convo: failed to send message`})
this.footerItems.set(ConvoItemError.PendingFailed, { this.pendingFailed = true
type: 'error-recoverable',
key: ConvoItemError.PendingFailed,
code: ConvoItemError.PendingFailed,
retry: () => {
this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit()
this.batchRetryPendingMessages()
},
})
this.commit() this.commit()
} finally { } finally {
this.isProcessingPendingMessages = false this.isProcessingPendingMessages = false
@@ -868,16 +864,7 @@ export class Convo {
) )
} catch (e: any) { } catch (e: any) {
logger.error(e, {context: `Convo: failed to batch retry messages`}) logger.error(e, {context: `Convo: failed to batch retry messages`})
this.footerItems.set(ConvoItemError.PendingFailed, { this.pendingFailed = true
type: 'error-recoverable',
key: ConvoItemError.PendingFailed,
code: ConvoItemError.PendingFailed,
retry: () => {
this.footerItems.delete(ConvoItemError.PendingFailed)
this.commit()
this.batchRetryPendingMessages()
},
})
this.commit() this.commit()
} }
} }
@@ -968,6 +955,13 @@ export class Convo {
sender: this.sender!, sender: this.sender!,
}, },
nextMessage: null, 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 = export type ConvoItem =
| { | {
type: 'message' | 'pending-message' type: 'message'
key: string key: string
message: ChatBskyConvoDefs.MessageView message: ChatBskyConvoDefs.MessageView
nextMessage: nextMessage:
@@ -91,6 +91,19 @@ export type ConvoItem =
| ChatBskyConvoDefs.DeletedMessageView | ChatBskyConvoDefs.DeletedMessageView
| null | 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' type: 'deleted-message'
key: string key: string