aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorActuallyTheSun <78964224+ActuallyTheSun@users.noreply.github.com>2022-12-21 21:16:32 +0200
committerGitHub <noreply@github.com>2022-12-21 20:16:32 +0100
commitd806be1346fb8218001eb86ffeaa14099248a3ab (patch)
tree8df0fd147be89daea19c5c6724177b1a1e55a4f1 /src/api
parent1f73cfa91a5a33ad73f3927ec3795a694c26922b (diff)
downloadVencord-d806be1346fb8218001eb86ffeaa14099248a3ab.tar.gz
Vencord-d806be1346fb8218001eb86ffeaa14099248a3ab.tar.bz2
Vencord-d806be1346fb8218001eb86ffeaa14099248a3ab.zip
feat(PlatformIndicators): add indicator to messages (#343)
Diffstat (limited to 'src/api')
-rw-r--r--src/api/Badges.ts17
-rw-r--r--src/api/MemberListDecorators.ts65
-rw-r--r--src/api/MessageDecorations.ts63
-rw-r--r--src/api/index.ts12
4 files changed, 148 insertions, 9 deletions
diff --git a/src/api/Badges.ts b/src/api/Badges.ts
index 55e9b3a..3607f37 100644
--- a/src/api/Badges.ts
+++ b/src/api/Badges.ts
@@ -17,7 +17,7 @@
*/
import { User } from "discord-types/general";
-import { HTMLProps } from "react";
+import { ComponentType, HTMLProps } from "react";
import Plugins from "~plugins";
@@ -27,20 +27,21 @@ export enum BadgePosition {
}
export interface ProfileBadge {
- /** The tooltip to show on hover */
- tooltip: string;
+ /** The tooltip to show on hover. Required for image badges */
+ tooltip?: string;
+ /** Custom component for the badge (tooltip not included) */
+ component?: ComponentType<ProfileBadge & BadgeUserArgs>;
/** The custom image to use */
image?: string;
/** Action to perform when you click the badge */
onClick?(): void;
/** Should the user display this badge? */
shouldShow?(userInfo: BadgeUserArgs): boolean;
- /** Optional props (e.g. style) for the badge */
+ /** Optional props (e.g. style) for the badge, ignored for component badges */
props?: HTMLProps<HTMLImageElement>;
/** Insert at start or end? */
position?: BadgePosition;
-
- /** The badge name to display. Discord uses this, but we don't. */
+ /** The badge name to display, Discord uses this. Required for component badges */
key?: string;
}
@@ -70,8 +71,8 @@ export function inject(badgeArray: ProfileBadge[], args: BadgeUserArgs) {
for (const badge of Badges) {
if (!badge.shouldShow || badge.shouldShow(args)) {
badge.position === BadgePosition.START
- ? badgeArray.unshift(badge)
- : badgeArray.push(badge);
+ ? badgeArray.unshift({ ...badge, ...args })
+ : badgeArray.push({ ...badge, ...args });
}
}
(Plugins.BadgeAPI as any).addDonorBadge(badgeArray, args.user.id);
diff --git a/src/api/MemberListDecorators.ts b/src/api/MemberListDecorators.ts
new file mode 100644
index 0000000..fade2a7
--- /dev/null
+++ b/src/api/MemberListDecorators.ts
@@ -0,0 +1,65 @@
+/*
+ * 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 { Channel, User } from "discord-types/general/index.js";
+
+interface DecoratorProps {
+ activities: any[];
+ canUseAvatarDecorations: boolean;
+ channel: Channel;
+ /**
+ * Only for DM members
+ */
+ channelName?: string;
+ /**
+ * Only for server members
+ */
+ currentUser?: User;
+ guildId?: string;
+ isMobile: boolean;
+ isOwner?: boolean;
+ isTyping: boolean;
+ selected: boolean;
+ status: string;
+ user: User;
+ [key: string]: any;
+}
+export type Decorator = (props: DecoratorProps) => JSX.Element | null;
+type OnlyIn = "guilds" | "dms";
+
+export const decorators = new Map<string, { decorator: Decorator, onlyIn?: OnlyIn; }>();
+
+export function addDecorator(identifier: string, decorator: Decorator, onlyIn?: OnlyIn) {
+ decorators.set(identifier, { decorator, onlyIn });
+}
+
+export function removeDecorator(identifier: string) {
+ decorators.delete(identifier);
+}
+
+export function __addDecoratorsToList(props: DecoratorProps): (JSX.Element | null)[] {
+ const isInGuild = !!(props.guildId);
+ return [...decorators.values()].map(decoratorObj => {
+ const { decorator, onlyIn } = decoratorObj;
+ // this can most likely be done cleaner
+ if (!onlyIn || (onlyIn === "guilds" && isInGuild) || (onlyIn === "dms" && !isInGuild)) {
+ return decorator(props);
+ }
+ return null;
+ });
+}
diff --git a/src/api/MessageDecorations.ts b/src/api/MessageDecorations.ts
new file mode 100644
index 0000000..d212b15
--- /dev/null
+++ b/src/api/MessageDecorations.ts
@@ -0,0 +1,63 @@
+/*
+ * 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 { Channel, Message } from "discord-types/general/index.js";
+
+interface DecorationProps {
+ author: {
+ /**
+ * Will be username if the user has no nickname
+ */
+ nick: string;
+ iconRoleId: string;
+ guildMemberAvatar: string;
+ colorRoleName: string;
+ colorString: string;
+ };
+ channel: Channel;
+ compact: boolean;
+ decorations: {
+ /**
+ * Element for the [BOT] tag if there is one
+ */
+ 0: JSX.Element | null;
+ /**
+ * Other decorations (including ones added with this api)
+ */
+ 1: JSX.Element[];
+ };
+ message: Message;
+ [key: string]: any;
+}
+export type Decoration = (props: DecorationProps) => JSX.Element | null;
+
+export const decorations = new Map<string, Decoration>();
+
+export function addDecoration(identifier: string, decoration: Decoration) {
+ decorations.set(identifier, decoration);
+}
+
+export function removeDecoration(identifier: string) {
+ decorations.delete(identifier);
+}
+
+export function __addDecorationsToMessage(props: DecorationProps): (JSX.Element | null)[] {
+ return [...decorations.values()].map(decoration => {
+ return decoration(props);
+ });
+}
diff --git a/src/api/index.ts b/src/api/index.ts
index b74da6e..7e981e2 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -19,7 +19,9 @@
import * as $Badges from "./Badges";
import * as $Commands from "./Commands";
import * as $DataStore from "./DataStore";
+import * as $MemberListDecorators from "./MemberListDecorators";
import * as $MessageAccessories from "./MessageAccessories";
+import * as $MessageDecorations from "./MessageDecorations";
import * as $MessageEventsAPI from "./MessageEvents";
import * as $MessagePopover from "./MessagePopover";
import * as $Notices from "./Notices";
@@ -72,5 +74,13 @@ const Badges = $Badges;
* An API allowing you to add custom elements to the server list
*/
const ServerList = $ServerList;
+/**
+ * An API allowing you to add components as message accessories
+ */
+const MessageDecorations = $MessageDecorations;
+/**
+ * An API allowing you to add components to member list users, in both DM's and servers
+ */
+const MemberListDecorators = $MemberListDecorators;
-export { Badges, Commands, DataStore, MessageAccessories, MessageEvents, MessagePopover, Notices, ServerList };
+export { Badges, Commands, DataStore, MemberListDecorators, MessageAccessories, MessageDecorations, MessageEvents, MessagePopover, Notices, ServerList };