mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-27 23:44:25 -04:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
0741086dc2
7 changed files with 76 additions and 40 deletions
|
@ -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<string> = UserAffinitiesStore.getUserAffinitiesUserIds();
|
||||
const userAffinities: Record<string, any>[] = 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
17
src/webpack/common/types/stores.d.ts
vendored
17
src/webpack/common/types/stores.d.ts
vendored
|
@ -272,3 +272,20 @@ export type useStateFromStores = <T>(
|
|||
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<number, number>;
|
||||
isBlocked(userId: string): boolean;
|
||||
isFriend(userId: string): boolean;
|
||||
|
||||
getSince(userId: string): string;
|
||||
isIgnored(userId: string): boolean;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue