import type { IFileAction } from '@nextcloud/files' import { getSidebar, Permission, registerFileAction } from '@nextcloud/files' import { loadState } from '@nextcloud/initial-state' const COMMENT_ICON = '' type ActionContext = Parameters>[0] function commentsTab(context: ActionContext): 'activity' | 'comments' | undefined { const [node] = context.nodes if (!node) { return undefined } const tabs = getSidebar().getTabs({ node, folder: context.folder, view: context.view, }) const commentsUseActivity = loadState('comments', 'activityEnabled', false) if (commentsUseActivity && tabs.some(({ id }) => id === 'activity')) { return 'activity' } if (tabs.some(({ id }) => id === 'comments')) { return 'comments' } return undefined } export const action: IFileAction = { id: 'korean-comments-action', displayName: () => '댓글', title: () => '댓글', iconSvgInline: () => COMMENT_ICON, enabled(context) { const [node] = context.nodes return context.nodes.length === 1 && node !== undefined && node.root.startsWith('/files/') && node.permissions !== Permission.NONE && getSidebar().available && commentsTab(context) !== undefined }, async exec(context) { const [node] = context.nodes const tabId = commentsTab(context) if (!node || !tabId) { return false } try { const sidebar = getSidebar() if (sidebar.isOpen && sidebar.node?.source === node.source) { sidebar.setActiveTab(tabId) } else { sidebar.open(node, tabId) } return null } catch (error) { console.error('Could not open the comments sidebar', error) return false } }, inline: () => false, order: -45, } registerFileAction(action)