From 914b3504318c3621e2245c66951ddf973a57058d Mon Sep 17 00:00:00 2001 From: Patrick O'Sullivan Date: Wed, 15 Nov 2023 06:20:02 -0600 Subject: [PATCH] replies: add hide/show to replies, fixes LAND-1194 --- ui/src/replies/ReplyMessage.tsx | 37 +++++++++++++++++-- ui/src/replies/ReplyMessageOptions.tsx | 50 +++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/ui/src/replies/ReplyMessage.tsx b/ui/src/replies/ReplyMessage.tsx index 23b42e036a..e1951acc84 100644 --- a/ui/src/replies/ReplyMessage.tsx +++ b/ui/src/replies/ReplyMessage.tsx @@ -1,5 +1,11 @@ /* eslint-disable react/no-unused-prop-types */ -import React, { useCallback, useEffect, useRef, useState } from 'react'; +import React, { + useCallback, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; import cn from 'classnames'; import debounce from 'lodash/debounce'; import { BigInteger } from 'big-integer'; @@ -14,6 +20,7 @@ import ChatContent from '@/chat/ChatContent/ChatContent'; import DateDivider from '@/chat/ChatMessage/DateDivider'; import { useChatState, + useMessageToggler, useTrackedMessageStatus, // useIsMessageDelivered, // useIsMessagePosted, @@ -24,9 +31,10 @@ import { useIsMobile } from '@/logic/useMedia'; import useLongPress from '@/logic/useLongPress'; import { useMarkReadMutation, + usePostToggler, useTrackedPostStatus, } from '@/state/channel/channel'; -import { emptyReply, Reply } from '@/types/channel'; +import { emptyReply, Reply, Story } from '@/types/channel'; import { useIsDmOrMultiDm } from '@/logic/utils'; import { useChatDialog, @@ -68,6 +76,17 @@ const mergeRefs = }); }; +const hiddenMessage: Story = [ + { + inline: [ + { + italics: [ + 'You have hidden this message. You can unhide it from the options menu.', + ], + }, + ], + }, +]; const ReplyMessage = React.memo< ReplyMessageProps & React.RefAttributes >( @@ -99,6 +118,12 @@ const ReplyMessage = React.memo< const { open: pickerOpen } = useChatDialog(whom, seal.id, 'picker'); const isDMOrMultiDM = useIsDmOrMultiDm(whom); const { mutate: markChatRead } = useMarkReadMutation(); + const { isHidden: isMessageHidden } = useMessageToggler(seal.id); + const { isHidden: isPostHidden } = usePostToggler(seal.id); + const isHidden = useMemo( + () => isMessageHidden || isPostHidden, + [isMessageHidden, isPostHidden] + ); const { ref: viewRef } = useInView({ threshold: 1, onChange: useCallback( @@ -282,7 +307,13 @@ const ReplyMessage = React.memo< isLinked && 'bg-blue-softer' )} > - {memo.content ? ( + {isHidden ? ( + + ) : memo.content ? ( isMessageHidden || isPostHidden, + [isMessageHidden, isPostHidden] + ); const onDelete = async () => { if (isMobile) { @@ -188,6 +206,16 @@ export default function ReplyMessageOptions(props: { } }, [isMobile, loadEmoji]); + const toggleMsg = useCallback( + () => (isMessageHidden ? showChatMessage() : hideChatMessage()), + [isMessageHidden, showChatMessage, hideChatMessage] + ); + + const togglePost = useCallback( + () => (isPostHidden ? showPost() : hidePost()), + [isPostHidden, showPost, hidePost] + ); + const showReactAction = canWrite; // TODO handle reply replies const showCopyAction = !!groupFlag; @@ -258,6 +286,26 @@ export default function ReplyMessageOptions(props: { }); } + actions.push({ + key: 'hide', + onClick: isDMorMultiDM ? toggleMsg : togglePost, + content: ( +
+ {isHidden ? ( + <> + + Show Message + + ) : ( + <> + + Hide Message + + )} +
+ ), + }); + if (showDeleteAction) { actions.push({ key: 'delete',