Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
thororen 2024-08-25 00:30:13 -04:00
commit f3ec0d86eb
13 changed files with 111 additions and 59 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "equicord", "name": "equicord",
"private": "true", "private": "true",
"version": "1.9.7", "version": "1.9.8",
"description": "The other cutest Discord client mod", "description": "The other cutest Discord client mod",
"homepage": "https://github.com/Equicord/Equicord#readme", "homepage": "https://github.com/Equicord/Equicord#readme",
"bugs": { "bugs": {

View file

@ -240,6 +240,10 @@ export function definePluginSettings<
if (!definedSettings.pluginName) throw new Error("Cannot access settings before plugin is initialized"); if (!definedSettings.pluginName) throw new Error("Cannot access settings before plugin is initialized");
return Settings.plugins[definedSettings.pluginName] as any; return Settings.plugins[definedSettings.pluginName] as any;
}, },
get plain() {
if (!definedSettings.pluginName) throw new Error("Cannot access settings before plugin is initialized");
return PlainSettings.plugins[definedSettings.pluginName] as any;
},
use: settings => useSettings( use: settings => useSettings(
settings?.map(name => `plugins.${definedSettings.pluginName}.${name}`) as UseSettings<Settings>[] settings?.map(name => `plugins.${definedSettings.pluginName}.${name}`) as UseSettings<Settings>[]
).plugins[definedSettings.pluginName] as any, ).plugins[definedSettings.pluginName] as any,

View file

@ -22,7 +22,7 @@ import { Devs } from "@utils/constants";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findLazy } from "@webpack"; import { findByCodeLazy, findLazy } from "@webpack";
import { Card, ChannelStore, Forms, GuildStore, PermissionsBits, Switch, TextInput, Tooltip, useState } from "@webpack/common"; import { Card, ChannelStore, Forms, GuildStore, PermissionsBits, Switch, TextInput, Tooltip } from "@webpack/common";
import type { Permissions, RC } from "@webpack/types"; import type { Permissions, RC } from "@webpack/types";
import type { Channel, Guild, Message, User } from "discord-types/general"; import type { Channel, Guild, Message, User } from "discord-types/general";
@ -107,14 +107,8 @@ const defaultSettings = Object.fromEntries(
tags.map(({ name, displayName }) => [name, { text: displayName, showInChat: true, showInNotChat: true }]) tags.map(({ name, displayName }) => [name, { text: displayName, showInChat: true, showInNotChat: true }])
) as TagSettings; ) as TagSettings;
function SettingsComponent(props: { setValue(v: any): void; }) { function SettingsComponent() {
settings.store.tagSettings ??= defaultSettings; const tagSettings = settings.store.tagSettings ??= defaultSettings;
const [tagSettings, setTagSettings] = useState(settings.store.tagSettings as TagSettings);
const setValue = (v: TagSettings) => {
setTagSettings(v);
props.setValue(v);
};
return ( return (
<Flex flexDirection="column"> <Flex flexDirection="column">
@ -137,19 +131,13 @@ function SettingsComponent(props: { setValue(v: any): void; }) {
type="text" type="text"
value={tagSettings[t.name]?.text ?? t.displayName} value={tagSettings[t.name]?.text ?? t.displayName}
placeholder={`Text on tag (default: ${t.displayName})`} placeholder={`Text on tag (default: ${t.displayName})`}
onChange={v => { onChange={v => tagSettings[t.name].text = v}
tagSettings[t.name].text = v;
setValue(tagSettings);
}}
className={Margins.bottom16} className={Margins.bottom16}
/> />
<Switch <Switch
value={tagSettings[t.name]?.showInChat ?? true} value={tagSettings[t.name]?.showInChat ?? true}
onChange={v => { onChange={v => tagSettings[t.name].showInChat = v}
tagSettings[t.name].showInChat = v;
setValue(tagSettings);
}}
hideBorder hideBorder
> >
Show in messages Show in messages
@ -157,10 +145,7 @@ function SettingsComponent(props: { setValue(v: any): void; }) {
<Switch <Switch
value={tagSettings[t.name]?.showInNotChat ?? true} value={tagSettings[t.name]?.showInNotChat ?? true}
onChange={v => { onChange={v => tagSettings[t.name].showInNotChat = v}
tagSettings[t.name].showInNotChat = v;
setValue(tagSettings);
}}
hideBorder hideBorder
> >
Show in member list and profiles Show in member list and profiles
@ -183,7 +168,7 @@ const settings = definePluginSettings({
tagSettings: { tagSettings: {
type: OptionType.COMPONENT, type: OptionType.COMPONENT,
component: SettingsComponent, component: SettingsComponent,
description: "fill me", description: "fill me"
} }
}); });

View file

@ -0,0 +1,3 @@
# NoMaskedUrlPaste
Pasting a link while you have text selected will NOT paste your link as a masked link.

View file

@ -0,0 +1,23 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Devs } from "@utils/constants.js";
import definePlugin from "@utils/types";
export default definePlugin({
name: "NoMaskedUrlPaste",
authors: [Devs.CatNoir],
description: "Pasting a link while having text selected will not paste as masked URL",
patches: [
{
find: ".selection,preventEmojiSurrogates:",
replacement: {
match: /if\(null!=\i.selection&&\i.\i.isExpanded\(\i.selection\)\)/,
replace: "if(false)"
}
}
],
});

View file

@ -19,7 +19,6 @@
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { UserStore } from "@webpack/common"; import { UserStore } from "@webpack/common";
import virtualMerge from "virtual-merge";
export default definePlugin({ export default definePlugin({
name: "NoProfileThemes", name: "NoProfileThemes",
@ -33,21 +32,7 @@ export default definePlugin({
replace: "$&$self.isCurrentUser(this.userId)&&" replace: "$&$self.isCurrentUser(this.userId)&&"
} }
}, },
{
find: "UserProfileStore",
replacement: {
match: /(?<=getUserProfile\(\i\){return )(.+?)(?=})/,
replace: "$self.removeProfileThemes($1)"
}
}
], ],
isCurrentUser: (userId: string) => userId === UserStore.getCurrentUser()?.id, isCurrentUser: (userId: string) => userId === UserStore.getCurrentUser()?.id,
removeProfileThemes: (displayProfile: any) => {
if (displayProfile == null) return displayProfile;
return displayProfile.userId === UserStore.getCurrentUser()?.id
? displayProfile
: virtualMerge(displayProfile, { banner: undefined, profileEffectId: undefined });
}
}); });

