Fix ImplicitRelationships, RelationshipNotifier & ServerInfo

This commit is contained in:
Vendicated 2025-06-17 21:58:12 +02:00
parent 3a1e17e04d
commit 8d97863db6
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
7 changed files with 30 additions and 26 deletions

View file

@ -23,7 +23,7 @@ import { findStoreLazy } from "@webpack";
import { Constants, FluxDispatcher, GuildStore, RelationshipStore, RestAPI, SnowflakeUtils, UserStore } from "@webpack/common"; import { Constants, FluxDispatcher, GuildStore, RelationshipStore, RestAPI, SnowflakeUtils, UserStore } from "@webpack/common";
import { Settings } from "Vencord"; import { Settings } from "Vencord";
const UserAffinitiesStore = findStoreLazy("UserAffinitiesStore"); const UserAffinitiesStore = findStoreLazy("UserAffinitiesV2Store");
export default definePlugin({ export default definePlugin({
name: "ImplicitRelationships", name: "ImplicitRelationships",
@ -117,7 +117,7 @@ export default definePlugin({
wrapSort(comparator: Function, row: any) { wrapSort(comparator: Function, row: any) {
return row.type === 5 return row.type === 5
? -(UserAffinitiesStore.getUserAffinity(row.user.id)?.affinity ?? 0) ? (UserAffinitiesStore.getUserAffinity(row.user.id)?.communicationRank ?? 0)
: comparator(row); : comparator(row);
}, },
@ -139,17 +139,15 @@ export default definePlugin({
// 1. Have an affinity for // 1. Have an affinity for
// 2. Do not have a relationship with // 2. Do not have a relationship with
await this.refreshUserAffinities(); await this.refreshUserAffinities();
const userAffinities: Set<string> = UserAffinitiesStore.getUserAffinitiesUserIds(); const userAffinities: Record<string, any>[] = UserAffinitiesStore.getUserAffinities();
const relationships = RelationshipStore.getRelationships(); const relationships = RelationshipStore.getMutableRelationships();
const nonFriendAffinities = Array.from(userAffinities).filter( const nonFriendAffinities = userAffinities.filter(a => !RelationshipStore.getRelationshipType(a.otherUserId));
id => !RelationshipStore.getRelationshipType(id) nonFriendAffinities.forEach(a => {
); relationships[a.otherUserId] = 5;
nonFriendAffinities.forEach(id => {
relationships[id] = 5;
}); });
RelationshipStore.emitChange(); 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 allGuildIds = Object.keys(GuildStore.getGuilds());
const sentNonce = SnowflakeUtils.fromTimestamp(Date.now()); const sentNonce = SnowflakeUtils.fromTimestamp(Date.now());
let count = allGuildIds.length * Math.ceil(toRequest.length / 100); let count = allGuildIds.length * Math.ceil(toRequest.length / 100);

View file

@ -21,12 +21,9 @@ import { Devs } from "@utils/constants";
import { runtimeHashMessageKey } from "@utils/intlHash"; import { runtimeHashMessageKey } from "@utils/intlHash";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { i18n, RelationshipStore } from "@webpack/common";
import { i18n } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked");
interface MessageDeleteProps { interface MessageDeleteProps {
// Internal intl message for BLOCKED_MESSAGE_COUNT // Internal intl message for BLOCKED_MESSAGE_COUNT
collapsedReason: () => any; collapsedReason: () => any;

View file

@ -19,19 +19,15 @@
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; 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 { ChannelStore, ComponentDispatch, FluxDispatcher as Dispatcher, MessageActions, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
import NoBlockedMessagesPlugin from "plugins/noBlockedMessages"; import NoBlockedMessagesPlugin from "plugins/noBlockedMessages";
import NoReplyMentionPlugin from "plugins/noReplyMention"; import NoReplyMentionPlugin from "plugins/noReplyMention";
const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked");
const isMac = navigator.platform.includes("Mac"); // bruh const isMac = navigator.platform.includes("Mac"); // bruh
let currentlyReplyingId: string | null = null; let currentlyReplyingId: string | null = null;
let currentlyEditingId: string | null = null; let currentlyEditingId: string | null = null;
const enum MentionOptions { const enum MentionOptions {
DISABLED, DISABLED,
ENABLED, ENABLED,

View file

@ -172,7 +172,7 @@ export async function syncFriends() {
friends.friends = []; friends.friends = [];
friends.requests = []; friends.requests = [];
const relationShips = RelationshipStore.getRelationships(); const relationShips = RelationshipStore.getMutableRelationships();
for (const id in relationShips) { for (const id in relationShips) {
switch (relationShips[id]) { switch (relationShips[id]) {
case RelationshipType.FRIEND: case RelationshipType.FRIEND:

View file

@ -220,12 +220,12 @@ function FriendsTab({ guild, setCount }: RelationshipProps) {
} }
function BlockedUsersTab({ 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); return UserList("blocked", guild, blockedIds, setCount);
} }
function IgnoredUserTab({ guild, setCount }: RelationshipProps) { 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); return UserList("ignored", guild, ignoredIds, setCount);
} }

View file

@ -46,11 +46,7 @@ export let SelectedChannelStore: Stores.SelectedChannelStore & t.FluxStore;
export let SelectedGuildStore: t.FluxStore & Record<string, any>; export let SelectedGuildStore: t.FluxStore & Record<string, any>;
export let ChannelStore: Stores.ChannelStore & t.FluxStore; export let ChannelStore: Stores.ChannelStore & t.FluxStore;
export let GuildMemberStore: Stores.GuildMemberStore & t.FluxStore; export let GuildMemberStore: Stores.GuildMemberStore & t.FluxStore;
export let RelationshipStore: Stores.RelationshipStore & t.FluxStore & { export let RelationshipStore: t.RelationshipStore;
/** Get the date (as a string) that the relationship was created */
getSince(userId: string): string;
isIgnored(userId: string): boolean;
};
export let EmojiStore: t.EmojiStore; export let EmojiStore: t.EmojiStore;
export let ThemeStore: t.ThemeStore; export let ThemeStore: t.ThemeStore;

View file

@ -233,3 +233,20 @@ export type useStateFromStores = <T>(
dependencies?: any, dependencies?: any,
isEqual?: (old: T, newer: T) => boolean isEqual?: (old: T, newer: T) => boolean
) => T; ) => 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<number, number>;
isBlocked(userId: string): boolean;
isFriend(userId: string): boolean;
getSince(userId: string): string;
isIgnored(userId: string): boolean;
}