diff options
author | Kareem Olim <kareemolim@gmail.com> | 2022-11-19 15:54:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-19 14:54:48 +0100 |
commit | 5ce2dc1bb4ee93f7e5121f684f957eb99ead22b8 (patch) | |
tree | 657d497442011f600ce1d67f9fad2442bb213832 /src/api | |
parent | 8f2c247f27ad097352904de2bd1035b270315375 (diff) | |
download | Vencord-5ce2dc1bb4ee93f7e5121f684f957eb99ead22b8.tar.gz Vencord-5ce2dc1bb4ee93f7e5121f684f957eb99ead22b8.tar.bz2 Vencord-5ce2dc1bb4ee93f7e5121f684f957eb99ead22b8.zip |
feat(plugin): Read all notifications button (#217)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/ServerList.ts | 55 | ||||
-rw-r--r-- | src/api/index.ts | 7 |
2 files changed, 61 insertions, 1 deletions
diff --git a/src/api/ServerList.ts b/src/api/ServerList.ts new file mode 100644 index 0000000..d3a9a11 --- /dev/null +++ b/src/api/ServerList.ts @@ -0,0 +1,55 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 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 Logger from "../utils/Logger"; + +const logger = new Logger("ServerListAPI"); + +export enum ServerListRenderPosition { + Above, + In, +} + +const renderFunctionsAbove = new Set<Function>(); +const renderFunctionsIn = new Set<Function>(); + +function getRenderFunctions(position: ServerListRenderPosition) { + return position === ServerListRenderPosition.Above ? renderFunctionsAbove : renderFunctionsIn; +} + +export function addServerListElement(position: ServerListRenderPosition, renderFunction: Function) { + getRenderFunctions(position).add(renderFunction); +} + +export function removeServerListElement(position: ServerListRenderPosition, renderFunction: Function) { + getRenderFunctions(position).delete(renderFunction); +} + +export const renderAll = (position: ServerListRenderPosition) => { + const ret: Array<JSX.Element> = []; + + for (const renderFunction of getRenderFunctions(position)) { + try { + ret.unshift(renderFunction()); + } catch (e) { + logger.error("Failed to render server list element:", e); + } + } + + return ret; +}; diff --git a/src/api/index.ts b/src/api/index.ts index bde4b3e..98fc6a4 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -22,6 +22,7 @@ import * as $DataStore from "./DataStore"; import * as $MessageAccessories from "./MessageAccessories"; import * as $MessageEventsAPI from "./MessageEvents"; import * as $Notices from "./Notices"; +import * as $ServerList from "./ServerList"; /** * An API allowing you to listen to Message Clicks or run your own logic @@ -62,5 +63,9 @@ const MessageAccessories = $MessageAccessories; * An API allowing you to add badges to user profiles */ const Badges = $Badges; +/** + * An API allowing you to add custom elements to the server list + */ +const ServerList = $ServerList; -export { Badges, Commands, DataStore, MessageAccessories, MessageEvents, Notices }; +export { Badges, Commands, DataStore, MessageAccessories, MessageEvents, Notices, ServerList }; |