From a31610742c76864e36977e5cf8c9459f4e8fef83 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 20 Jul 2020 13:34:20 -0400 Subject: [PATCH] fix: code review --- src/signals/messages.nim | 2 +- ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 3 ++- .../MessageComponents/ChatReply.qml | 2 +- .../ChatColumn/MessageComponents/ChatTime.qml | 2 +- .../MessageComponents/CompactMessage.qml | 14 +++++++++--- .../MessageComponents/NormalMessage.qml | 22 +++++++++++++------ .../MessageComponents/SentMessage.qml | 2 +- .../MessageComponents/UserImage.qml | 2 +- .../MessageComponents/UsernameLabel.qml | 2 +- 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/signals/messages.nim b/src/signals/messages.nim index ec4574f957..b7f54607e1 100644 --- a/src/signals/messages.nim +++ b/src/signals/messages.nim @@ -5,7 +5,7 @@ import ../status/libstatus/settings as status_settings import ../status/libstatus/types as status_types import ../status/chat/[chat, message] import ../status/profile/[profile, devices] -import types +import types proc toMessage*(jsonMsg: JsonNode): Message diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index 57b0741a9d..fd1a2514ee 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -26,9 +26,10 @@ Item { property bool isEmoji: contentType === Constants.emojiType property bool isImage: contentType === Constants.imageType - property bool isMessage: contentType === Constants.messageType || contentType === Constants.stickerType property bool isStatusMessage: contentType === Constants.systemMessagePrivateGroupType property bool isSticker: contentType === Constants.stickerType + property bool isText: contentType === Constants.messageType + property bool isMessage: isEmoji || isImage || isSticker || isText property bool isExpired: (outgoingStatus == "sending" && (Math.floor(timestamp) + 180000) < Date.now()) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml index d981c6d905..a256710bf8 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml @@ -10,7 +10,7 @@ Rectangle { color: Style.current.lightBlue visible: responseTo != "" && replyMessageIndex > -1 // childrenRect.height shows a binding loop for soem reason, so we use heights instead - height: this.visible ? lblReplyAuthor.height + ((repliedMessageType == Constants.imageType ? imgReplyImage.height : lblReplyMessage.height) + 5 + 8) : 0 + height: this.visible ? lblReplyAuthor.height + ((repliedMessageType === Constants.imageType ? imgReplyImage.height : lblReplyMessage.height) + 5 + 8) : 0 StyledTextEdit { id: lblReplyAuthor diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml index 948842304f..fc205af4b4 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatTime.qml @@ -4,7 +4,7 @@ import "../../../../../imports" StyledTextEdit { id: chatTime - visible: (isEmoji || isMessage || isSticker || isImage) + visible: isMessage color: Style.current.darkGrey text: { let messageDate = new Date(Math.floor(timestamp)) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml index 3afcf82973..120e71668e 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/CompactMessage.qml @@ -57,13 +57,21 @@ Item { anchors.rightMargin: chatTextItem.chatHorizontalPadding } - ChatImage { + Loader { id: chatImageContent - imageWidth: 200 - imageSource: image + active: isImage + sourceComponent: chatImageComponent anchors.left: chatImage.right } + Component { + id: chatImageComponent + ChatImage { + imageSource: image + imageWidth: 200 + } + } + Rectangle { id: stickerContainer visible: contentType === Constants.stickerType diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/NormalMessage.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/NormalMessage.qml index 365835b543..98b6b30eb6 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/NormalMessage.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/NormalMessage.qml @@ -18,7 +18,7 @@ Item { UserImage { id: chatImage - visible: (isMessage || isEmoji || isImage) && authorCurrentMsg != authorPrevMsg && !isCurrentUser + visible: isMessage && authorCurrentMsg != authorPrevMsg && !isCurrentUser anchors.left: parent.left anchors.leftMargin: Style.current.padding anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top @@ -27,7 +27,7 @@ Item { UsernameLabel { id: chatName - visible: (isMessage || isEmoji || isImage) && authorCurrentMsg != authorPrevMsg && !isCurrentUser + visible: isMessage && authorCurrentMsg != authorPrevMsg && !isCurrentUser text: userName anchors.leftMargin: 20 anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top @@ -83,7 +83,7 @@ Item { anchors.rightMargin: !isCurrentUser ? 0 : Style.current.padding anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : (dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top) anchors.topMargin: 0 - visible: isMessage || isEmoji || isImage + visible: isMessage ChatReply { id: chatReply @@ -110,12 +110,20 @@ Item { color: !isCurrentUser ? Style.current.textColor : Style.current.currentUserTextColor } - ChatImage { + Loader { id: chatImageContent - imageWidth: 250 - imageSource: image + active: isImage + sourceComponent: chatImageComponent } + Component { + id: chatImageComponent + ChatImage { + imageSource: image + imageWidth: 250 + } + } + Sticker { id: stickerId anchors.left: parent.left @@ -130,7 +138,7 @@ Item { RectangleCorner { // TODO find a way to show the corner for stickers since they have a border - visible: isMessage || isEmoji + visible: isMessage } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/SentMessage.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/SentMessage.qml index c8ce7c04f6..74f300e5c8 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/SentMessage.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/SentMessage.qml @@ -4,7 +4,7 @@ import "../../../../../imports" StyledText { id: sentMessage - visible: isCurrentUser && !timeout && (isEmoji || isMessage || isSticker || isImage) + visible: isCurrentUser && !timeout && isMessage color: Style.current.darkGrey text: outgoingStatus == "sent" ? //% "Sent" diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UserImage.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UserImage.qml index d8243c29a0..24bb782fd2 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UserImage.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UserImage.qml @@ -4,7 +4,7 @@ import "../../../../../imports" Rectangle { id: chatImage - visible: (isMessage || isEmoji) && authorCurrentMsg != authorPrevMsg + visible: isMessage && authorCurrentMsg != authorPrevMsg width: identiconImage.width height: identiconImage.height border.width: 1 diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UsernameLabel.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UsernameLabel.qml index ec208b1ec9..8b11ee098c 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UsernameLabel.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/UsernameLabel.qml @@ -4,7 +4,7 @@ import "../../../../../imports" StyledTextEdit { id: chatName - visible: (isMessage || isEmoji) && authorCurrentMsg != authorPrevMsg + visible: isMessage && authorCurrentMsg != authorPrevMsg height: this.visible ? 18 : 0 //% "You" text: !isCurrentUser ? userName : qsTrId("You")