feat(plugin): Read all notifications button (#217)

Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
Kareem Olim 2022-11-19 15:54:48 +02:00 committed by GitHub
parent 8f2c247f27
commit 5ce2dc1bb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 186 additions and 2 deletions

55
src/api/ServerList.ts Normal file
View file

@ -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;
};

View file

@ -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 };