Fix WhoReacted (#1769)
This commit is contained in:
parent
6db9721c06
commit
1f38a8eeab
2 changed files with 26 additions and 98 deletions
5
src/plugins/whoReacted/README.md
Normal file
5
src/plugins/whoReacted/README.md
Normal 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)
|
|
@ -24,14 +24,14 @@ import { LazyComponent, useForceUpdater } from "@utils/react";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findByCode, findByPropsLazy } from "@webpack";
|
import { findByCode, findByPropsLazy } from "@webpack";
|
||||||
import { ChannelStore, FluxDispatcher, React, RestAPI, Tooltip } from "@webpack/common";
|
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 UserSummaryItem = LazyComponent(() => findByCode("defaultRenderUser", "showDefaultAvatarsForNullUsers"));
|
||||||
const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
|
const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar");
|
||||||
|
|
||||||
const ReactionStore = findByPropsLazy("getReactions");
|
|
||||||
|
|
||||||
const queue = new Queue();
|
const queue = new Queue();
|
||||||
|
let reactions: Record<string, ReactionCacheEntry>;
|
||||||
|
|
||||||
function fetchReactions(msg: Message, emoji: ReactionEmoji, type: number) {
|
function fetchReactions(msg: Message, emoji: ReactionEmoji, type: number) {
|
||||||
const key = emoji.name + (emoji.id ? `:${emoji.id}` : "");
|
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) {
|
function getReactionsWithQueue(msg: Message, e: ReactionEmoji, type: number) {
|
||||||
const key = `${msg.id}:${e.name}:${e.id ?? ""}:${type}`;
|
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) {
|
if (!cache.fetched) {
|
||||||
queue.unshift(() =>
|
queue.unshift(() => fetchReactions(msg, e, type));
|
||||||
fetchReactions(msg, e, type)
|
|
||||||
);
|
|
||||||
cache.fetched = true;
|
cache.fetched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ function handleClickAvatar(event: React.MouseEvent<HTMLElement, MouseEvent>) {
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "WhoReacted",
|
name: "WhoReacted",
|
||||||
description: "Renders the Avatars of reactors",
|
description: "Renders the avatars of users who reacted to a message",
|
||||||
authors: [Devs.Ven, Devs.KannaDev],
|
authors: [Devs.Ven, Devs.KannaDev],
|
||||||
|
|
||||||
patches: [{
|
patches: [{
|
||||||
|
@ -101,6 +99,12 @@ export default definePlugin({
|
||||||
match: /(?<=(\i)=(\i)\.hideCount,)(.+?reactionCount.+?\}\))/,
|
match: /(?<=(\i)=(\i)\.hideCount,)(.+?reactionCount.+?\}\))/,
|
||||||
replace: (_, hideCount, props, rest) => `whoReactedProps=${props},${rest},${hideCount}?null:$self.renderUsers(whoReactedProps)`
|
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) {
|
renderUsers(props: RootObject) {
|
||||||
|
@ -150,106 +154,25 @@ export default definePlugin({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
set reactions(value: any) {
|
||||||
|
reactions = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface ReactionCacheEntry {
|
||||||
export interface GuildMemberAvatar { }
|
fetched: boolean;
|
||||||
|
users: Record<string, User>;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Emoji {
|
interface RootObject {
|
||||||
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 {
|
|
||||||
message: Message;
|
message: Message;
|
||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
isLurking: boolean;
|
isLurking: boolean;
|
||||||
isPendingMember: boolean;
|
isPendingMember: boolean;
|
||||||
useChatFontScaling: boolean;
|
useChatFontScaling: boolean;
|
||||||
emoji: Emoji;
|
emoji: CustomEmoji;
|
||||||
count: number;
|
count: number;
|
||||||
burst_user_ids: any[];
|
burst_user_ids: any[];
|
||||||
burst_count: number;
|
burst_count: number;
|
||||||
|
|
Loading…
Reference in a new issue