From 3939e278271618556110a5c69108d6c17aef4260 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 30 Aug 2022 10:42:55 -0400 Subject: [PATCH] Add ability to copy the message --- .../chats/components/chat-message-list.tsx | 52 ++++++++++++------- app/soapbox/locales/ar.json | 2 +- app/soapbox/locales/ast.json | 2 +- app/soapbox/locales/bg.json | 2 +- app/soapbox/locales/bn.json | 2 +- app/soapbox/locales/br.json | 2 +- app/soapbox/locales/co.json | 2 +- app/soapbox/locales/cy.json | 2 +- app/soapbox/locales/da.json | 2 +- app/soapbox/locales/el.json | 2 +- app/soapbox/locales/en.json | 2 +- app/soapbox/locales/eo.json | 2 +- app/soapbox/locales/es-AR.json | 2 +- app/soapbox/locales/es.json | 2 +- app/soapbox/locales/et.json | 2 +- app/soapbox/locales/eu.json | 2 +- app/soapbox/locales/fa.json | 2 +- app/soapbox/locales/fi.json | 2 +- app/soapbox/locales/fr.json | 2 +- app/soapbox/locales/ga.json | 2 +- app/soapbox/locales/gl.json | 2 +- app/soapbox/locales/hi.json | 2 +- app/soapbox/locales/hr.json | 2 +- app/soapbox/locales/hu.json | 2 +- app/soapbox/locales/hy.json | 2 +- app/soapbox/locales/id.json | 2 +- app/soapbox/locales/io.json | 2 +- app/soapbox/locales/ka.json | 2 +- app/soapbox/locales/kk.json | 2 +- app/soapbox/locales/ko.json | 2 +- app/soapbox/locales/lt.json | 2 +- app/soapbox/locales/lv.json | 2 +- app/soapbox/locales/mk.json | 2 +- app/soapbox/locales/ms.json | 2 +- app/soapbox/locales/nl.json | 2 +- app/soapbox/locales/nn.json | 2 +- app/soapbox/locales/no.json | 2 +- app/soapbox/locales/oc.json | 2 +- app/soapbox/locales/pt-BR.json | 2 +- app/soapbox/locales/ro.json | 2 +- app/soapbox/locales/sk.json | 2 +- app/soapbox/locales/sl.json | 2 +- app/soapbox/locales/sq.json | 2 +- app/soapbox/locales/sr-Latn.json | 2 +- app/soapbox/locales/sr.json | 2 +- app/soapbox/locales/sv.json | 2 +- app/soapbox/locales/ta.json | 2 +- app/soapbox/locales/te.json | 2 +- app/soapbox/locales/th.json | 2 +- app/soapbox/locales/tr.json | 2 +- app/soapbox/locales/uk.json | 2 +- app/soapbox/locales/zh-HK.json | 2 +- app/soapbox/locales/zh-TW.json | 2 +- 53 files changed, 84 insertions(+), 72 deletions(-) diff --git a/app/soapbox/features/chats/components/chat-message-list.tsx b/app/soapbox/features/chats/components/chat-message-list.tsx index 36ddc799f..2369d1252 100644 --- a/app/soapbox/features/chats/components/chat-message-list.tsx +++ b/app/soapbox/features/chats/components/chat-message-list.tsx @@ -29,8 +29,8 @@ const BIG_EMOJI_LIMIT = 1; const messages = defineMessages({ today: { id: 'chats.dividers.today', defaultMessage: 'Today' }, more: { id: 'chats.actions.more', defaultMessage: 'More' }, - delete: { id: 'chats.actions.delete', defaultMessage: 'Delete message' }, - report: { id: 'chats.actions.report', defaultMessage: 'Report user' }, + delete: { id: 'chats.actions.delete', defaultMessage: 'Delete' }, + copy: { id: 'chats.actions.copy', defaultMessage: 'Copy' }, }); type TimeFormat = 'today' | 'date'; @@ -203,29 +203,31 @@ const ChatMessageList: React.FC = ({ chat, autosize }) => { const renderDivider = (key: React.Key, text: string) => ; - const handleReportUser = (userId: string) => { - return () => { - dispatch(initReportById(userId)); - }; + const handleCopyText = (chatMessage: IChatMessage) => { + if (navigator.clipboard) { + navigator.clipboard.writeText(chatMessage.content); + } }; const renderMessage = (chatMessage: any) => { const isMyMessage = chatMessage.account_id === me; - const menu: Menu = [ - { + const menu: Menu = []; + + if (navigator.clipboard) { + menu.push({ + text: intl.formatMessage(messages.copy), + action: () => handleCopyText(chatMessage), + icon: require('@tabler/icons/copy.svg'), + }); + } + + if (isMyMessage) { + menu.push({ text: intl.formatMessage(messages.delete), action: () => handleDeleteMessage.mutate(chatMessage.id), icon: require('@tabler/icons/trash.svg'), destructive: true, - }, - ]; - - if (chatMessage.account_id !== me) { - menu.push({ - text: intl.formatMessage(messages.report), - action: handleReportUser(chatMessage.account_id), - icon: require('@tabler/icons/flag.svg'), }); } @@ -244,19 +246,29 @@ const ChatMessageList: React.FC = ({ chat, autosize }) => { 'opacity-50': chatMessage.pending, })} > - {isMyMessage ? ( -
+ {menu.length > 0 && ( +
- ) : null} + )}