View file

@ -26,11 +26,6 @@ import { CompactPronounsChatComponentWrapper, PronounsChatComponentWrapper } fro
import { useProfilePronouns } from "./pronoundbUtils"; import { useProfilePronouns } from "./pronoundbUtils";
import { settings } from "./settings"; import { settings } from "./settings";
const PRONOUN_TOOLTIP_PATCH = {
match: /text:(.{0,10}.Messages\.USER_PROFILE_PRONOUNS)(?=,)/,
replace: '$& + (typeof vcPronounSource !== "undefined" ? ` (${vcPronounSource})` : "")'
};
export default definePlugin({ export default definePlugin({
name: "PronounDB", name: "PronounDB",
authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven, Devs.Elvyra], authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven, Devs.Elvyra],
@ -53,7 +48,24 @@ export default definePlugin({
] ]
}, },
// @TODO Patch discord pronoun hook in user profiles (useProfilePronouns) {
find: ".Messages.USER_PROFILE_PRONOUNS",
group: true,
replacement: [
{
match: /\.PANEL},/,
replace: "$&[vcPronoun,vcPronounSource,vcHasPendingPronouns]=$self.useProfilePronouns(arguments[0].user?.id),"
},
{
match: /text:\i\.\i.Messages.USER_PROFILE_PRONOUNS/,
replace: '$&+vcHasPendingPronouns?"":` (${vcPronounSource})`'
},
{
match: /(\.pronounsText.+?children:)(\i)/,
replace: "$1vcHasPendingPronouns?$2:vcPronoun"
}
]
}
], ],
settings, settings,

View file

