diff --git a/src/equicordplugins/keywordNotify/index.tsx b/src/equicordplugins/keywordNotify/index.tsx index 6efddc43b..573841bdb 100644 --- a/src/equicordplugins/keywordNotify/index.tsx +++ b/src/equicordplugins/keywordNotify/index.tsx @@ -11,7 +11,7 @@ import { definePluginSettings } from "@api/Settings"; import { Button, TextButton } from "@components/Button"; import { Flex } from "@components/Flex"; import { FormSwitch } from "@components/FormSwitch"; -import { Heading, HeadingTertiary } from "@components/Heading"; +import { Heading } from "@components/Heading"; import { DeleteIcon } from "@components/Icons"; import { EquicordDevs } from "@utils/constants"; import { classNameFactory } from "@utils/css"; @@ -31,8 +31,8 @@ let keywordEntries: Array = []; let keywordLog: Array = []; let interceptor: (e: any) => void; -const recentMentionsPopoutClass = findCssClassesLazy("recentMentionsPopout"); -const tabClass = findCssClassesLazy("inboxTitle", "tab", "expand", "expanded", "controlButton"); +const recentMentionsPopoutClass = findCssClassesLazy("recentMentionsPopout", "scroller"); +const tabClass = findCssClassesLazy("inboxTitle", "tab"); const Popout = findByCodeLazy("getProTip", "canCloseAllMessages:"); const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:"); const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries"; @@ -73,24 +73,24 @@ function highlightKeywords(str: string, entries: Array) { let regexes: Array; try { regexes = entries.map(e => new RegExp(e.regex, "g" + (e.ignoreCase ? "i" : ""))); - } catch { + } catch (err) { return [str]; } - const matches = regexes.map(r => str.match(r)).flat().filter(e => e != null) as Array; + const matches = regexes.map(r => str.match(r)).flat().filter(e => e !== null) as Array; if (matches.length === 0) { return [str]; } const idx = str.indexOf(matches[0]); - return [ + return ( <> {str.substring(0, idx)} {matches[0]} {str.substring(idx + matches[0].length)} - ]; + ); } function Collapsible({ title, children }) { @@ -107,7 +107,7 @@ function Collapsible({ title, children }) { color: "var(--text-muted)", paddingRight: "5px" }}>{isOpen ? "▼" : "▶"} - {title} + {title} {isOpen && children} @@ -127,29 +127,27 @@ function ListedIds({ listIds, setListIds }) { const elements = values.map((currentValue: string, index: number) => { return ( - <> - -
- onChange(e, index)} - /> -
- -
- + +
+ onChange(e, index)} + /> +
+ +
); }); @@ -227,13 +225,13 @@ function KeywordEntries() { { setIgnoreCase(i, !values[i].ignoreCase); }} /> - Whitelist/Blacklist + Whitelist/Blacklist
setListIds(i, e)} /> @@ -372,14 +370,15 @@ export default definePlugin({ interceptor = (e: any) => { return this.modify(e); }; - FluxDispatcher.addInterceptor(interceptor); - }, + FluxDispatcher.subscribe("MESSAGE_CREATE", interceptor); + FluxDispatcher.subscribe("MESSAGE_UPDATE", interceptor); + FluxDispatcher.subscribe("LOAD_MESSAGES_SUCCESS", interceptor); + }, stop() { - const index = FluxDispatcher._interceptors.indexOf(interceptor); - if (index > -1) { - FluxDispatcher._interceptors.splice(index, 1); - } + FluxDispatcher.unsubscribe("MESSAGE_CREATE", interceptor); + FluxDispatcher.unsubscribe("MESSAGE_UPDATE", interceptor); + FluxDispatcher.unsubscribe("LOAD_MESSAGES_SUCCESS", interceptor); }, applyKeywordEntries(m: Message) { @@ -393,7 +392,7 @@ export default definePlugin({ let listed = entry.listIds.some(id => id.trim() === m.channel_id || id === m.author.id); if (!listed) { const channel = ChannelStore.getChannel(m.channel_id); - if (channel != null) { + if (channel !== null) { listed = entry.listIds.some(id => id.trim() === channel.guild_id); } } @@ -419,7 +418,7 @@ export default definePlugin({ if (safeMatchesRegex(embed.description, entry.regex, flags) || safeMatchesRegex(embed.title, entry.regex, flags)) { matches = true; break; - } else if (embed.fields != null) { + } else if (embed.fields !== null) { for (const field of embed.fields as Array<{ name: string, value: string; }>) { if (safeMatchesRegex(field.value, entry.regex, flags) || safeMatchesRegex(field.name, entry.regex, flags)) { matches = true; @@ -459,6 +458,15 @@ export default definePlugin({ DataStore.set(KEYWORD_LOG_KEY, log.map(e => JSON.stringify(e))); }); }, + discardMessage(id: string) { + DataStore.get(KEYWORD_LOG_KEY).then((log: string[]) => { + let parsed_logs: Message[] = log ? log.map(e => JSON.parse(e)) : []; + + parsed_logs = parsed_logs.filter(msg => msg.id !== id); + + DataStore.set(KEYWORD_LOG_KEY, parsed_logs.map(e => JSON.stringify(e))); + }); + }, addToLog(m: Message) { if (m == null || keywordLog.some(e => e.id === m.id)) return; @@ -466,7 +474,7 @@ export default definePlugin({ let messageRecord: any; try { messageRecord = createMessageRecord(m); - } catch { + } catch (err) { return; } @@ -487,7 +495,7 @@ export default definePlugin({ keywordTabBar() { return ( - + Keywords ); @@ -543,12 +551,16 @@ export default definePlugin({ <> null} renderMessage={messageRender} channel={channel} onJump={onJump} onFetch={() => null} - onCloseMessage={this.deleteKeyword} + onCloseMessage={(id: string) => { + this.deleteKeyword(id); + this.discardMessage(id); + }} loadMore={() => null} messages={tempLogs} renderEmptyState={() => null} diff --git a/src/equicordplugins/keywordNotify/style.css b/src/equicordplugins/keywordNotify/style.css index 68727ee4f..07a5f1ae8 100644 --- a/src/equicordplugins/keywordNotify/style.css +++ b/src/equicordplugins/keywordNotify/style.css @@ -15,7 +15,7 @@ cursor: pointer; } -.vc-keywordnotify-switch { +.vc-keywordnotify-ignoreCaseSwitch { margin-top: 0.5em; margin-right: 40px; } \ No newline at end of file