Compare commits

...

4 commits

Author SHA1 Message Date
Nick H.
6eb2248814
Merge 20f2bb9045 into c7e5295da0 2024-09-18 21:34:13 +02:00
Vendicated
c7e5295da0
SearchReply => FullSearchContext ~ now adds all options back
Some checks are pending
Sync to Codeberg / codeberg (push) Waiting to run
test / test (push) Waiting to run
2024-09-18 21:33:46 +02:00
Nick H.
20f2bb9045
Fixed Header 2024-09-01 15:39:06 -03:00
Nick H.
86f16f68d7
Attempt to fix all inconsistencies; DM Support 2024-09-01 12:03:30 -03:00
5 changed files with 170 additions and 104 deletions

View file

@ -0,0 +1,5 @@
# FullSearchContext
Makes the message context menu in message search results have all options you'd expect.
![](https://github.com/user-attachments/assets/472d1327-3935-44c7-b7c4-0978b5348550)

View file

@ -0,0 +1,82 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { migratePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, ContextMenuApi, i18n, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
import type { MouseEvent } from "react";
const { useMessageMenu } = findByPropsLazy("useMessageMenu");
function MessageMenu({ message, channel, onHeightUpdate }) {
const canReport = message.author &&
!(message.author.id === UserStore.getCurrentUser().id || message.author.system);
return useMessageMenu({
navId: "message-actions",
ariaLabel: i18n.Messages.MESSAGE_UTILITIES_A11Y_LABEL,
message,
channel,
canReport,
onHeightUpdate,
onClose: () => ContextMenuApi.closeContextMenu(),
textSelection: "",
favoriteableType: null,
favoriteableId: null,
favoriteableName: null,
itemHref: void 0,
itemSrc: void 0,
itemSafeSrc: void 0,
itemTextContent: void 0,
});
}
migratePluginSettings("FullSearchContext", "SearchReply");
export default definePlugin({
name: "FullSearchContext",
description: "Makes the message context menu in message search results have all options you'd expect",
authors: [Devs.Ven, Devs.Aria],
patches: [{
find: "onClick:this.handleMessageClick,",
replacement: {
match: /this(?=\.handleContextMenu\(\i,\i\))/,
replace: "$self"
}
}],
handleContextMenu(event: MouseEvent, message: Message) {
const channel = ChannelStore.getChannel(message.channel_id);
if (!channel) return;
event.stopPropagation();
ContextMenuApi.openContextMenu(event, contextMenuProps =>
<MessageMenu
message={message}
channel={channel}
onHeightUpdate={contextMenuProps.onHeightUpdate}
/>
);
}
});

View file

@ -1,6 +0,0 @@
# SearchReply
Adds a reply button to search results.
![the plugin in action](https://github.com/Vendicated/Vencord/assets/45497981/07e741d3-0f97-4e5c-82b0-80712ecf2cbb)

View file

@ -1,75 +0,0 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { ReplyIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByCodeLazy } from "@webpack";
import { ChannelStore, i18n, Menu, PermissionsBits, PermissionStore, SelectedChannelStore } from "@webpack/common";
import { Message } from "discord-types/general";
const replyToMessage = findByCodeLazy(".TEXTAREA_FOCUS)", "showMentionToggle:");
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, { message }: { message: Message; }) => {
// make sure the message is in the selected channel
if (SelectedChannelStore.getChannelId() !== message.channel_id) return;
const channel = ChannelStore.getChannel(message?.channel_id);
if (!channel) return;
if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
// dms and group chats
const dmGroup = findGroupChildrenByChildId("pin", children);
if (dmGroup && !dmGroup.some(child => child?.props?.id === "reply")) {
const pinIndex = dmGroup.findIndex(c => c?.props.id === "pin");
dmGroup.splice(pinIndex + 1, 0, (
<Menu.MenuItem
id="reply"
label={i18n.Messages.MESSAGE_ACTION_REPLY}
icon={ReplyIcon}
action={(e: React.MouseEvent) => replyToMessage(channel, message, e)}
/>
));
return;
}
// servers
const serverGroup = findGroupChildrenByChildId("mark-unread", children);
if (serverGroup && !serverGroup.some(child => child?.props?.id === "reply")) {
serverGroup.unshift((
<Menu.MenuItem
id="reply"
label={i18n.Messages.MESSAGE_ACTION_REPLY}
icon={ReplyIcon}
action={(e: React.MouseEvent) => replyToMessage(channel, message, e)}
/>
));
return;
}
};
export default definePlugin({
name: "SearchReply",
description: "Adds a reply button to search results",
authors: [Devs.Aria],
contextMenus: {
"message": messageContextMenuPatch
}
});

View file

@ -6,18 +6,18 @@
import "./styles.css";
import { ChannelStore } from "@webpack/common";
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { Message, User } from "discord-types/general";
import { Message } from "discord-types/general";
interface UsernameProps {
author: { nick: string; };
message: Message;
withMentionPrefix?: boolean;
isRepliedMessage: boolean;
userOverride?: User;
}
const settings = definePluginSettings({
@ -28,18 +28,27 @@ const settings = definePluginSettings({
{ label: "Username then nickname", value: "user-nick", default: true },
{ label: "Nickname then username", value: "nick-user" },
{ label: "Username only", value: "user" },
{ label: "Vanilla (Nickname prioritized)", value: "nick" },
],
},
displayNames: {
type: OptionType.BOOLEAN,
description: "Use display names in place of usernames",
default: false
},
inReplies: {
type: OptionType.BOOLEAN,
default: false,
description: "Also apply functionality to reply previews",
},
inDirectMessages: {
type: OptionType.BOOLEAN,
default: false,
description: "Also apply functionality to direct messages",
},
inDirectGroups: {
type: OptionType.BOOLEAN,
default: false,
description: "Also apply functionality to direct messages on groups",
},
});
export default definePlugin({
@ -57,28 +66,79 @@ export default definePlugin({
],
settings,
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix }: UsernameProps) => {
try {
const user = userOverride ?? message.author;
let { username } = user;
if (settings.store.displayNames)
username = (user as any).globalName || username;
// Discord by default will display the username unless the user has set an nickname
// The code will also do the same if certain settings are turned off
const { nick } = author;
const prefix = withMentionPrefix ? "@" : "";
// There is no way to get the nick from the message for some reason so this had to stay
const nickname: string = author.nick;
if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase())
return <>{prefix}{nick}</>;
const userObj = message.author;
const prefix: string = withMentionPrefix ? "@" : "";
const username: string = userObj.username;
const isRedundantDoubleUsername = (username.toLowerCase() === nickname.toLowerCase());
let display_name = nickname;
if (settings.store.mode === "user-nick")
return <>{prefix}{username} <span className="vc-smyn-suffix">{nick}</span></>;
switch (settings.store.mode) {
case "user-nick":
if (!isRedundantDoubleUsername) {
display_name = <>{prefix}{username} <span className="vc-smyn-suffix">{nickname}</span></>;
}
if (settings.store.mode === "nick-user")
return <>{prefix}{nick} <span className="vc-smyn-suffix">{username}</span></>;
break;
// the <span> makes the text gray
return <>{prefix}{username}</>;
} catch {
return <>{author?.nick}</>;
case "nick-user":
if (!isRedundantDoubleUsername) {
display_name = <>{prefix}{nickname} <span className="vc-smyn-suffix">{username}</span></>;
}
break;
case "user":
display_name = <>{prefix}{username}</>;
break;
case "vanilla":
display_name = <>{prefix}{nickname}</>;
break;
}
const current_channel = ChannelStore.getChannel(message.channel_id);
const isDM = (current_channel.guild_id === null);
if (isDM) {
const isGroupChat = (current_channel.recipients.length > 1);
const shouldDisplayDM = !isGroupChat && settings.store.inDirectMessages;
const shouldDisplayGroup = isGroupChat && settings.store.inDirectGroups;
if (shouldDisplayDM || shouldDisplayGroup) {
if (isRepliedMessage) {
if (settings.store.inReplies) return display_name;
return nickname;
}
return display_name;
}
return nickname;
}
// Servers
if (isRepliedMessage) {
if (settings.store.inReplies) return display_name;
return nickname;
}
// Unless any of the functions above changed it, it will be the nickname
return display_name;
} catch (errorMsg) {
console.log(`ShowMeYourName ERROR: ${errorMsg}`);
return <>{message?.author.username}</>;
}
}, { noop: true }),
});