Skip to content

Commit

Permalink
[Clipclops] Deletions (#3824)
Browse files Browse the repository at this point in the history
* Handle message deletions

* Handle failures
  • Loading branch information
estrattonbailey authored May 2, 2024
1 parent 1a07e23 commit a20fe4c
Showing 1 changed file with 57 additions and 23 deletions.
80 changes: 57 additions & 23 deletions src/state/messages/convo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class Convo {
string,
{id: string; message: ChatBskyConvoSendMessage.InputSchema['message']}
> = new Map()
private deletedMessages: Set<string> = new Set()
private footerItems: Map<string, ConvoItem> = new Map()

private pendingEventIngestion: Promise<void> | undefined
Expand Down Expand Up @@ -278,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)
}
}
}
Expand Down Expand Up @@ -411,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
*/
Expand Down Expand Up @@ -474,36 +501,43 @@ export class Convo {
}
})

return items.map((item, i) => {
let nextMessage = null
const isMessage = isConvoItemMessage(item)

if (isMessage) {
if (
isMessage &&
(ChatBskyConvoDefs.isMessageView(item.message) ||
ChatBskyConvoDefs.isDeletedMessageView(item.message))
) {
const next = items[i - 1]
return items
.filter(item => {
if (isConvoItemMessage(item)) {
return !this.deletedMessages.has(item.message.id)
}
return true
})
.map((item, i) => {
let nextMessage = null
const isMessage = isConvoItemMessage(item)

if (isMessage) {
if (
isConvoItemMessage(next) &&
next &&
(ChatBskyConvoDefs.isMessageView(next.message) ||
ChatBskyConvoDefs.isDeletedMessageView(next.message))
isMessage &&
(ChatBskyConvoDefs.isMessageView(item.message) ||
ChatBskyConvoDefs.isDeletedMessageView(item.message))
) {
nextMessage = next.message
const next = items[i - 1]

if (
isConvoItemMessage(next) &&
next &&
(ChatBskyConvoDefs.isMessageView(next.message) ||
ChatBskyConvoDefs.isDeletedMessageView(next.message))
) {
nextMessage = next.message
}
}
}

return {
...item,
nextMessage,
return {
...item,
nextMessage,
}
}
}

return item
})
return item
})
}

destroy() {
Expand Down

0 comments on commit a20fe4c

Please sign in to comment.