Improve permission checks on several plugins (#1746)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Hugo C 2023-09-24 16:42:53 +02:00 committed by GitHub
parent 0b7fca864a
commit 044f64e446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 25 deletions

View file

@ -20,7 +20,7 @@ import { definePluginSettings, Settings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
const Kangaroo = findByPropsLazy("jumpToMessage");
@ -172,6 +172,7 @@ function shouldMention(message) {
// handle next/prev reply
function nextReply(isUp: boolean) {
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, ChannelStore.getChannel(SelectedChannelStore.getChannelId()))) return;
const message = getNextMessage(isUp, true);
if (!message)
@ -179,7 +180,6 @@ function nextReply(isUp: boolean) {
type: "DELETE_PENDING_REPLY",
channelId: SelectedChannelStore.getChannelId(),
});
const channel = ChannelStore.getChannel(message.channel_id);
const meId = UserStore.getCurrentUser().id;
@ -196,21 +196,20 @@ function nextReply(isUp: boolean) {
// handle next/prev edit
function nextEdit(isUp: boolean) {
if (!PermissionStore.can(PermissionsBits.SEND_MESSAGES, ChannelStore.getChannel(SelectedChannelStore.getChannelId()))) return;
const message = getNextMessage(isUp, false);
if (!message)
Dispatcher.dispatch({
return Dispatcher.dispatch({
type: "MESSAGE_END_EDIT",
channelId: SelectedChannelStore.getChannelId()
});
else {
Dispatcher.dispatch({
type: "MESSAGE_START_EDIT",
channelId: message.channel_id,
messageId: message.id,
content: message.content,
_isQuickEdit: true
});
jumpIfOffScreen(message.channel_id, message.id);
}
Dispatcher.dispatch({
type: "MESSAGE_START_EDIT",
channelId: message.channel_id,
messageId: message.id,
content: message.content,
_isQuickEdit: true
});
jumpIfOffScreen(message.channel_id, message.id);
}