feat(NoAutoReplyMention): Inverse shift reply behaviour (#839)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Amsyar Rasyiq 2023-04-09 12:55:04 +08:00 committed by GitHub
parent 613fa9a57b
commit c4a3d25d37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 31 deletions

View file

@ -16,9 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { migratePluginSettings } from "@api/settings";
import { definePluginSettings, migratePluginSettings, Settings } from "@api/settings";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
@ -31,10 +31,33 @@ let editIdx = -1;
migratePluginSettings("QuickReply", "InteractionKeybinds");
const enum MentionOptions {
DISABLED,
ENABLED,
NO_REPLY_MENTION_PLUGIN
}
const settings = definePluginSettings({
shouldMention: {
type: OptionType.SELECT,
description: "Ping reply by default",
options: [
{
label: "Follow NoReplyMention",
value: MentionOptions.NO_REPLY_MENTION_PLUGIN,
default: true
},
{ label: "Enabled", value: MentionOptions.ENABLED },
{ label: "Disabled", value: MentionOptions.DISABLED },
]
}
});
export default definePlugin({
name: "QuickReply",
authors: [Devs.obscurity, Devs.Ven],
authors: [Devs.obscurity, Devs.Ven, Devs.pylix],
description: "Reply to (ctrl + up/down) and edit (ctrl + shift + up/down) messages via keybinds",
settings,
start() {
Dispatcher.subscribe("DELETE_PENDING_REPLY", onDeletePendingReply);
@ -137,6 +160,14 @@ function getNextMessage(isUp: boolean, isReply: boolean) {
return i === - 1 ? undefined : messages[messages.length - i - 1];
}
function shouldMention() {
switch (settings.store.shouldMention) {
case MentionOptions.NO_REPLY_MENTION_PLUGIN: return !Settings.plugins.NoReplyMention.enabled;
case MentionOptions.DISABLED: return false;
default: return true;
}
}
// handle next/prev reply
function nextReply(isUp: boolean) {
const message = getNextMessage(isUp, true);
@ -149,11 +180,12 @@ function nextReply(isUp: boolean) {
const channel = ChannelStore.getChannel(message.channel_id);
const meId = UserStore.getCurrentUser().id;
Dispatcher.dispatch({
type: "CREATE_PENDING_REPLY",
channel,
message,
shouldMention: true,
shouldMention: shouldMention(),
showMentionToggle: channel.guild_id !== null && message.author.id !== meId,
_isQuickReply: true
});