diff options
author | Vendicated <vendicated@riseup.net> | 2022-08-29 22:05:22 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-08-29 22:05:22 +0200 |
commit | 483bc13a31ab2ba878ff8d9002b0a8671a640ec8 (patch) | |
tree | 9967493cf8d65dc90202bb76d604749c5c4ba5ca /src/plugins/messageActions.ts | |
parent | c39ff8f6481463a1700014ebd204f2b6189759a1 (diff) | |
download | Vencord-483bc13a31ab2ba878ff8d9002b0a8671a640ec8.tar.gz Vencord-483bc13a31ab2ba878ff8d9002b0a8671a640ec8.tar.bz2 Vencord-483bc13a31ab2ba878ff8d9002b0a8671a640ec8.zip |
Finish rewrite
Diffstat (limited to 'src/plugins/messageActions.ts')
-rw-r--r-- | src/plugins/messageActions.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts new file mode 100644 index 0000000..c2857cb --- /dev/null +++ b/src/plugins/messageActions.ts @@ -0,0 +1,36 @@ +import { MessageClicks } from "../api"; +import definePlugin from "../utils/types"; +import { find, findByProps } from "../utils/webpack"; + +export default definePlugin({ + name: "MessageQuickActions", + description: "Quick Delete, Quick edit", + author: "Vendicated", + start() { + const { deleteMessage, startEditMessage } = findByProps("deleteMessage"); + const { can } = findByProps("can", "initialize"); + const { Permissions: { MANAGE_MESSAGES } } = find(m => m.Permissions?.MANAGE_MESSAGES); + const { getCurrentUser } = findByProps("getCurrentUser"); + + let isDeletePressed = false; + document.addEventListener("keydown", e => { + if (e.key === "Backspace") isDeletePressed = true; + }); + document.addEventListener("keyup", e => { + if (e.key === "Backspace") isDeletePressed = false; + }); + + MessageClicks.addListener((msg, chan, event) => { + const isMe = msg.author.id === getCurrentUser().id; + if (!isDeletePressed) { + if (isMe && event.detail >= 2) { + startEditMessage(chan.id, msg.id, msg.content); + event.preventDefault(); + } + } else if (isMe || can(MANAGE_MESSAGES, chan)) { + deleteMessage(chan.id, msg.id); + event.preventDefault(); + } + }); + } +});
\ No newline at end of file |