import { Archive, Bell, BellOff, Check, CheckCircle2, CircleDot, Copy, LogOut, LoaderCircle, Plus, Star, StarOff, Trash2, TriangleAlert, } from "lucide-react"; import { useArchiveChannelMutation, useChannelMembersQuery, } from "@/features/channels/hooks"; import { useChannelModerationCapabilities } from "@/features/channels/ui/ChannelManagementModerationActions"; import type { ChannelSection } from "@/features/sidebar/lib/useChannelSections"; import { ContextMenuIconSlot, deferMenuAction, } from "@/features/sidebar/ui/sidebarMenuHelpers"; import { StatusEmoji } from "@/features/user-status/ui/StatusEmoji"; import type { Channel } from "@/shared/api/types"; import { useIdentityQuery } from "@/shared/api/hooks"; import { copyTextToClipboard } from "@/shared/lib/clipboard"; import { ContextMenuItem, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, } from "@/shared/ui/context-menu"; function MoveToSectionSubmenu({ channelId, sections, assignments, onAssignChannel, onUnassignChannel, onCreateSectionForChannel, }: { channelId: string; sections: ChannelSection[]; assignments: Record; onAssignChannel: (channelId: string, sectionId: string) => void; onUnassignChannel: (channelId: string) => void; onCreateSectionForChannel: (channelId: string) => void; }) { const currentSectionId = assignments[channelId]; return ( Move to section {sections.map((section) => ( deferMenuAction(() => onAssignChannel(channelId, section.id)) } > {currentSectionId === section.id ? ( ) : section.icon ? ( ) : null} {section.name} ))} {sections.length > 0 ? : null} deferMenuAction(() => onCreateSectionForChannel(channelId)) } > New section... {currentSectionId ? ( deferMenuAction(() => onUnassignChannel(channelId))} > Remove from section ) : null} ); } /** * The channel/DM context menu's Copy actions, grouped under a single * "Copy" submenu (channel name / channel ID). */ function CopyChannelSubmenu({ channel }: { channel: Channel }) { return ( Copy copyTextToClipboard( channel.name, "Channel name copied to clipboard", ) } > Copy channel name copyTextToClipboard(channel.id, "Channel ID copied to clipboard") } > Copy channel ID ); } export function ChannelContextMenuItems({ channel, hasUnread, isMuted, isStarred, sections, assignments, onMarkChannelRead, onMarkChannelUnread, onMuteChannel, onUnmuteChannel, onStarChannel, onUnstarChannel, onAssignChannel, onUnassignChannel, onCreateSectionForChannel, onDeleteChannel, onLeaveChannel, }: { channel: Channel; hasUnread: boolean; isMuted?: boolean; isStarred?: boolean; sections?: ChannelSection[]; assignments?: Record; onMarkChannelRead?: ( channelId: string, lastMessageAt: string | null | undefined, ) => void; onMarkChannelUnread?: (channelId: string) => void; onMuteChannel?: (channelId: string) => void; onUnmuteChannel?: (channelId: string) => void; onStarChannel?: (channelId: string) => void; onUnstarChannel?: (channelId: string) => void; onAssignChannel?: (channelId: string, sectionId: string) => void; onUnassignChannel?: (channelId: string) => void; onCreateSectionForChannel?: (channelId: string) => void; onDeleteChannel?: (channel: Channel) => void; onLeaveChannel?: (channel: Channel) => void; }) { const canLoadOwnerActions = channel.channelType !== "dm" && Boolean(onDeleteChannel); const membersQuery = useChannelMembersQuery(channel.id, canLoadOwnerActions); const currentPubkey = useIdentityQuery().data?.pubkey; const archiveChannel = useArchiveChannelMutation(channel.id); const { canDeleteChannel, canManageChannel, error: capabilityError, isLoading: isCapabilityLoading, } = useChannelModerationCapabilities( membersQuery.data, currentPubkey, canLoadOwnerActions, ); const ownerActionsError = membersQuery.error ?? capabilityError; const ownerActionsLoading = canLoadOwnerActions && (membersQuery.isLoading || isCapabilityLoading); const showChannelActions = Boolean( onLeaveChannel || ownerActionsLoading || ownerActionsError || canManageChannel || canDeleteChannel, ); const showStar = Boolean(onStarChannel && onUnstarChannel); const showReadToggle = hasUnread ? Boolean(onMarkChannelRead) : Boolean(onMarkChannelUnread); const showMuteToggle = Boolean(onMuteChannel && onUnmuteChannel); const showMove = Boolean( sections && assignments && onAssignChannel && onUnassignChannel && onCreateSectionForChannel, ); return ( <> {showMove ? ( {})} onUnassignChannel={onUnassignChannel ?? (() => {})} onCreateSectionForChannel={onCreateSectionForChannel ?? (() => {})} /> ) : null} {showReadToggle ? : null} {hasUnread && onMarkChannelRead ? ( deferMenuAction(() => onMarkChannelRead(channel.id, channel.lastMessageAt), ) } > Mark as read ) : !hasUnread && onMarkChannelUnread ? ( deferMenuAction(() => onMarkChannelUnread(channel.id)) } > Mark unread ) : null} {showMuteToggle || showStar ? : null} {showMuteToggle ? ( isMuted ? ( deferMenuAction(() => onUnmuteChannel?.(channel.id)) } > Unmute channel ) : ( deferMenuAction(() => onMuteChannel?.(channel.id))} > Mute channel ) ) : null} {showStar ? ( isStarred ? ( deferMenuAction(() => onUnstarChannel?.(channel.id)) } > Unstar channel ) : ( deferMenuAction(() => onStarChannel?.(channel.id))} > Star channel ) ) : null} {showChannelActions ? : null} {onLeaveChannel ? ( deferMenuAction(() => onLeaveChannel(channel))} > Leave channel ) : null} {ownerActionsLoading ? ( Loading channel actions... ) : ownerActionsError ? ( Channel actions unavailable ) : null} {canManageChannel ? ( deferMenuAction(() => archiveChannel.mutate())} > Archive channel ) : null} {canDeleteChannel ? ( deferMenuAction(() => onDeleteChannel?.(channel))} > Delete channel ) : null} ); }