MoreUserTags Chat

This commit is contained in:
thororen1234 2025-05-02 21:00:56 -04:00
parent 61e75e1d89
commit 2613ec170e
No known key found for this signature in database
17 changed files with 668 additions and 228 deletions

40
src/api/NicknameIcons.tsx Normal file
View file

@ -0,0 +1,40 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import ErrorBoundary from "@components/ErrorBoundary";
import { Logger } from "@utils/Logger";
import { ReactNode } from "react";
export interface NicknameIconProps {
userId: string;
}
export type NicknameIconFactory = (props: NicknameIconProps) => ReactNode | Promise<ReactNode>;
export interface NicknameIcon {
priority: number;
factory: NicknameIconFactory;
}
const nicknameIcons = new Map<string, NicknameIcon>();
const logger = new Logger("NicknameIcons");
export function addNicknameIcon(id: string, factory: NicknameIconFactory, priority = 0) {
return nicknameIcons.set(id, {
priority,
factory: ErrorBoundary.wrap(factory, { noop: true, onError: error => logger.error(`Failed to render ${id}`, error) })
});
}
export function removeNicknameIcon(id: string) {
return nicknameIcons.delete(id);
}
export function _renderIcons(props: NicknameIconProps) {
return Array.from(nicknameIcons)
.sort((a, b) => b[1].priority - a[1].priority)
.map(([id, { factory: NicknameIcon }]) => <NicknameIcon key={id} {...props} />);
}

View file

@ -27,6 +27,7 @@ import * as $MessageDecorations from "./MessageDecorations";
import * as $MessageEventsAPI from "./MessageEvents";
import * as $MessagePopover from "./MessagePopover";
import * as $MessageUpdater from "./MessageUpdater";
import * as $NicknameIcons from "./NicknameIcons";
import * as $Notices from "./Notices";
import * as $Notifications from "./Notifications";
import * as $ServerList from "./ServerList";
@ -123,6 +124,11 @@ export const MessageUpdater = $MessageUpdater;
*/
export const UserSettings = $UserSettings;
/**
* An API allowing you to add icons to the nickname, in profiles
*/
export const NicknameIcons = $NicknameIcons;
/**
* Just used to identify if user is on Equicord as Vencord doesnt have this
*/