From c8f214111434e20a2a1610fdc1d6cc1276dbbce9 Mon Sep 17 00:00:00 2001 From: ActuallyTheSun <78964224+ActuallyTheSun@users.noreply.github.com> Date: Thu, 15 Dec 2022 00:44:58 +0200 Subject: feat(plugin): add MessageLinkEmbeds (#264) Co-authored-by: Ven --- src/api/MessageAccessories.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/api/MessageAccessories.ts') 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 . */ -export type AccessoryCallback = (props: Record) => JSX.Element; +export type AccessoryCallback = (props: Record) => JSX.Element | null | Array; export type Accessory = { callback: AccessoryCallback; position?: number; @@ -44,6 +44,15 @@ export function _modifyAccessories( props: Record ) { 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[] ); } -- cgit