Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,34 @@ export function Messages(props: Props) {
);
}
}
/**
* Handle bulk-deleted messages
*/
function onMessageDeleteBulk(
deleted_messages: { id: string; channelId: string }[],
channel?: { id: string },
) {
if (channel?.id === props.channel.id) {
setMessages((messages) =>
messages.filter(
(msg) => !deleted_messages.find((m) => m.id === msg.id),
),
);
}
}

// Add listener for messages
onMount(() => {
const c = client();
c.addListener("messageCreate", onMessage);
c.addListener("messageDelete", onMessageDelete);
c.addListener("messageDeleteBulk", onMessageDeleteBulk);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something here? Does this ever get called?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but only when the element is first mounted. The onMessageDeleteBulk function is only called when a bulk deletion event is received by the client. The listener is also removed when the element is unmounted.

It worked on my (very limited) testing, used Automod to bulk delete 10 messages and could confirm that the message elements did not persist.

});

onCleanup(() => {
const c = client();
c.removeListener("messageCreate", onMessage);
c.removeListener("messageDeleteBulk", onMessageDeleteBulk);
c.removeListener("messageDelete", onMessageDelete);
});

Expand Down
Loading