Include history fetching in recoverable states

This commit is contained in:
Eric Bailey
2024-05-16 12:39:18 -05:00
parent 8075605796
commit cc7d53e727
+25 -11
View File
@@ -74,7 +74,6 @@ export class Convo {
{id: string; message: ChatBskyConvoSendMessage.InputSchema['message']} {id: string; message: ChatBskyConvoSendMessage.InputSchema['message']}
> = new Map() > = new Map()
private deletedMessages: Set<string> = new Set() private deletedMessages: Set<string> = new Set()
private headerItems: Map<string, ConvoItem> = new Map()
private isProcessingPendingMessages = false private isProcessingPendingMessages = false
@@ -380,9 +379,10 @@ export class Convo {
this.newMessages = new Map() this.newMessages = new Map()
this.pendingMessages = new Map() this.pendingMessages = new Map()
this.deletedMessages = new Set() this.deletedMessages = new Set()
this.headerItems = new Map()
this.pendingMessageFailure = null this.pendingMessageFailure = null
this.fetchMessageHistoryError = undefined
this.firehoseError = undefined
this.dispatch({event: ConvoDispatchEvent.Init}) this.dispatch({event: ConvoDispatchEvent.Init})
} }
@@ -395,6 +395,12 @@ export class Convo {
} else { } else {
this.batchRetryPendingMessages() this.batchRetryPendingMessages()
} }
if (this.fetchMessageHistoryError) {
this.fetchMessageHistoryError.retry()
this.fetchMessageHistoryError = undefined
this.commit()
}
} }
private async setup() { private async setup() {
@@ -532,6 +538,11 @@ export class Convo {
} }
} }
private fetchMessageHistoryError:
| {
retry: () => void
}
| undefined
async fetchMessageHistory() { async fetchMessageHistory() {
logger.debug('Convo: fetch message history', {}, logger.DebugContext.convo) logger.debug('Convo: fetch message history', {}, logger.DebugContext.convo)
@@ -549,7 +560,7 @@ export class Convo {
* If we've rendered a retry state for history fetching, exit. Upon retry, * If we've rendered a retry state for history fetching, exit. Upon retry,
* this will be removed and we'll try again. * this will be removed and we'll try again.
*/ */
if (this.headerItems.has(ConvoItemError.HistoryFailed)) return if (this.fetchMessageHistoryError) return
try { try {
this.isFetchingHistory = true this.isFetchingHistory = true
@@ -598,15 +609,11 @@ export class Convo {
} catch (e: any) { } catch (e: any) {
logger.error('Convo: failed to fetch message history') logger.error('Convo: failed to fetch message history')
this.headerItems.set(ConvoItemError.HistoryFailed, { this.fetchMessageHistoryError = {
type: 'error',
key: ConvoItemError.HistoryFailed,
code: ConvoItemError.HistoryFailed,
retry: () => { retry: () => {
this.headerItems.delete(ConvoItemError.HistoryFailed)
this.fetchMessageHistory() this.fetchMessageHistory()
}, },
}) }
} finally { } finally {
this.isFetchingHistory = false this.isFetchingHistory = false
this.commit() this.commit()
@@ -956,9 +963,16 @@ export class Convo {
} }
}) })
this.headerItems.forEach(item => { if (this.fetchMessageHistoryError) {
items.unshift(item) items.unshift({
type: 'error',
code: ConvoItemError.HistoryFailed,
key: ConvoItemError.HistoryFailed,
retry: () => {
this.maybeRecoverFromNetworkError()
},
}) })
}
this.newMessages.forEach(m => { this.newMessages.forEach(m => {
if (ChatBskyConvoDefs.isMessageView(m)) { if (ChatBskyConvoDefs.isMessageView(m)) {