From 75591329fe0e368d9639fb180e14f38ed9e0c6bf Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Wed, 15 Jun 2022 16:15:22 +0200 Subject: [PATCH] feat: improve message reply --- .../components/chat-message/message-reply.tsx | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/packages/status-react/src/routes/chat/components/chat-message/message-reply.tsx b/packages/status-react/src/routes/chat/components/chat-message/message-reply.tsx index a2b6b18f..5c6bec0c 100644 --- a/packages/status-react/src/routes/chat/components/chat-message/message-reply.tsx +++ b/packages/status-react/src/routes/chat/components/chat-message/message-reply.tsx @@ -1,38 +1,63 @@ import React from 'react' +import { useMatch } from 'react-router-dom' + +import { useProtocol } from '~/src/protocol' import { styled } from '~/src/styles/config' import { Avatar, Box, Flex, Image, Text } from '~/src/system' -import type { Reply } from '~/src/protocol/use-messages' - interface Props { - reply: Reply + messageId: string } export const MessageReply = (props: Props) => { - const { reply } = props + const { messageId } = props - const { contact } = reply + const { client } = useProtocol() + + // TODO: use protocol hook + const { params } = useMatch(':id')! // eslint-disable-line @typescript-eslint/no-non-null-assertion + const message = client.community.getChat(params.id).getMessage(messageId) + + if (!message) { + return ( + + + Message not available. + + + ) + } + + const { contentType, text, sender } = message + const { username } = client.community.getMember(sender) return ( - + - {contact.name} + {username} - {reply.type === 'text' && ( + {contentType === 'TEXT_PLAIN' && ( - {reply.text} + {text} )} - {reply.type === 'image' && ( + {contentType === 'EMOJI' && ( + + + {text} + + + )} + {contentType === 'IMAGE' && ( { /> )} - {reply.type === 'image-text' && ( - - - {reply.text} - - message - - )} ) }