From 8d97863db6d1c6e628a057e3cb66ea1634d0a3f9 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 17 Jun 2025 21:58:12 +0200 Subject: [PATCH 1/4] Fix ImplicitRelationships, RelationshipNotifier & ServerInfo --- src/plugins/implicitRelationships/index.ts | 18 ++++++++---------- src/plugins/noBlockedMessages/index.ts | 5 +---- src/plugins/quickReply/index.ts | 4 ---- src/plugins/relationshipNotifier/utils.ts | 2 +- src/plugins/serverInfo/GuildInfoModal.tsx | 4 ++-- src/webpack/common/stores.ts | 6 +----- src/webpack/common/types/stores.d.ts | 17 +++++++++++++++++ 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index 13c12ed9..edaf4be9 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -23,7 +23,7 @@ import { findStoreLazy } from "@webpack"; import { Constants, FluxDispatcher, GuildStore, RelationshipStore, RestAPI, SnowflakeUtils, UserStore } from "@webpack/common"; import { Settings } from "Vencord"; -const UserAffinitiesStore = findStoreLazy("UserAffinitiesStore"); +const UserAffinitiesStore = findStoreLazy("UserAffinitiesV2Store"); export default definePlugin({ name: "ImplicitRelationships", @@ -117,7 +117,7 @@ export default definePlugin({ wrapSort(comparator: Function, row: any) { return row.type === 5 - ? -(UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0) + ? (UserAffinitiesStore.getUserAffinity(row.user.id)?.communicationRank ?? 0) : comparator(row); }, @@ -139,17 +139,15 @@ export default definePlugin({ // 1. Have an affinity for // 2. Do not have a relationship with await this.refreshUserAffinities(); - const userAffinities: Set = UserAffinitiesStore.getUserAffinitiesUserIds(); - const relationships = RelationshipStore.getRelationships(); - const nonFriendAffinities = Array.from(userAffinities).filter( - id => !RelationshipStore.getRelationshipType(id) - ); - nonFriendAffinities.forEach(id => { - relationships[id] = 5; + const userAffinities: Record[] = UserAffinitiesStore.getUserAffinities(); + const relationships = RelationshipStore.getMutableRelationships(); + const nonFriendAffinities = userAffinities.filter(a => !RelationshipStore.getRelationshipType(a.otherUserId)); + nonFriendAffinities.forEach(a => { + relationships[a.otherUserId] = 5; }); RelationshipStore.emitChange(); - const toRequest = nonFriendAffinities.filter(id => !UserStore.getUser(id)); + const toRequest = nonFriendAffinities.filter(a => !UserStore.getUser(a.otherUserId)); const allGuildIds = Object.keys(GuildStore.getGuilds()); const sentNonce = SnowflakeUtils.fromTimestamp(Date.now()); let count = allGuildIds.length * Math.ceil(toRequest.length / 100); diff --git a/src/plugins/noBlockedMessages/index.ts b/src/plugins/noBlockedMessages/index.ts index efa4ed08..973e3796 100644 --- a/src/plugins/noBlockedMessages/index.ts +++ b/src/plugins/noBlockedMessages/index.ts @@ -21,12 +21,9 @@ import { Devs } from "@utils/constants"; import { runtimeHashMessageKey } from "@utils/intlHash"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { i18n } from "@webpack/common"; +import { i18n, RelationshipStore } from "@webpack/common"; import { Message } from "discord-types/general"; -const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked"); - interface MessageDeleteProps { // Internal intl message for BLOCKED_MESSAGE_COUNT collapsedReason: () => any; diff --git a/src/plugins/quickReply/index.ts b/src/plugins/quickReply/index.ts index 5a6b45f9..dcd2038c 100644 --- a/src/plugins/quickReply/index.ts +++ b/src/plugins/quickReply/index.ts @@ -19,19 +19,15 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; import { ChannelStore, ComponentDispatch, FluxDispatcher as Dispatcher, MessageActions, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common"; import { Message } from "discord-types/general"; import NoBlockedMessagesPlugin from "plugins/noBlockedMessages"; import NoReplyMentionPlugin from "plugins/noReplyMention"; -const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked"); - const isMac = navigator.platform.includes("Mac"); // bruh let currentlyReplyingId: string | null = null; let currentlyEditingId: string | null = null; - const enum MentionOptions { DISABLED, ENABLED, diff --git a/src/plugins/relationshipNotifier/utils.ts b/src/plugins/relationshipNotifier/utils.ts index 84e812a7..75cf2d3a 100644 --- a/src/plugins/relationshipNotifier/utils.ts +++ b/src/plugins/relationshipNotifier/utils.ts @@ -172,7 +172,7 @@ export async function syncFriends() { friends.friends = []; friends.requests = []; - const relationShips = RelationshipStore.getRelationships(); + const relationShips = RelationshipStore.getMutableRelationships(); for (const id in relationShips) { switch (relationShips[id]) { case RelationshipType.FRIEND: diff --git a/src/plugins/serverInfo/GuildInfoModal.tsx b/src/plugins/serverInfo/GuildInfoModal.tsx index 60401b71..8300380d 100644 --- a/src/plugins/serverInfo/GuildInfoModal.tsx +++ b/src/plugins/serverInfo/GuildInfoModal.tsx @@ -220,12 +220,12 @@ function FriendsTab({ guild, setCount }: RelationshipProps) { } function BlockedUsersTab({ guild, setCount }: RelationshipProps) { - const blockedIds = Object.keys(RelationshipStore.getRelationships()).filter(id => RelationshipStore.isBlocked(id)); + const blockedIds = Object.keys(RelationshipStore.getMutableRelationships()).filter(id => RelationshipStore.isBlocked(id)); return UserList("blocked", guild, blockedIds, setCount); } function IgnoredUserTab({ guild, setCount }: RelationshipProps) { - const ignoredIds = Object.keys(RelationshipStore.getRelationships()).filter(id => RelationshipStore.isIgnored(id)); + const ignoredIds = Object.keys(RelationshipStore.getMutableRelationships()).filter(id => RelationshipStore.isIgnored(id)); return UserList("ignored", guild, ignoredIds, setCount); } diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index 1dcda187..e0c00f6d 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -46,11 +46,7 @@ export let SelectedChannelStore: Stores.SelectedChannelStore & t.FluxStore; export let SelectedGuildStore: t.FluxStore & Record; export let ChannelStore: Stores.ChannelStore & t.FluxStore; export let GuildMemberStore: Stores.GuildMemberStore & t.FluxStore; -export let RelationshipStore: Stores.RelationshipStore & t.FluxStore & { - /** Get the date (as a string) that the relationship was created */ - getSince(userId: string): string; - isIgnored(userId: string): boolean; -}; +export let RelationshipStore: t.RelationshipStore; export let EmojiStore: t.EmojiStore; export let ThemeStore: t.ThemeStore; diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts index 67148303..497de739 100644 --- a/src/webpack/common/types/stores.d.ts +++ b/src/webpack/common/types/stores.d.ts @@ -233,3 +233,20 @@ export type useStateFromStores = ( dependencies?: any, isEqual?: (old: T, newer: T) => boolean ) => T; + +export class RelationshipStore extends FluxStore { + getFriendIDs(): string[]; + /** Related to friend nicknames experiment. */ + getNickname(userId: string): string; + getPendingCount(): number; + getRelationshipCount(): number; + /** @returns Enum value from constants.RelationshipTypes */ + getRelationshipType(userId: string): number; + /** @returns Format: [userId: Enum value from constants.RelationshipTypes] */ + getMutableRelationships(): Record; + isBlocked(userId: string): boolean; + isFriend(userId: string): boolean; + + getSince(userId: string): string; + isIgnored(userId: string): boolean; +} From a6c1f97d12311a7379ffa39fb07db030a20a226d Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 17 Jun 2025 22:03:13 +0200 Subject: [PATCH 2/4] Fix AnonymiseFileNames --- src/plugins/anonymiseFileNames/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/anonymiseFileNames/index.tsx b/src/plugins/anonymiseFileNames/index.tsx index d24de222..8237be8b 100644 --- a/src/plugins/anonymiseFileNames/index.tsx +++ b/src/plugins/anonymiseFileNames/index.tsx @@ -75,11 +75,7 @@ export default definePlugin({ find: "async uploadFiles(", replacement: [ { - match: /async uploadFiles\((\i),\i\){/, - replace: "$&$1.forEach($self.anonymise);" - }, - { - match: /async uploadFilesSimple\((\i)\){/, + match: /async uploadFiles\((\i)\){/, replace: "$&$1.forEach($self.anonymise);" } ], From 0444831073d9a6d9b165dbdfb9e220c79642ee9b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 17 Jun 2025 22:15:11 +0200 Subject: [PATCH 3/4] RoleColorEverywhere: fix chat mentions --- src/plugins/roleColorEverywhere/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/roleColorEverywhere/index.tsx b/src/plugins/roleColorEverywhere/index.tsx index dc60bb64..61ea7868 100644 --- a/src/plugins/roleColorEverywhere/index.tsx +++ b/src/plugins/roleColorEverywhere/index.tsx @@ -84,8 +84,8 @@ export default definePlugin({ find: ".USER_MENTION)", replacement: [ { - match: /(?<=onContextMenu:\i,color:)\i(?<=\.getNickname\((\i),\i,(\i).+?)/, - replace: "$self.getColorInt($2?.id,$1)", + match: /(?<=user:(\i),guildId:([^,]+?),.{0,100}?children:\i=>\i)\((\i)\)/, + replace: "({...$3,color:$self.getColorInt($1?.id,$2)})", } ], predicate: () => settings.store.chatMentions From 7779e5a1ecf24b74eb2171e2483f2d3826c18ea6 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 17 Jun 2025 22:37:56 +0200 Subject: [PATCH 4/4] fix IrcColors --- src/plugins/ircColors/index.ts | 50 +++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/plugins/ircColors/index.ts b/src/plugins/ircColors/index.ts index d543c995..d0d020af 100644 --- a/src/plugins/ircColors/index.ts +++ b/src/plugins/ircColors/index.ts @@ -67,9 +67,8 @@ export default definePlugin({ find: '="SYSTEM_TAG"', replacement: { // Override colorString with our custom color and disable gradients if applying the custom color. - match: /&&null!=\i\.secondaryColor,(?<=colorString:(\i).+?(\i)=.+?)/, - replace: (m, colorString, hasGradientColors) => `${m}` + - `vcIrcColorsDummy=[${colorString},${hasGradientColors}]=$self.getMessageColorsVariables(arguments[0],${hasGradientColors}),` + match: /(?<=colorString:\i,colorStrings:\i,colorRoleName:\i}=)(\i),/, + replace: "$self.wrapMessageColorProps($1, arguments[0])," } }, { @@ -82,11 +81,26 @@ export default definePlugin({ } ], - getMessageColorsVariables(context: any, hasGradientColors: boolean) { - const colorString = this.calculateNameColorForMessageContext(context); - const originalColorString = context?.author?.colorString; + wrapMessageColorProps(colorProps: { colorString: string, colorStrings?: Record<"primaryColor" | "secondaryColor" | "tertiaryColor", string>; }, context: any) { + try { + const colorString = this.calculateNameColorForMessageContext(context); + if (colorString === colorProps.colorString) { + return colorProps; + } - return [colorString, hasGradientColors && colorString === originalColorString]; + return { + ...colorProps, + colorString, + colorStrings: colorProps.colorStrings && { + primaryColor: colorString, + secondaryColor: undefined, + tertiaryColor: undefined + } + }; + } catch (e) { + console.error("Failed to calculate message color strings:", e); + return colorProps; + } }, calculateNameColorForMessageContext(context: any) { @@ -108,16 +122,20 @@ export default definePlugin({ }, calculateNameColorForListContext(context: any) { - const id = context?.user?.id; - const colorString = context?.colorString; - const color = calculateNameColorForUser(id); + try { + const id = context?.user?.id; + const colorString = context?.colorString; + const color = calculateNameColorForUser(id); - if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) { - return colorString; + if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) { + return colorString; + } + + return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) + ? color + : colorString; + } catch (e) { + console.error("Failed to calculate name color for list context:", e); } - - return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) - ? color - : colorString; } });