1+ import { useRoom } from '@ably/chat/react' ;
12import React from 'react' ;
23
4+ import { useChatSettings } from '../../hooks/use-chat-settings.tsx' ;
35import { Button } from '../atoms/button.tsx' ;
46import { Icon } from '../atoms/icon.tsx' ;
57
@@ -27,8 +29,8 @@ export interface MessageActionsProps {
2729 * Callback function triggered when the edit button is clicked.
2830 * Should initiate edit mode for the message, typically replacing the message
2931 * content with an editable input field or editor component.
30- * Only displayed when isOwn is true.
31- *
32+ * Displayed when:
33+ * - The message is owned by the current user and allowMessageUpdatesOwn is true, or allowMessageUpdatesAny is true
3234 *
3335 * @example
3436 * ```tsx
@@ -44,8 +46,8 @@ export interface MessageActionsProps {
4446 /**
4547 * Callback function triggered when the delete button is clicked.
4648 * Should handle message deletion, typically with confirmation dialog.
47- * Only displayed when isOwn is true.
48- *
49+ * Displayed when:
50+ * - The message is owned by the current user and allowMessageDeletesOwn is true, or allowMessageDeletesAny is true
4951 *
5052 * @example
5153 * ```tsx
@@ -59,17 +61,12 @@ export interface MessageActionsProps {
5961
6062 /**
6163 * Whether the message belongs to the current user.
62- * Determines if edit and delete buttons are shown.
63- * When false, only the reaction button is displayed.
64- *
65- * - Own messages: Show all actions (reaction, edit, delete)
66- * - Other messages: Show only reaction button
64+ * Used in combination with chat settings to determine if edit and delete buttons are shown.
6765 *
6866 * @example
6967 * ```tsx
7068 * // Basic ownership check
7169 * isOwn={message.senderId === currentUser.id}
72- *
7370 * ```
7471 */
7572 isOwn : boolean ;
@@ -116,10 +113,35 @@ export const MessageActions = ({
116113 onDeleteButtonClicked,
117114 isOwn,
118115} : MessageActionsProps ) => {
119- // Check if there are any actions to display
120- const hasReactionAction = onReactionButtonClicked !== undefined ;
121- const hasEditAction = isOwn && onEditButtonClicked !== undefined ;
122- const hasDeleteAction = isOwn && onDeleteButtonClicked !== undefined ;
116+ // Get the current room name
117+ const { roomName } = useRoom ( ) ;
118+
119+ // Get chat settings for the current room
120+ const { getEffectiveSettings } = useChatSettings ( ) ;
121+ const settings = getEffectiveSettings ( roomName ) ;
122+
123+ const {
124+ allowMessageUpdatesOwn,
125+ allowMessageUpdatesAny,
126+ allowMessageDeletesOwn,
127+ allowMessageDeletesAny,
128+ allowMessageReactions,
129+ } = settings ;
130+
131+ // Check if there are any actions to display based on settings and permissions
132+ const hasReactionAction = allowMessageReactions && onReactionButtonClicked !== undefined ;
133+
134+ // Can edit if:
135+ // - User owns the message AND can edit own messages, OR
136+ // - User can edit any message
137+ const canEdit = ( isOwn && allowMessageUpdatesOwn ) || allowMessageUpdatesAny ;
138+ const hasEditAction = canEdit && onEditButtonClicked !== undefined ;
139+
140+ // Can delete if:
141+ // - User owns the message AND can delete own messages, OR
142+ // - User can delete any message
143+ const canDelete = ( isOwn && allowMessageDeletesOwn ) || allowMessageDeletesAny ;
144+ const hasDeleteAction = canDelete && onDeleteButtonClicked !== undefined ;
123145
124146 // If no actions are available, don't render anything
125147 if ( ! hasReactionAction && ! hasEditAction && ! hasDeleteAction ) {
@@ -128,7 +150,7 @@ export const MessageActions = ({
128150
129151 return (
130152 < div
131- className = "absolute -top-10 right-0 z-10 flex items-center gap-1 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-md p-1"
153+ className = "absolute -top-9 right-0 z-10 flex items-center gap-1 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-md p-1"
132154 role = "toolbar"
133155 aria-label = "Message actions"
134156 >
0 commit comments