fullVcPfp: add server profile avatar setting (#859)
This commit is contained in:
parent
9db2d746e8
commit
19dc4ab68d
1 changed files with 36 additions and 4 deletions
|
|
@ -4,17 +4,27 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { disableStyle, enableStyle } from "@api/Styles";
|
||||
import { EquicordDevs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { ChannelRTCStore, IconUtils, UserStore, VoiceStateStore } from "@webpack/common";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { ChannelRTCStore, ChannelStore, GuildMemberStore, IconUtils, UserStore, VoiceStateStore } from "@webpack/common";
|
||||
|
||||
import style from "./style.css?managed";
|
||||
|
||||
const settings = definePluginSettings({
|
||||
useServerProfileAvatars: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Use server profile avatars in guild voice channels when available.",
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "FullVCPFP",
|
||||
description: "Makes avatars take up the entire vc tile",
|
||||
authors: [EquicordDevs.mochienya],
|
||||
settings,
|
||||
patches: [
|
||||
{
|
||||
find: "\"data-selenium-video-tile\":",
|
||||
|
|
@ -29,15 +39,37 @@ export default definePlugin({
|
|||
if (!className.includes("tile") || !participantUserId) return;
|
||||
|
||||
const user = UserStore.getUser(participantUserId);
|
||||
const channelId = VoiceStateStore.getVoiceStateForUser(participantUserId)?.channelId!;
|
||||
if (!user) return;
|
||||
|
||||
const channelId = VoiceStateStore.getVoiceStateForUser(participantUserId)?.channelId;
|
||||
if (!channelId) return;
|
||||
|
||||
const isSpeaking = ChannelRTCStore.getSpeakingParticipants(channelId).some(p => p.user.id === participantUserId && p.speaking);
|
||||
const avatarUrl = IconUtils.getUserAvatarURL(user, isSpeaking, 1024);
|
||||
const avatarUrl = settings.store.useServerProfileAvatars
|
||||
? this.getServerAvatarUrl(participantUserId, channelId, isSpeaking) ?? IconUtils.getUserAvatarURL(user, isSpeaking, 1024)
|
||||
: IconUtils.getUserAvatarURL(user, isSpeaking, 1024);
|
||||
|
||||
return {
|
||||
"--full-res-avatar": `url(${avatarUrl})`
|
||||
};
|
||||
},
|
||||
|
||||
getServerAvatarUrl(userId: string, channelId: string, canAnimate: boolean) {
|
||||
const guildId = ChannelStore.getChannel(channelId)?.guild_id;
|
||||
if (!guildId) return;
|
||||
|
||||
const guildAvatar = GuildMemberStore.getMember(guildId, userId)?.avatar;
|
||||
if (!guildAvatar) return;
|
||||
|
||||
return IconUtils.getGuildMemberAvatarURLSimple({
|
||||
userId,
|
||||
guildId,
|
||||
avatar: guildAvatar,
|
||||
canAnimate,
|
||||
size: 1024
|
||||
});
|
||||
},
|
||||
|
||||
start() {
|
||||
enableStyle(style);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue