mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 03:17:02 -04:00
feat(plugin): FavoriteEmojiFirst (#1110)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
341151a718
commit
1d6b78f6c6
7 changed files with 193 additions and 20 deletions
|
@ -24,12 +24,11 @@ import { Margins } from "@utils/margins";
|
|||
import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
|
||||
import definePlugin from "@utils/types";
|
||||
import { findByCodeLazy, findStoreLazy } from "@webpack";
|
||||
import { FluxDispatcher, Forms, GuildStore, Menu, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
|
||||
import { EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
|
||||
import { Promisable } from "type-fest";
|
||||
|
||||
const MANAGE_EMOJIS_AND_STICKERS = 1n << 30n;
|
||||
|
||||
const GuildEmojiStore = findStoreLazy("EmojiStore");
|
||||
const StickersStore = findStoreLazy("StickersStore");
|
||||
const uploadEmoji = findByCodeLazy('"EMOJI_UPLOAD_START"', "GUILD_EMOJIS(");
|
||||
|
||||
|
@ -129,7 +128,7 @@ function getGuildCandidates(data: Data) {
|
|||
const { isAnimated } = data as Emoji;
|
||||
|
||||
const emojiSlots = g.getMaxEmojiSlots();
|
||||
const { emojis } = GuildEmojiStore.getGuilds()[g.id];
|
||||
const { emojis } = EmojiStore.getGuilds()[g.id];
|
||||
|
||||
let count = 0;
|
||||
for (const emoji of emojis)
|
||||
|
|
|
@ -24,7 +24,7 @@ import { getCurrentGuild } from "@utils/discord";
|
|||
import { proxyLazy } from "@utils/lazy";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, FluxDispatcher, Parser, PermissionStore, UserStore } from "@webpack/common";
|
||||
import { ChannelStore, EmojiStore, FluxDispatcher, Parser, PermissionStore, UserStore } from "@webpack/common";
|
||||
import type { Message } from "discord-types/general";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
|
@ -38,8 +38,6 @@ const StickerStore = findStoreLazy("StickersStore") as {
|
|||
getAllGuildStickers(): Map<string, Sticker[]>;
|
||||
getStickerById(id: string): Sticker | undefined;
|
||||
};
|
||||
const EmojiStore = findStoreLazy("EmojiStore");
|
||||
|
||||
|
||||
function searchProtoClass(localName: string, parentProtoClass: any) {
|
||||
if (!parentProtoClass) return;
|
||||
|
|
83
src/plugins/favEmojiFirst.ts
Normal file
83
src/plugins/favEmojiFirst.ts
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { EmojiStore } from "@webpack/common";
|
||||
import { Emoji } from "@webpack/types";
|
||||
|
||||
interface EmojiAutocompleteState {
|
||||
query?: {
|
||||
type: string;
|
||||
typeInfo: {
|
||||
sentinel: string;
|
||||
};
|
||||
results: {
|
||||
emojis: Emoji[] & { sliceTo?: number; };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "FavoriteEmojiFirst",
|
||||
authors: [Devs.Aria, Devs.Ven],
|
||||
description: "Puts your favorite emoji first in the emoji autocomplete.",
|
||||
patches: [
|
||||
{
|
||||
find: ".activeCommandOption",
|
||||
replacement: [
|
||||
{
|
||||
// = someFunc(a.selectedIndex); ...trackEmojiSearch({ state: theState, isInPopoutExperimental: someBool })
|
||||
match: /=\i\(\i\.selectedIndex\);(?=.+?state:(\i),isInPopoutExperiment:\i)/,
|
||||
// self.sortEmojis(theState)
|
||||
replace: "$&$self.sortEmojis($1);"
|
||||
},
|
||||
|
||||
// set maxCount to Infinity so our sortEmojis callback gets the entire list, not just the first 10
|
||||
// and remove Discord's emojiResult slice, storing the endIndex on the array for us to use later
|
||||
{
|
||||
// searchEmojis(...,maxCount: stuff) ... endEmojis = emojis.slice(0, maxCount - gifResults.length)
|
||||
match: /,maxCount:(\i)(.+?)=(\i)\.slice\(0,(\1-\i\.length)\)/,
|
||||
// ,maxCount:Infinity ... endEmojis = (emojis.sliceTo = n, emojis)
|
||||
replace: ",maxCount:Infinity$2=($3.sliceTo=$4,$3)"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
sortEmojis({ query }: EmojiAutocompleteState) {
|
||||
if (
|
||||
query?.type !== "EMOJIS_AND_STICKERS"
|
||||
|| query.typeInfo?.sentinel !== ":"
|
||||
|| !query.results?.emojis?.length
|
||||
) return;
|
||||
|
||||
const emojiContext = EmojiStore.getDisambiguatedEmojiContext();
|
||||
|
||||
query.results.emojis = query.results.emojis.sort((a, b) => {
|
||||
const aIsFavorite = emojiContext.isFavoriteEmojiWithoutFetchingLatest(a);
|
||||
const bIsFavorite = emojiContext.isFavoriteEmojiWithoutFetchingLatest(b);
|
||||
|
||||
if (aIsFavorite && !bIsFavorite) return -1;
|
||||
|
||||
if (!aIsFavorite && bIsFavorite) return 1;
|
||||
|
||||
return 0;
|
||||
}).slice(0, query.results.emojis.sliceTo ?? 10);
|
||||
}
|
||||
});
|
|
@ -20,8 +20,8 @@ import { Settings } from "@api/Settings";
|
|||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { LazyComponent } from "@utils/react";
|
||||
import { formatDuration } from "@utils/text";
|
||||
import { find, findByPropsLazy, findStoreLazy } from "@webpack";
|
||||
import { FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common";
|
||||
import { find, findByPropsLazy } from "@webpack";
|
||||
import { EmojiStore, FluxDispatcher, GuildMemberStore, GuildStore, moment, Parser, PermissionStore, SnowflakeUtils, Text, Timestamp, Tooltip, useEffect, useState } from "@webpack/common";
|
||||
import type { Channel } from "discord-types/general";
|
||||
import type { ComponentType } from "react";
|
||||
|
||||
|
@ -94,7 +94,6 @@ const TagComponent = LazyComponent(() => find(m => {
|
|||
return code.includes(".Messages.FORUM_TAG_A11Y_FILTER_BY_TAG") && !code.includes("increasedActivityPill");
|
||||
}));
|
||||
|
||||
const EmojiStore = findStoreLazy("EmojiStore");
|
||||
const EmojiParser = findByPropsLazy("convertSurrogateToName");
|
||||
const EmojiUtils = findByPropsLazy("getURL", "buildEmojiReactionColorsPlatformed");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue