diff options
author | ActuallyTheSun <78964224+ActuallyTheSun@users.noreply.github.com> | 2022-12-15 00:44:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-14 23:44:58 +0100 |
commit | c8f214111434e20a2a1610fdc1d6cc1276dbbce9 (patch) | |
tree | 57afbb96e8b2b5db0f2e15e4f1e3a8afa18f5d48 /src/api/MessageAccessories.ts | |
parent | fea8c60a4091e10123e15b5c403f0e3f4e15c9c8 (diff) | |
download | Vencord-c8f214111434e20a2a1610fdc1d6cc1276dbbce9.tar.gz Vencord-c8f214111434e20a2a1610fdc1d6cc1276dbbce9.tar.bz2 Vencord-c8f214111434e20a2a1610fdc1d6cc1276dbbce9.zip |
feat(plugin): add MessageLinkEmbeds (#264)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/api/MessageAccessories.ts')
-rw-r--r-- | src/api/MessageAccessories.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/api/MessageAccessories.ts b/src/api/MessageAccessories.ts index ee74af5..19026cf 100644 --- a/src/api/MessageAccessories.ts +++ b/src/api/MessageAccessories.ts @@ -16,7 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -export type AccessoryCallback = (props: Record<string, any>) => JSX.Element; +export type AccessoryCallback = (props: Record<string, any>) => JSX.Element | null | Array<JSX.Element | null>; export type Accessory = { callback: AccessoryCallback; position?: number; @@ -44,6 +44,15 @@ export function _modifyAccessories( props: Record<string, any> ) { for (const accessory of accessories.values()) { + let accessories = accessory.callback(props); + if (accessories == null) + continue; + + if (!Array.isArray(accessories)) + accessories = [accessories]; + else if (accessories.length === 0) + continue; + elements.splice( accessory.position != null ? accessory.position < 0 @@ -51,7 +60,7 @@ export function _modifyAccessories( : accessory.position : elements.length, 0, - accessory.callback(props) + ...accessories.filter(e => e != null) as JSX.Element[] ); } |