@ -21,13 +21,16 @@ import { debounce } from "@shared/debounce";
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
import { getCurrentChannel } from "@utils/discord"; import { getCurrentChannel } from "@utils/discord";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
import { findStoreLazy } from "@webpack";
import { UserProfileStore, UserStore } from "@webpack/common"; import { UserProfileStore, UserStore } from "@webpack/common";
import { settings } from "./settings"; import { settings } from "./settings";
import { CachePronouns, PronounCode, PronounMapping, PronounsResponse } from "./types"; import { CachePronouns, PronounCode, PronounMapping, PronounsResponse } from "./types";
type PronounsWithSource = [string | null, string]; const UserSettingsAccountStore = findStoreLazy("UserSettingsAccountStore");
const EmptyPronouns: PronounsWithSource = [null, ""];
type PronounsWithSource = [pronouns: string | null, source: string, hasPendingPronouns: boolean];
const EmptyPronouns: PronounsWithSource = [null, "", false];
export const enum PronounsFormat { export const enum PronounsFormat {
Lowercase = "LOWERCASE", Lowercase = "LOWERCASE",
@ -75,13 +78,15 @@ export function useFormattedPronouns(id: string, useGlobalProfile: boolean = fal
onError: e => console.error("Fetching pronouns failed: ", e) onError: e => console.error("Fetching pronouns failed: ", e)
}); });
const hasPendingPronouns = UserSettingsAccountStore.getPendingPronouns() != null;
if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns) if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns)
return [discordPronouns, "Discord"]; return [discordPronouns, "Discord", hasPendingPronouns];
if (result && result !== PronounMapping.unspecified) if (result && result !== PronounMapping.unspecified)
return [result, "PronounDB"]; return [result, "PronounDB", hasPendingPronouns];
return [discordPronouns, "Discord"]; return [discordPronouns, "Discord", hasPendingPronouns];
} }
export function useProfilePronouns(id: string, useGlobalProfile: boolean = false): PronounsWithSource { export function useProfilePronouns(id: string, useGlobalProfile: boolean = false): PronounsWithSource {
@ -148,7 +153,7 @@ async function bulkFetchPronouns(ids: string[]): Promise<PronounsResponse> {
} }
} }
export function extractPronouns(pronounSet?: { [locale: string]: PronounCode[] }): string { export function extractPronouns(pronounSet?: { [locale: string]: PronounCode[]; }): string {
if (!pronounSet || !pronounSet.en) return PronounMapping.unspecified; if (!pronounSet || !pronounSet.en) return PronounMapping.unspecified;
// PronounDB returns an empty set instead of {sets: {en: ["unspecified"]}}. // PronounDB returns an empty set instead of {sets: {en: ["unspecified"]}}.
const pronouns = pronounSet.en; const pronouns = pronounSet.en;

View file

@ -96,10 +96,24 @@ export default definePlugin({
{ {
find: ".BITE_SIZE,user:", find: ".BITE_SIZE,user:",
replacement: { replacement: {
match: /(?<=\.BITE_SIZE,children:\[)\(0,\i\.jsx\)\(\i\.\i,\{user:(\i),/, match: /{profileType:\i\.\i\.BITE_SIZE,children:\[/,
replace: "$self.BiteSizeReviewsButton({user:$1}),$&" replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
}, },
predicate: () => settings.store.preferButtonOverDropdown predicate: () => settings.store.preferButtonOverDropdown
},
{
find: ".FULL_SIZE,user:",
replacement: {
match: /{profileType:\i\.\i\.FULL_SIZE,children:\[/,
replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
}
},
{
find: ".PANEL,isInteractionSource:",
replacement: {
match: /{profileType:\i\.\i\.PANEL,children:\[/,
replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
}
} }
], ],

View file

@ -168,7 +168,7 @@ export default definePlugin({
patches: [ patches: [
{ {
find: '"BiteSizeProfileBody"', find: ".hasAvatarForGuild(null==",
replacement: { replacement: {
match: /currentUser:\i,guild:\i}\)(?<=user:(\i),bio:null==(\i)\?.+?)/, match: /currentUser:\i,guild:\i}\)(?<=user:(\i),bio:null==(\i)\?.+?)/,
replace: "$&,$self.profilePopoutComponent({ user: $1, displayProfile: $2 })" replace: "$&,$self.profilePopoutComponent({ user: $1, displayProfile: $2 })"

View file

@ -309,6 +309,8 @@ export interface DefinedSettings<
> { > {
/** Shorthand for `Vencord.Settings.plugins.PluginName`, but with typings */ /** Shorthand for `Vencord.Settings.plugins.PluginName`, but with typings */
store: SettingsStore<Def> & PrivateSettings; store: SettingsStore<Def> & PrivateSettings;
/** Shorthand for `Vencord.PlainSettings.plugins.PluginName`, but with typings */
plain: SettingsStore<Def> & PrivateSettings;
/** /**
* React hook for getting the settings for this plugin * React hook for getting the settings for this plugin
* @param filter optional filter to avoid rerenders for irrelevent settings * @param filter optional filter to avoid rerenders for irrelevent settings

View file

@ -223,9 +223,26 @@ export interface Constants {
FriendsSections: Record<string, string>; FriendsSections: Record<string, string>;
} }
export type ActiveView = LiteralUnion<"emoji" | "gif" | "sticker" | "soundboard", string>;
export interface ExpressionPickerStoreState extends Record<PropertyKey, any> {
activeView: ActiveView | null;
lastActiveView: ActiveView | null;
activeViewType: any | null;
searchQuery: string;
isSearchSuggestion: boolean,
pickerId: string;
}
export interface ExpressionPickerStore { export interface ExpressionPickerStore {
openExpressionPicker(activeView: ActiveView, activeViewType?: any): void;
closeExpressionPicker(activeViewType?: any): void; closeExpressionPicker(activeViewType?: any): void;
openExpressionPicker(activeView: LiteralUnion<"emoji" | "gif" | "sticker", string>, activeViewType?: any): void; toggleMultiExpressionPicker(activeViewType?: any): void;
toggleExpressionPicker(activeView: ActiveView, activeViewType?: any): void;
setExpressionPickerView(activeView: ActiveView): void;
setSearchQuery(searchQuery: string, isSearchSuggestion?: boolean): void;
useExpressionPickerStore(): ExpressionPickerStoreState;
useExpressionPickerStore<T>(selector: (state: ExpressionPickerStoreState) => T): T;
} }
export interface BrowserWindowFeatures { export interface BrowserWindowFeatures {

View file

@ -16,10 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { canonicalizeMatch } from "@utils/patches";
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "@webpack";
import type { Channel } from "discord-types/general"; import type { Channel } from "discord-types/general";
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
import type * as t from "./types/utils"; import type * as t from "./types/utils";
export let FluxDispatcher: t.FluxDispatcher; export let FluxDispatcher: t.FluxDispatcher;
@ -168,11 +167,14 @@ export const ReadStateUtils = mapMangledModuleLazy('type:"ENABLE_AUTOMATIC_ACK",
ackChannel: filters.byCode(".getActiveJoinedThreadsForParent(") ackChannel: filters.byCode(".getActiveJoinedThreadsForParent(")
}); });
const openExpressionPickerMatcher = canonicalizeMatch(/setState\({activeView:\i,activeViewType:/);
// TODO: type
export const ExpressionPickerStore: t.ExpressionPickerStore = mapMangledModuleLazy("expression-picker-last-active-view", { export const ExpressionPickerStore: t.ExpressionPickerStore = mapMangledModuleLazy("expression-picker-last-active-view", {
openExpressionPicker: filters.byCode(/setState\({activeView:(?:(?!null)\i),activeViewType:/),
closeExpressionPicker: filters.byCode("setState({activeView:null"), closeExpressionPicker: filters.byCode("setState({activeView:null"),
openExpressionPicker: m => typeof m === "function" && openExpressionPickerMatcher.test(m.toString()), toggleMultiExpressionPicker: filters.byCode(".EMOJI,"),
toggleExpressionPicker: filters.byCode(/getState\(\)\.activeView===\i\?\i\(\):\i\(/),
setExpressionPickerView: filters.byCode(/setState\({activeView:\i,lastActiveView:/),
setSearchQuery: filters.byCode("searchQuery:"),
useExpressionPickerStore: filters.byCode("Object.is")
}); });
export const PopoutActions: t.PopoutActions = mapMangledModuleLazy('type:"POPOUT_WINDOW_OPEN"', { export const PopoutActions: t.PopoutActions = mapMangledModuleLazy('type:"POPOUT_WINDOW_OPEN"', {