Fix WhoReacted (#1769)

This commit is contained in:
TheKodeToad 2023-10-03 01:26:38 +01:00 committed by GitHub
parent 6db9721c06
commit 1f38a8eeab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 98 deletions

View file

@ -0,0 +1,5 @@
# WhoReacted
Next to each reaction, display each user's avatar. Each avatar can be clicked and will open the profile.
![](https://github.com/Vendicated/Vencord/assets/57493648/97fec9e8-396f-4f5e-916e-1ec21445113d)

View file

@ -24,14 +24,14 @@ import { LazyComponent, useForceUpdater } from "@utils/react";
import definePlugin from "@utils/types";
import { findByCode, findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher, React, RestAPI, Tooltip } from "@webpack/common";
import { ReactionEmoji, User } from "discord-types/general";
import { CustomEmoji } from "@webpack/types";
import { Message, ReactionEmoji, User } from "discord-types/general";
const UserSummaryItem = LazyComponent(() => findByCode("defaultRenderUser", "showDefaultAvatarsForNullUsers"));
const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
const ReactionStore = findByPropsLazy("getReactions");
const queue = new Queue();
let reactions: Record<string, ReactionCacheEntry>;
function fetchReactions(msg: Message, emoji: ReactionEmoji, type: number) {
const key = emoji.name + (emoji.id ? `:${emoji.id}` : "");
@ -57,11 +57,9 @@ function fetchReactions(msg: Message, emoji: ReactionEmoji, type: number) {
function getReactionsWithQueue(msg: Message, e: ReactionEmoji, type: number) {
const key = `${msg.id}:${e.name}:${e.id ?? ""}:${type}`;
const cache = ReactionStore.__getLocalVars().reactions[key] ??= { fetched: false, users: {} };
const cache = reactions[key] ??= { fetched: false, users: {} };
if (!cache.fetched) {
queue.unshift(() =>
fetchReactions(msg, e, type)
);
queue.unshift(() => fetchReactions(msg, e, type));
cache.fetched = true;
}
@ -92,7 +90,7 @@ function handleClickAvatar(event: React.MouseEvent<HTMLElement, MouseEvent>) {
export default definePlugin({
name: "WhoReacted",
description: "Renders the Avatars of reactors",
description: "Renders the avatars of users who reacted to a message",
authors: [Devs.Ven, Devs.KannaDev],
patches: [{
@ -101,6 +99,12 @@ export default definePlugin({
match: /(?<=(\i)=(\i)\.hideCount,)(.+?reactionCount.+?\}\))/,
replace: (_, hideCount, props, rest) => `whoReactedProps=${props},${rest},${hideCount}?null:$self.renderUsers(whoReactedProps)`
}
}, {
find: '.displayName="MessageReactionsStore";',
replacement: {
match: /(?<=CONNECTION_OPEN:function\(\){)(\i)={}/,
replace: "$&;$self.reactions=$1"
}
}],
renderUsers(props: RootObject) {
@ -150,106 +154,25 @@ export default definePlugin({
</div>
</div>
);
},
set reactions(value: any) {
reactions = value;
}
});
export interface GuildMemberAvatar { }
export interface Author {
id: string;
username: string;
discriminator: string;
avatar: string;
avatarDecoration?: any;
email: string;
verified: boolean;
bot: boolean;
system: boolean;
mfaEnabled: boolean;
mobile: boolean;
desktop: boolean;
premiumType: number;
flags: number;
publicFlags: number;
purchasedFlags: number;
premiumUsageFlags: number;
phone: string;
nsfwAllowed: boolean;
guildMemberAvatars: GuildMemberAvatar;
interface ReactionCacheEntry {
fetched: boolean;
users: Record<string, User>;
}
export interface Emoji {
id: string;
name: string;
}
export interface Reaction {
emoji: Emoji;
count: number;
burst_user_ids: any[];
burst_count: number;
burst_colors: any[];
burst_me: boolean;
me: boolean;
}
export interface Message {
id: string;
type: number;
channel_id: string;
author: Author;
content: string;
deleted: boolean;
editHistory: any[];
attachments: any[];
embeds: any[];
mentions: any[];
mentionRoles: any[];
mentionChannels: any[];
mentioned: boolean;
pinned: boolean;
mentionEveryone: boolean;
tts: boolean;
codedLinks: any[];
giftCodes: any[];
timestamp: string;
editedTimestamp?: any;
state: string;
nonce?: any;
blocked: boolean;
call?: any;
bot: boolean;
webhookId?: any;
reactions: Reaction[];
applicationId?: any;
application?: any;
activity?: any;
messageReference?: any;
flags: number;
isSearchHit: boolean;
stickers: any[];
stickerItems: any[];
components: any[];
loggingName?: any;
interaction?: any;
interactionData?: any;
interactionError?: any;
}
export interface Emoji {
id: string;
name: string;
animated: boolean;
}
export interface RootObject {
interface RootObject {
message: Message;
readOnly: boolean;
isLurking: boolean;
isPendingMember: boolean;
useChatFontScaling: boolean;
emoji: Emoji;
emoji: CustomEmoji;
count: number;
burst_user_ids: any[];
burst_count: number;