From 5648b16107c81bc31bb0dab5dfd1c729e23c52af Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:21:23 -0600 Subject: [PATCH] brand new inbox feature --- src/plugins/keywordNotify/index.tsx | 154 ++++++++++++++++++++++++++-- 1 file changed, 146 insertions(+), 8 deletions(-) diff --git a/src/plugins/keywordNotify/index.tsx b/src/plugins/keywordNotify/index.tsx index faacbe1a8..760a6859a 100644 --- a/src/plugins/keywordNotify/index.tsx +++ b/src/plugins/keywordNotify/index.tsx @@ -10,12 +10,19 @@ import { definePluginSettings } from "@api/Settings"; import { DeleteIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { Flex } from "@components/Flex"; -import { TextInput, useState, Forms, Button, UserStore, UserUtils } from "@webpack/common"; +import { TextInput, useState, Forms, Button, UserStore, UserUtils, TabBar, ChannelStore, SelectedChannelStore } from "@webpack/common"; import { useForceUpdater } from "@utils/react"; +import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy, filters } from "@webpack"; import "./style.css"; let regexes = []; -let me = null; + +const MenuHeader = findByCodeLazy("useInDesktopNotificationCenterExperiment)("); +const Popout = findByPropsLazy("ItemsPopout"); +const popoutClasses = findByPropsLazy("recentMentionsPopout"); +const MessageObject = findByCodeLazy("}isFirstMessageInForumPost"); +const createMessageRecord = mapMangledModuleLazy("createMessageRecord:", {fn: filters.byCode("MessageTypes.THREAD_CREATED")}) + async function setRegexes(idx: number, reg: string) { regexes[idx] = reg; @@ -42,6 +49,31 @@ function safeMatchesRegex(s: string, r: string) { } } +function highlightKeywords(s: string, r: Array) { + let reg; + try { + reg = new RegExp(r.join("|"), "g"); + } catch { + return [s]; + } + + let matches = s.match(reg); + if (!matches) + return [s]; + + let parts = [...matches.map((e) => { + let idx = s.indexOf(e); + let before = s.substring(0, idx); + s = s.substring(idx + e.length); + return before; + }, s), s]; + + return parts.map(e => [ + ({e}), + matches.length ? ({matches.splice(0, 1)[0]}) : [] + ]); +} + const settings = definePluginSettings({ replace: { type: OptionType.COMPONENT, @@ -64,14 +96,13 @@ const settings = definePluginSettings({
setRegexes(i, values[i])} />
-