diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index 918c7bab..50e8ca17 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -321,7 +321,7 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi const handleUserClick = useUserClickHandler(); const handleUsernameClick = useUsernameClickHandler(editor); - const [replyDraft, handleReplyClick] = useReplyClickHandler(timeline, editor); + const [replyDraft, handleReplyClick] = useReplyClickHandler(editor); const handleReactionToggle = useCallback((targetEventId: string) => { console.log(targetEventId); @@ -421,6 +421,7 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi canDelete={canRedact || (canDeleteOwn && event.sender === ct.session.userId)} canSendReaction={canSendReaction} canPinEvent={canPinEvent} + canThread imagePackRooms={imagePackRooms} reactionEvents={reactionEvents && reactionEvents.length > 0 ? reactionEvents : undefined} onUserClick={handleUserClick} diff --git a/src/app/features/room/hooks/useTimeline.ts b/src/app/features/room/hooks/useTimeline.ts index 20b75011..26ad81ab 100644 --- a/src/app/features/room/hooks/useTimeline.ts +++ b/src/app/features/room/hooks/useTimeline.ts @@ -201,7 +201,6 @@ export const useAtBottomToggle = ( }; export const useReplyClickHandler = ( - timeline: TimelineView, editor: Editor, threadId?: string ): [ReplyDraft | undefined, MouseEventHandler] => { @@ -213,12 +212,11 @@ export const useReplyClickHandler = ( const handleReplyClick: MouseEventHandler = useCallback( (evt) => { const replyId = evt.currentTarget.getAttribute('data-event-id'); - if (!replyId) { - console.warn('Button should have "data-event-id" attribute!'); + const senderId = evt.currentTarget.getAttribute('data-sender-id'); + if (!replyId || !senderId) { + console.warn('Button should have "data-event-id" or "data-sender-id" attribute!'); return; } - const senderId = timeline.batch.read.messages.get(replyId)?.sender; - if (!senderId) return; if (senderId) { setReplyDraft({ @@ -228,7 +226,7 @@ export const useReplyClickHandler = ( setTimeout(() => ReactEditor.focus(editor), 100); } }, - [setReplyDraft, editor, timeline] + [setReplyDraft, editor] ); return [replyDraft, handleReplyClick]; diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index 8a4402a0..9a95fe23 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -52,13 +52,7 @@ import { Username, UsernameBold, } from '../../../components/message'; -import { - canEditEvent, - fallbackReply, - getReactionGroups, - getReplyId, - getThreadId, -} from '../../../utils/room'; +import { canEditEvent, fallbackReply, getReactionGroups, getReplyId } from '../../../utils/room'; import { MessageLayout, MessageSpacing } from '../../../state/settings'; import { useRecentEmoji } from '../../../hooks/useRecentEmoji'; import * as css from './styles.css'; @@ -835,6 +829,7 @@ export type MessageProps = { canDelete?: boolean; canSendReaction?: boolean; canPinEvent?: boolean; + canThread?: boolean; imagePackRooms?: string[]; reactionEvents?: MessageEventWithoutRoomId[]; messageLayout: MessageLayout; @@ -868,6 +863,7 @@ export const Message = as<'div', MessageProps>( canDelete, canSendReaction, canPinEvent, + canThread, imagePackRooms, reactionEvents, messageLayout, @@ -1022,13 +1018,14 @@ export const Message = as<'div', MessageProps>( - {!getThreadId(event) && ( + {canThread && ( ( after={} radii="300" data-event-id={event.event_id} + data-sender-id={event.sender} onClick={(evt: any) => { onReplyClick(evt); closeMenu(); @@ -1117,7 +1115,7 @@ export const Message = as<'div', MessageProps>( Quote - {!getThreadId(event) && ( + {canThread && ( } diff --git a/src/app/features/room/thread-view/TimelineView.tsx b/src/app/features/room/thread-view/TimelineView.tsx index babf5751..d3f11f5f 100644 --- a/src/app/features/room/thread-view/TimelineView.tsx +++ b/src/app/features/room/thread-view/TimelineView.tsx @@ -302,11 +302,7 @@ export function TimelineView({ threadTimeline }: TimelineViewProps) { const handleUserClick = useUserClickHandler(); const handleUsernameClick = useUsernameClickHandler(editor); - const [replyDraft, handleReplyClick] = useReplyClickHandler( - threadTimeline, - editor, - threadTimeline.threadId - ); + const [replyDraft, handleReplyClick] = useReplyClickHandler(editor, threadTimeline.threadId); const handleReactionToggle = useCallback((targetEventId: string) => { console.log(targetEventId);