diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index d332fc6c..edaf4be9 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -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 userAffinities: Record[] = UserAffinitiesStore.getUserAffinities(); const relationships = RelationshipStore.getMutableRelationships(); - const nonFriendAffinities = Array.from(userAffinities).filter( - id => !RelationshipStore.getRelationshipType(id) - ); - nonFriendAffinities.forEach(id => { - relationships[id] = 5; + 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/ircColors/index.ts b/src/plugins/ircColors/index.ts index c9d2c613..5506acd5 100644 --- a/src/plugins/ircColors/index.ts +++ b/src/plugins/ircColors/index.ts @@ -68,9 +68,8 @@ export default definePlugin({ find: '="SYSTEM_TAG"', replacement: { // Override colorString with our custom color and disable gradients if applying the custom color. - match: /useContext\(\i\.\i\),(?<=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])," } }, { @@ -83,38 +82,41 @@ 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) { const userId: string | undefined = context?.message?.author?.id; const colorString = context?.author?.colorString; const color = calculateNameColorForUser(userId); - const customColor = userId && Settings.plugins.CustomUserColors.enabled ? getCustomColorString(userId, true) : null; - - if ( - (context?.message?.channel_id === "1337" && userId === "313337") || - (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) || - (settings.store.applyColorOnlyToUsersWithoutColor && colorString) - ) return customColor ?? colorString; - - return customColor ?? color; - }, - - calculateNameColorForListContext(context: any) { - const id = context?.user?.id; - const colorString = context?.colorString; - const color = calculateNameColorForUser(id); if (Settings.plugins.CustomUserColors.enabled) { - const customColor = getCustomColorString(id, true); + const customColor = getCustomColorString(userId, true); if (customColor) return customColor; } + if (context?.message?.channel_id === "1337" && userId === "313337") + return colorString; + if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) { return colorString; } @@ -122,5 +124,28 @@ export default definePlugin({ return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) ? color : colorString; + }, + + calculateNameColorForListContext(context: any) { + try { + const id = context?.user?.id; + const colorString = context?.colorString; + const color = calculateNameColorForUser(id); + + if (Settings.plugins.CustomUserColors.enabled) { + const customColor = getCustomColorString(id, true); + if (customColor) return customColor; + } + + 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); + } } }); diff --git a/src/plugins/noBlockedMessages/index.ts b/src/plugins/noBlockedMessages/index.ts index 81265d41..b64fca3e 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, MessageStore } from "@webpack/common"; +import { i18n, MessageStore, RelationshipStore } from "@webpack/common"; import { Message } from "discord-types/general"; -const RelationshipStore = findByPropsLazy("getFriendIDs", "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 e5d52085..dcd2038c 100644 --- a/src/plugins/quickReply/index.ts +++ b/src/plugins/quickReply/index.ts @@ -28,7 +28,6 @@ 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/roleColorEverywhere/index.tsx b/src/plugins/roleColorEverywhere/index.tsx index 68379753..accf465c 100644 --- a/src/plugins/roleColorEverywhere/index.tsx +++ b/src/plugins/roleColorEverywhere/index.tsx @@ -85,8 +85,8 @@ export default definePlugin({ find: ".USER_MENTION)", replacement: [ { - match: /(?<=onContextMenu:\i(?!,children))(?<=\.getNickname\((\i),\i,(\i).+?)/, - replace: ",color:$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 diff --git a/src/plugins/serverInfo/GuildInfoModal.tsx b/src/plugins/serverInfo/GuildInfoModal.tsx index 40a0a1ab..9920d8aa 100644 --- a/src/plugins/serverInfo/GuildInfoModal.tsx +++ b/src/plugins/serverInfo/GuildInfoModal.tsx @@ -255,12 +255,12 @@ function FriendsTab({ guild, setCount }: RelationshipProps) { } function BlockedUsersTab({ guild, setCount }: RelationshipProps) { - const blockedIds = RelationshipStore.getBlockedIDs(); + const blockedIds = Object.keys(RelationshipStore.getMutableRelationships()).filter(id => RelationshipStore.isBlocked(id)); return UserList("blocked", guild, blockedIds, setCount); } function IgnoredUserTab({ guild, setCount }: RelationshipProps) { - const ignoredIds = RelationshipStore.getIgnoredIDs(); + const ignoredIds = Object.keys(RelationshipStore.getMutableRelationships()).filter(id => RelationshipStore.isIgnored(id)); return UserList("ignored", guild, ignoredIds, setCount); } diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts index 98e230f6..b2e42f0e 100644 --- a/src/webpack/common/types/stores.d.ts +++ b/src/webpack/common/types/stores.d.ts @@ -272,3 +272,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; +}