UNPKG

@nextcloud/vue

Version:
1 lines 2.42 kB
{"version":3,"file":"contactsMenu.cjs","sources":["../../src/functions/contactsMenu/index.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport { logger } from '../../utils/logger.ts'\n\n// Taken from \\OC\\Contacts\\ContactsMenu\\Entry::jsonSerialize\nexport interface ContactsMenuEntry {\n\tid: number | string | null\n\tfullName: string\n\tavatar: string | null\n\ttopAction: object | null\n\tactions: object[]\n\tlastMessage: ''\n\temailAddresses: string[]\n\tprofileTitle: string | null\n\tprofileUrl: string | null\n\tstatus: string | null\n\tstatusMessage: null | string\n\tstatusMessageTimestamp: null | number\n\tstatusIcon: null | string\n\tisUser: boolean\n\tuid: null | string\n}\n\nexport interface ContactsMenuAction {\n\tid: string\n\tdisplayName: (entry: ContactsMenuEntry) => string\n\tenabled: (entry: ContactsMenuEntry) => boolean\n\ticonSvg: (entry: ContactsMenuEntry) => string\n\tcallback: (entry: ContactsMenuEntry) => void\n}\n\n/**\n * Register a contacts and avatar menu action that will invoke the given callback on click.\n *\n * @param action The action to register\n */\nexport function registerContactsMenuAction(action: ContactsMenuAction): void {\n\twindow._nc_contacts_menu_hooks ??= {}\n\n\tif (window._nc_contacts_menu_hooks[action.id]) {\n\t\tlogger.error(`ContactsMenu action for id ${action.id} has already been registered`, {\n\t\t\taction,\n\t\t})\n\t\treturn\n\t}\n\n\twindow._nc_contacts_menu_hooks[action.id] = action\n}\n\n/**\n * Get all registered and enabled contacts menu actions for the given menu entry.\n *\n * @param entry The contacts menu entry object as returned by the backend\n */\nexport function getEnabledContactsMenuActions(entry: ContactsMenuEntry): ContactsMenuAction[] {\n\tif (!window._nc_contacts_menu_hooks) {\n\t\treturn []\n\t}\n\n\treturn Object.values(window._nc_contacts_menu_hooks).filter((action) => action.enabled(entry))\n}\n"],"names":["logger"],"mappings":";;;AAuCO,SAAS,2BAA2B,QAAkC;AAC5E,SAAO,4BAA4B,CAAA;AAEnC,MAAI,OAAO,wBAAwB,OAAO,EAAE,GAAG;AAC9CA,WAAAA,OAAO,MAAM,8BAA8B,OAAO,EAAE,gCAAgC;AAAA,MACnF;AAAA,IAAA,CACA;AACD;AAAA,EACD;AAEA,SAAO,wBAAwB,OAAO,EAAE,IAAI;AAC7C;AAOO,SAAS,8BAA8B,OAAgD;AAC7F,MAAI,CAAC,OAAO,yBAAyB;AACpC,WAAO,CAAA;AAAA,EACR;AAEA,SAAO,OAAO,OAAO,OAAO,uBAAuB,EAAE,OAAO,CAAC,WAAW,OAAO,QAAQ,KAAK,CAAC;AAC9F;;;"}