Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserVoiceShow: Add option to show username #3116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/plugins/userVoiceShow/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc";
import { filters, findByCodeLazy, findByPropsLazy, findComponentByCodeLazy, findStoreLazy, mapMangledModuleLazy } from "@webpack";
import { ChannelRouter, ChannelStore, GuildStore, IconUtils, match, P, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common";
import { ChannelRouter, ChannelStore, GuildStore, IconUtils, match, P, PermissionsBits, PermissionStore, React, RelationshipStore, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores, GuildMemberStore } from "@webpack/common";
import { Channel } from "discord-types/general";
import { settings } from "./index";

const cl = classNameFactory("vc-uvs-");

Expand Down Expand Up @@ -115,15 +116,34 @@ function VoiceChannelTooltip({ channel, isLocked }: VoiceChannelTooltipProps) {
{channelIcon}
<Text variant="text-sm/semibold">{channelName}</Text>
</div>
<div className={cl("vc-members")}>
<div className={cl("vc-members-container")}>
{isLocked ? <LockedSpeakerIcon size={18} /> : <SpeakerIcon size={18} />}
<UserSummaryItem
{!settings.store.showUserNames && <UserSummaryItem
users={users}
renderIcon={false}
max={13}
size={18}
/>
</div>
/>}
{settings.store.showUserNames && (
<div className={cl("vc-members")}>
{users.map(user => (
<div key={user.id} className={cl("vc-member")}>
<Avatar src={user.getAvatarURL()} size="SIZE_32" />
<Text variant="text-sm/semibold">
{(() => {
const name = (guild && GuildMemberStore.getNick(guild.id, user.id))
|| (!guild && RelationshipStore.getNickname(user.id))
|| (user as any).globalName
|| user.username;
const maxLength = settings.store.maxNameLength;
return name.length > maxLength ? name.slice(0, maxLength) + "..." : name;
})()}
</Text>
</div>
))}
</div>
)}
</div >
</>
);
}
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/userVoiceShow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import definePlugin, { OptionType } from "@utils/types";

import { VoiceChannelIndicator } from "./components";

const settings = definePluginSettings({
export const settings = definePluginSettings({
showInUserProfileModal: {
type: OptionType.BOOLEAN,
description: "Show a user's Voice Channel indicator in their profile next to the name",
Expand All @@ -44,13 +44,23 @@ const settings = definePluginSettings({
description: "Show a user's Voice Channel indicator in messages",
default: true,
restartNeeded: true
}
},
showUserNames: {
type: OptionType.BOOLEAN,
description: "Show user's name in the Voice Channel indicator",
default: false,
},
maxNameLength: {
type: OptionType.NUMBER,
description: "Set the maximum length for the user's name in the Voice Channel indicator",
default: 10,
},
});

export default definePlugin({
name: "UserVoiceShow",
description: "Shows an indicator when a user is in a Voice Channel",
authors: [Devs.Nuckyz, Devs.LordElias],
authors: [Devs.Nuckyz, Devs.LordElias, Devs.ScarZ],
dependencies: ["MemberListDecoratorsAPI", "MessageDecorationsAPI"],
settings,

Expand Down
22 changes: 20 additions & 2 deletions src/plugins/userVoiceShow/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

.vc-uvs-tooltip-container {
max-width: 300px;
max-width: 350px;
}

.vc-uvs-tooltip-content {
Expand All @@ -44,7 +44,25 @@
align-self: center;
}

.vc-uvs-vc-members {
.vc-uvs-vc-members-container {
display: flex;
gap: 6px;
}

.vc-uvs-vc-members-container>.vc-uvs-speaker {
display: flex;
padding-top: 6px;
align-items: flex-start
}

.vc-uvs-vc-members {
display: flex;
flex-wrap: wrap;
gap: 8px;
}

.vc-uvs-vc-member {
display: flex;
align-items: center;
gap: 4px;
}
4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "jamesbt365",
id: 158567567487795200n,
},
ScarZ: {
name: "ScarZ",
id: 0n
},
} satisfies Record<string, Dev>);

// iife so #__PURE__ works correctly
Expand Down