diff options
author | Syncx <47534062+Syncxv@users.noreply.github.com> | 2023-05-17 12:38:15 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 04:38:15 +0200 |
commit | 1d6b78f6c660f0cd6905552243a3908366a28595 (patch) | |
tree | c8d217a937be8bf2ce39f24e031208388d8f9cb5 /src/plugins | |
parent | 341151a71811ddf2a7a36af3dc037135d2b9f7dd (diff) | |
download | Vencord-1d6b78f6c660f0cd6905552243a3908366a28595.tar.gz Vencord-1d6b78f6c660f0cd6905552243a3908366a28595.tar.bz2 Vencord-1d6b78f6c660f0cd6905552243a3908366a28595.zip |
feat(plugin): FavoriteEmojiFirst (#1110)
Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/emoteCloner.tsx | 5 | ||||
-rw-r--r-- | src/plugins/fakeNitro.tsx | 4 | ||||
-rw-r--r-- | src/plugins/favEmojiFirst.ts | 83 | ||||
-rw-r--r-- | src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx | 5 |
4 files changed, 88 insertions, 9 deletions
diff --git a/src/plugins/emoteCloner.tsx b/src/plugins/emoteCloner.tsx index 01065fd..0900422 100644 --- a/src/plugins/emoteCloner.tsx +++ b/src/plugins/emoteCloner.tsx @@ -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) diff --git a/src/plugins/fakeNitro.tsx b/src/plugins/fakeNitro.tsx index b48a466..88b2ae2 100644 --- a/src/plugins/fakeNitro.tsx +++ b/src/plugins/fakeNitro.tsx @@ -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; diff --git a/src/plugins/favEmojiFirst.ts b/src/plugins/favEmojiFirst.ts new file mode 100644 index 0000000..fec0b04 --- /dev/null +++ b/src/plugins/favEmojiFirst.ts @@ -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); + } +}); diff --git a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx index 2d1441a..506fbe7 100644 --- a/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx +++ b/src/plugins/showHiddenChannels/components/HiddenChannelLockScreen.tsx @@ -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"); |