Handle failures

This commit is contained in:
Eric Bailey
2024-05-02 12:57:03 -05:00
parent 91cef31f1b
commit 56071f7069
+26 -26
View File
@@ -279,6 +279,8 @@ export class Convo {
* this.pastMessages.set(log.message.id, log.message)
*/
this.pastMessages.delete(log.message.id)
this.newMessages.delete(log.message.id)
this.deletedMessages.delete(log.message.id)
}
}
}
@@ -412,6 +414,30 @@ export class Convo {
}
}
async deleteMessage(messageId: string) {
this.deletedMessages.add(messageId)
this.commit()
try {
await this.agent.api.chat.bsky.convo.deleteMessageForSelf(
{
convoId: this.convoId,
messageId,
},
{
encoding: 'application/json',
headers: {
Authorization: this.__tempFromUserDid,
},
},
)
} catch (e) {
this.deletedMessages.delete(messageId)
this.commit()
throw e
}
}
/*
* Items in reverse order, since FlatList inverts
*/
@@ -514,32 +540,6 @@ export class Convo {
})
}
async deleteMessage(messageId: string) {
this.deletedMessages.add(messageId)
this.commit()
await this.agent.api.chat.bsky.convo.deleteMessageForSelf(
{
convoId: this.convoId,
messageId,
},
{
encoding: 'application/json',
headers: {
Authorization: this.__tempFromUserDid,
},
},
)
// remove from optimistic
this.deletedMessages.delete(messageId)
// remove from either new or past messages
this.pastMessages.delete(messageId)
this.newMessages.delete(messageId)
// commit
this.commit()
}
destroy() {
this.status = ConvoStatus.Destroyed
this.commit()