mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-19 22:20:34 +00:00
Compare commits
12 commits
457f882385
...
be30f0eb6e
Author | SHA1 | Date | |
---|---|---|---|
|
be30f0eb6e | ||
|
a015cf96f6 | ||
|
c7e5295da0 | ||
|
0a51a865d3 | ||
|
560fb982e6 | ||
|
f4572d0377 | ||
|
3a7499644e | ||
|
1a2033e137 | ||
|
1bdde745e2 | ||
|
b333deb731 | ||
|
e0bb9bf77d | ||
|
c73c3fa636 |
11 changed files with 466 additions and 110 deletions
42
src/plugins/editUsers/data.ts
Normal file
42
src/plugins/editUsers/data.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
|
||||
export const enum OverrideFlags {
|
||||
None = 0,
|
||||
PreferServerNicks = 1 << 0,
|
||||
DisableNicks = 1 << 1,
|
||||
KeepServerAvatar = 1 << 2,
|
||||
DisableServerAvatars = 1 << 3,
|
||||
KeepServerBanner = 1 << 4,
|
||||
DisableServerBanners = 1 << 5,
|
||||
}
|
||||
|
||||
export interface UserOverride {
|
||||
username: string;
|
||||
avatarUrl: string;
|
||||
bannerUrl: string;
|
||||
pronouns: string;
|
||||
flags: OverrideFlags;
|
||||
}
|
||||
|
||||
export const emptyOverride: UserOverride = Object.freeze({
|
||||
username: "",
|
||||
avatarUrl: "",
|
||||
bannerUrl: "",
|
||||
pronouns: "",
|
||||
flags: OverrideFlags.None,
|
||||
});
|
||||
|
||||
export const settings = definePluginSettings({})
|
||||
.withPrivateSettings<{
|
||||
users?: Record<string, UserOverride>;
|
||||
}>();
|
||||
|
||||
export const getUserOverride = (userId: string) => settings.store.users?.[userId] ?? emptyOverride;
|
||||
|
||||
export const hasFlag = (field: OverrideFlags, flag: OverrideFlags) => (field & flag) === flag;
|
125
src/plugins/editUsers/index.tsx
Normal file
125
src/plugins/editUsers/index.tsx
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import "./styles.css";
|
||||
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { Menu } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
|
||||
import { getUserOverride, hasFlag, OverrideFlags, settings } from "./data";
|
||||
import { openUserEditModal } from "./modal";
|
||||
|
||||
export default definePlugin({
|
||||
name: "EditUsers",
|
||||
description: "Edit users",
|
||||
authors: [Devs.Ven],
|
||||
|
||||
settings,
|
||||
|
||||
contextMenus: {
|
||||
"user-context"(children, { user }: { user?: User; }) {
|
||||
if (!user) return;
|
||||
|
||||
children.push(
|
||||
<Menu.MenuItem
|
||||
id="vc-edit-user"
|
||||
label="Edit User"
|
||||
action={() => openUserEditModal(user)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: ",getUserTag:",
|
||||
replacement: {
|
||||
match: /if\(\i\((\i)\.global_name\)\)return(?=.{0,100}return"\?\?\?")/,
|
||||
replace: "const vcEuName=$self.getUsername($1);if(vcEuName)return vcEuName;$&"
|
||||
}
|
||||
},
|
||||
{
|
||||
find: "=this.guildMemberAvatars[",
|
||||
replacement: [
|
||||
{
|
||||
match: /&&null!=this\.guildMemberAvatars\[\i\]/,
|
||||
replace: "$& && !$self.shouldIgnoreGuildAvatar(this)"
|
||||
},
|
||||
{
|
||||
match: /(?<=null!=(\i))\?(\i\.\i\.getGuildMemberAvatarURLSimple.+?):(?=\i\.\i\.getUserAvatarURL\(this)/,
|
||||
replace: "&& this.hasAvatarForGuild?.($1) ? $2 : $self.getAvatarUrl(this)||"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
find: "this.isUsingGuildMemberBanner()",
|
||||
replacement: [
|
||||
{
|
||||
match: /:\i\.banner\)!=null/,
|
||||
replace: "$& && !$self.shouldIgnoreGuildBanner(this.userId)"
|
||||
},
|
||||
{
|
||||
match: /(?<=:).{0,10}\(\{id:this\.userId,banner/,
|
||||
replace: "$self.getBannerUrl(this.userId)||$&"
|
||||
},
|
||||
{
|
||||
match: /isUsingGuildMemberPronouns\(\)\{/,
|
||||
replace:
|
||||
"set pronouns(v){this._vcPronouns=v}" +
|
||||
"get pronouns(){return $self.getPronouns(this.userId)||this._vcPronouns}" +
|
||||
"isUsingGuildMemberPronouns(){"
|
||||
},
|
||||
{
|
||||
match: /\i\(this,"pronouns",void 0\),/,
|
||||
replace: ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
find: '"GuildMemberStore"',
|
||||
replacement: {
|
||||
match: /getNick\(\i,(\i)\)\{/,
|
||||
replace: "$& if ($self.shouldIgnoreNick($1)) return null;"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
getUsername: (user: User) => getUserOverride(user.id).username,
|
||||
getAvatarUrl: (user: User) => getUserOverride(user.id).avatarUrl,
|
||||
getBannerUrl: (userId: string) => getUserOverride(userId).bannerUrl,
|
||||
getPronouns: (userId: string) => getUserOverride(userId).pronouns,
|
||||
|
||||
shouldIgnoreGuildAvatar(user: User) {
|
||||
const { avatarUrl, flags } = getUserOverride(user.id);
|
||||
|
||||
if (avatarUrl && !hasFlag(flags, OverrideFlags.KeepServerAvatar))
|
||||
return true;
|
||||
|
||||
return hasFlag(flags, OverrideFlags.DisableServerAvatars);
|
||||
},
|
||||
|
||||
shouldIgnoreGuildBanner(userId: string) {
|
||||
const { bannerUrl, flags } = getUserOverride(userId);
|
||||
|
||||
if (bannerUrl && !hasFlag(flags, OverrideFlags.KeepServerBanner))
|
||||
return true;
|
||||
|
||||
return hasFlag(flags, OverrideFlags.DisableServerBanners);
|
||||
},
|
||||
|
||||
shouldIgnoreNick(userId?: string) {
|
||||
if (!userId) return false;
|
||||
|
||||
const { username, flags } = getUserOverride(userId);
|
||||
|
||||
if (username && !hasFlag(flags, OverrideFlags.PreferServerNicks))
|
||||
return true;
|
||||
|
||||
return hasFlag(flags, OverrideFlags.DisableNicks);
|
||||
}
|
||||
});
|
170
src/plugins/editUsers/modal.tsx
Normal file
170
src/plugins/editUsers/modal.tsx
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import { Flex } from "@components/Flex";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||
import { Button, DisplayProfileUtils, showToast, Switch, TabBar, Text, TextInput, Toasts, UsernameUtils, useState } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
|
||||
import { emptyOverride, hasFlag, OverrideFlags, settings, UserOverride } from "./data";
|
||||
|
||||
const cl = classNameFactory("vc-editUsers-");
|
||||
|
||||
interface OverrideProps {
|
||||
override: UserOverride;
|
||||
setOverride: Dispatch<SetStateAction<UserOverride>>;
|
||||
}
|
||||
|
||||
interface SettingsRowProps extends OverrideProps {
|
||||
overrideKey: keyof Omit<UserOverride, "flags">;
|
||||
name: string;
|
||||
flagDisable: OverrideFlags;
|
||||
flagPrefer: OverrideFlags;
|
||||
placeholder: string;
|
||||
}
|
||||
|
||||
function SettingsRow(props: SettingsRowProps) {
|
||||
const { name, override, setOverride, overrideKey, placeholder, flagDisable, flagPrefer } = props;
|
||||
const namePlural = name + "s";
|
||||
const { flags } = override;
|
||||
|
||||
const toggleFlag = (on: boolean, flag: OverrideFlags) =>
|
||||
on
|
||||
? flags | flag
|
||||
: flags & ~flag;
|
||||
|
||||
return (
|
||||
<>
|
||||
<TextInput
|
||||
className={Margins.bottom16}
|
||||
value={override[overrideKey]}
|
||||
onChange={v => setOverride(o => ({ ...o, [overrideKey]: v }))}
|
||||
placeholder={placeholder}
|
||||
autoFocus
|
||||
/>
|
||||
<Switch
|
||||
value={hasFlag(flags, flagDisable)}
|
||||
onChange={v => setOverride(o => ({ ...o, flags: toggleFlag(v, flagDisable) }))}
|
||||
note={`Will use the user's global ${name} (or your EditUser configured ${name}) over server specific ${namePlural}`}
|
||||
>
|
||||
Disable server specific {namePlural}
|
||||
</Switch>
|
||||
<Switch
|
||||
value={hasFlag(flags, flagPrefer)}
|
||||
onChange={v => setOverride(o => ({ ...o, flags: toggleFlag(v, flagPrefer) }))}
|
||||
note={`Will use server specific ${namePlural} over the EditUser configured ${name}`}
|
||||
hideBorder
|
||||
>
|
||||
Prefer server specific {namePlural}
|
||||
</Switch>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const Tabs = {
|
||||
username: {
|
||||
name: "Username",
|
||||
flagDisable: OverrideFlags.DisableNicks,
|
||||
flagPrefer: OverrideFlags.PreferServerNicks,
|
||||
placeholder: (user: User) => UsernameUtils.getName(user),
|
||||
},
|
||||
avatarUrl: {
|
||||
name: "Avatar",
|
||||
flagDisable: OverrideFlags.DisableServerAvatars,
|
||||
flagPrefer: OverrideFlags.KeepServerAvatar,
|
||||
placeholder: (user: User) => user.getAvatarURL(),
|
||||
},
|
||||
bannerUrl: {
|
||||
name: "Banner",
|
||||
flagDisable: OverrideFlags.DisableServerBanners,
|
||||
flagPrefer: OverrideFlags.KeepServerBanner,
|
||||
placeholder: (user: User) => DisplayProfileUtils.getDisplayProfile(user.id)?.getBannerURL({ canAnimate: true, size: 64 }) ?? "",
|
||||
},
|
||||
} as const;
|
||||
const TabKeys = Object.keys(Tabs) as (keyof typeof Tabs)[];
|
||||
|
||||
function EditTabs({ user, override, setOverride }: { user: User; } & OverrideProps) {
|
||||
const [currentTabName, setCurrentTabName] = useState(TabKeys[0]);
|
||||
|
||||
const currentTab = Tabs[currentTabName];
|
||||
|
||||
return (
|
||||
<>
|
||||
<TabBar
|
||||
type="top"
|
||||
look="brand"
|
||||
className={cl("tabBar")}
|
||||
selectedItem={currentTabName}
|
||||
onItemSelect={setCurrentTabName}
|
||||
>
|
||||
{TabKeys.map(key => (
|
||||
<TabBar.Item
|
||||
id={key}
|
||||
key={key}
|
||||
className={cl("tab")}
|
||||
>
|
||||
{Tabs[key].name}
|
||||
</TabBar.Item>
|
||||
))}
|
||||
</TabBar>
|
||||
|
||||
<SettingsRow
|
||||
{...currentTab}
|
||||
override={override}
|
||||
overrideKey={currentTabName}
|
||||
setOverride={setOverride}
|
||||
placeholder={currentTab.placeholder(user)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function EditModal({ user, modalProps }: { user: User; modalProps: ModalProps; }) {
|
||||
const [override, setOverride] = useState(() => ({ ...settings.store.users?.[user.id] ?? emptyOverride }));
|
||||
|
||||
return (
|
||||
<ModalRoot {...modalProps} size={ModalSize.MEDIUM}>
|
||||
<ModalHeader>
|
||||
<Text variant="heading-lg/semibold" style={{ flexGrow: 1 }}>Edit User {user.username}</Text>
|
||||
<ModalCloseButton onClick={modalProps.onClose} />
|
||||
</ModalHeader>
|
||||
|
||||
<ModalContent>
|
||||
<div className={cl("modal")}>
|
||||
<EditTabs user={user} override={override} setOverride={setOverride} />
|
||||
</div>
|
||||
</ModalContent>
|
||||
|
||||
<ModalFooter>
|
||||
<Flex>
|
||||
<Button
|
||||
color={Button.Colors.RED}
|
||||
onClick={() => setOverride({ ...emptyOverride })}
|
||||
>
|
||||
Reset All
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
const s = settings.store.users ??= {};
|
||||
s[user.id] = override;
|
||||
modalProps.onClose();
|
||||
showToast("Saved! Switch chats for changes to apply everywhere", Toasts.Type.SUCCESS, { position: Toasts.Position.BOTTOM });
|
||||
}}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Flex>
|
||||
</ModalFooter>
|
||||
</ModalRoot>
|
||||
);
|
||||
}
|
||||
|
||||
export function openUserEditModal(user: User) {
|
||||
openModal(props => <EditModal user={user} modalProps={props} />);
|
||||
}
|
14
src/plugins/editUsers/styles.css
Normal file
14
src/plugins/editUsers/styles.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
.vc-editUsers-modal {
|
||||
padding: 1em 0;
|
||||
}
|
||||
|
||||
.vc-editUsers-tabBar {
|
||||
gap: 1em;
|
||||
margin-bottom: 16px;
|
||||
border-bottom: 2px solid var(--background-modifier-accent);
|
||||
}
|
||||
|
||||
.vc-editUsers-tab {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
5
src/plugins/fullSearchContext/README.md
Normal file
5
src/plugins/fullSearchContext/README.md
Normal 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)
|
82
src/plugins/fullSearchContext/index.tsx
Normal file
82
src/plugins/fullSearchContext/index.tsx
Normal 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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
});
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
}
|
||||
});
|
|
@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles";
|
|||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { classes } from "@utils/misc";
|
||||
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
const cl = classNameFactory("vc-uvs-");
|
||||
|
@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan
|
|||
const VoiceStateStore = findStoreLazy("VoiceStateStore");
|
||||
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
|
||||
|
||||
interface IconProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
interface IconProps extends React.ComponentPropsWithoutRef<"div"> {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
|
@ -71,23 +71,18 @@ interface VoiceChannelTooltipProps {
|
|||
|
||||
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
||||
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
|
||||
|
||||
const users = useMemo(
|
||||
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
|
||||
[voiceStates]
|
||||
);
|
||||
|
||||
const guild = useMemo(
|
||||
() => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()),
|
||||
[channel]
|
||||
);
|
||||
|
||||
const guildIcon = useMemo(() => {
|
||||
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
|
||||
id: guild.id,
|
||||
icon: guild.icon,
|
||||
size: 30
|
||||
});
|
||||
}, [guild]);
|
||||
const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId());
|
||||
const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
|
||||
id: guild.id,
|
||||
icon: guild.icon,
|
||||
size: 30
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -103,7 +98,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
|||
<UserSummaryItem
|
||||
users={users}
|
||||
renderIcon={false}
|
||||
max={7}
|
||||
max={13}
|
||||
size={18}
|
||||
/>
|
||||
</div>
|
||||
|
@ -119,11 +114,14 @@ const clickTimers = {} as Record<string, any>;
|
|||
|
||||
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
|
||||
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
|
||||
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
|
||||
|
||||
const onClick = useCallback((e: React.MouseEvent) => {
|
||||
const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId);
|
||||
if (channel == null) return null;
|
||||
|
||||
function onClick(e: React.MouseEvent) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (channel == null || channelId == null) return;
|
||||
|
||||
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
|
||||
|
@ -147,18 +145,15 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
|
|||
delete clickTimers[channelId];
|
||||
}, 250);
|
||||
}
|
||||
}, [channelId]);
|
||||
}
|
||||
|
||||
const isLocked = useMemo(() => {
|
||||
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
|
||||
}, [channelId]);
|
||||
|
||||
if (channel == null) return null;
|
||||
const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
text={<VoiceChannelTooltip channel={channel} />}
|
||||
tooltipClassName={cl("tooltip-container")}
|
||||
tooltipContentClassName={cl("tooltip-content")}
|
||||
>
|
||||
{props =>
|
||||
isLocked ?
|
||||
|
|
|
@ -32,7 +32,7 @@ const settings = definePluginSettings({
|
|||
default: true,
|
||||
restartNeeded: true
|
||||
},
|
||||
showInVoiceMemberList: {
|
||||
showInMemberList: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Show a user's Voice Channel indicator in the member and DMs list",
|
||||
default: true,
|
||||
|
@ -82,12 +82,12 @@ export default definePlugin({
|
|||
match: /\.subtext,children:.+?}\)\]}\)(?=])/,
|
||||
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
|
||||
},
|
||||
predicate: () => settings.store.showInVoiceMemberList
|
||||
predicate: () => settings.store.showInMemberList
|
||||
}
|
||||
],
|
||||
|
||||
start() {
|
||||
if (settings.store.showInVoiceMemberList) {
|
||||
if (settings.store.showInMemberList) {
|
||||
addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -15,7 +15,13 @@
|
|||
}
|
||||
|
||||
.vc-uvs-tooltip-container {
|
||||
max-width: 200px;
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.vc-uvs-tooltip-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.vc-uvs-guild-name {
|
||||
|
@ -31,7 +37,5 @@
|
|||
|
||||
.vc-uvs-vc-members {
|
||||
display: flex;
|
||||
margin: 8px 0;
|
||||
flex-direction: row;
|
||||
gap: 6px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue