Add revalidateConvo method

This commit is contained in:
Eric Bailey
2024-05-14 13:44:10 -05:00
parent 0e04b19627
commit 682674de54
2 changed files with 26 additions and 1 deletions
+20 -1
View File
@@ -97,6 +97,7 @@ export class Convo {
this.sendMessage = this.sendMessage.bind(this)
this.deleteMessage = this.deleteMessage.bind(this)
this.fetchMessageHistory = this.fetchMessageHistory.bind(this)
this.revalidateConvo = this.revalidateConvo.bind(this)
this.ingestFirehose = this.ingestFirehose.bind(this)
this.onFirehoseConnect = this.onFirehoseConnect.bind(this)
this.onFirehoseError = this.onFirehoseError.bind(this)
@@ -148,6 +149,7 @@ export class Convo {
deleteMessage: undefined,
sendMessage: undefined,
fetchMessageHistory: undefined,
revalidateConvo: undefined,
}
}
case ConvoStatus.Suspended:
@@ -164,6 +166,7 @@ export class Convo {
deleteMessage: this.deleteMessage,
sendMessage: this.sendMessage,
fetchMessageHistory: this.fetchMessageHistory,
revalidateConvo: this.revalidateConvo,
}
}
case ConvoStatus.Error: {
@@ -178,6 +181,7 @@ export class Convo {
deleteMessage: undefined,
sendMessage: undefined,
fetchMessageHistory: undefined,
revalidateConvo: undefined,
}
}
default: {
@@ -192,6 +196,7 @@ export class Convo {
deleteMessage: undefined,
sendMessage: undefined,
fetchMessageHistory: undefined,
revalidateConvo: undefined,
}
}
}
@@ -489,7 +494,7 @@ export class Convo {
return this.pendingFetchConvo
}
async refreshConvo() {
private async refreshConvo() {
try {
const {convo, sender, recipients} = await this.fetchConvo()
// throw new Error('UNCOMMENT TO TEST REFRESH FAILURE')
@@ -512,6 +517,20 @@ export class Convo {
}
}
async revalidateConvo() {
try {
const {convo, sender, recipients} = await this.fetchConvo()
// throw new Error('UNCOMMENT TO TEST REFRESH FAILURE')
this.convo = convo || this.convo
this.sender = sender || this.sender
this.recipients = recipients || this.recipients
} catch (e: any) {
logger.error(e, {context: `Convo: failed to revalidate convo`})
} finally {
this.commit()
}
}
async fetchMessageHistory() {
logger.debug('Convo: fetch message history', {}, logger.DebugContext.convo)
+6
View File
@@ -124,6 +124,7 @@ export type ConvoStateUninitialized = {
deleteMessage: undefined
sendMessage: undefined
fetchMessageHistory: undefined
revalidateConvo: undefined
}
export type ConvoStateInitializing = {
status: ConvoStatus.Initializing
@@ -136,6 +137,7 @@ export type ConvoStateInitializing = {
deleteMessage: undefined
sendMessage: undefined
fetchMessageHistory: undefined
revalidateConvo: undefined
}
export type ConvoStateReady = {
status: ConvoStatus.Ready
@@ -148,6 +150,7 @@ export type ConvoStateReady = {
deleteMessage: DeleteMessage
sendMessage: SendMessage
fetchMessageHistory: FetchMessageHistory
revalidateConvo: () => void
}
export type ConvoStateBackgrounded = {
status: ConvoStatus.Backgrounded
@@ -160,6 +163,7 @@ export type ConvoStateBackgrounded = {
deleteMessage: DeleteMessage
sendMessage: SendMessage
fetchMessageHistory: FetchMessageHistory
revalidateConvo: () => void
}
export type ConvoStateSuspended = {
status: ConvoStatus.Suspended
@@ -172,6 +176,7 @@ export type ConvoStateSuspended = {
deleteMessage: DeleteMessage
sendMessage: SendMessage
fetchMessageHistory: FetchMessageHistory
revalidateConvo: () => void
}
export type ConvoStateError = {
status: ConvoStatus.Error
@@ -184,6 +189,7 @@ export type ConvoStateError = {
deleteMessage: undefined
sendMessage: undefined
fetchMessageHistory: undefined
revalidateConvo: undefined
}
export type ConvoState =
| ConvoStateUninitialized