From a342192f43d8d4674aad05f69e49bbfe13532ee5 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 10 Jul 2020 18:22:39 -0400 Subject: [PATCH] fix: code review --- src/app/chat/view.nim | 26 ++++--------------- src/app/chat/views/message_format.nim | 4 +-- src/app/chat/views/message_list.nim | 5 ++-- ui/app/AppLayouts/Chat/ChatColumn.qml | 19 +++++--------- .../Chat/ChatColumn/ChatButtons.qml | 2 +- .../AppLayouts/Chat/ChatColumn/ChatInput.qml | 2 +- .../Chat/ChatColumn/ChatMessages.qml | 6 ----- ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 26 +++++++++++-------- .../AppLayouts/Chat/ChatColumn/ReplyArea.qml | 24 ++++++++++++++--- .../Chat/ContactsColumn/ChannelList.qml | 2 ++ ui/imports/SelectedMessage.qml | 18 +++++++++++++ ui/imports/qmldir | 1 + 12 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 ui/imports/SelectedMessage.qml diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 64a9fba05f..2c1c354b3d 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -76,23 +76,8 @@ QtObject: proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} = self.chats.getChannelColor(channel) - proc replyAreaEnabled*(self: ChatsView, enable: bool, userName: string, message: string, identicon: string) {.signal.} - - proc setReplyTo(self: ChatsView, messageId: string) {.slot.} = - self.replyTo = messageId - - proc enableReplyArea*(self: ChatsView, enable: bool, userName: string = "", message: string = "", identicon: string = "") {.slot.} = - if not enable: - self.replyTo = "" - self.replyAreaEnabled(enable, username, message, identicon) - - proc disableReplyArea(self: ChatsView) = - self.replyTo = "" - self.replyAreaEnabled(false, "", "", "") - - proc sendMessage*(self: ChatsView, message: string, isReply: bool) {.slot.} = - self.status.chat.sendMessage(self.activeChannel.id, message, if isReply: self.replyTo else: "") - self.disableReplyArea() + proc sendMessage*(self: ChatsView, message: string, replyTo: string) {.slot.} = + self.status.chat.sendMessage(self.activeChannel.id, message, replyTo) proc activeChannelChanged*(self: ChatsView) {.signal.} @@ -105,7 +90,6 @@ QtObject: if self.activeChannel.id == selectedChannel.id: return self.activeChannel.setChatItem(selectedChannel) self.status.chat.setActiveChannel(selectedChannel.id) - self.disableReplyArea() self.activeChannelChanged() proc getActiveChannelIdx(self: ChatsView): QVariant {.slot.} = @@ -135,7 +119,6 @@ QtObject: proc setActiveChannel*(self: ChatsView, channel: string) = if(channel == ""): return self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel))) - self.disableReplyArea() self.activeChannelChanged() proc getActiveChannel*(self: ChatsView): QVariant {.slot.} = @@ -150,8 +133,9 @@ QtObject: if not self.messageList.hasKey(channel): self.messageList[channel] = newChatMessageList(channel, self.status) # If there is only one channel, set is as active - if (self.activeChannel.chatItem == nil and self.chats.rowCount() == 1): - self.setActiveChannelByIndex(0) + # if (self.activeChannel.chatItem == nil and self.chats.rowCount() == 1): + # self.setActiveChannelByIndex(0) + # RRAMOS: commented because it was hanging the app on login proc messagePushed*(self: ChatsView) {.signal.} diff --git a/src/app/chat/views/message_format.nim b/src/app/chat/views/message_format.nim index 3632b13d20..2999340a19 100644 --- a/src/app/chat/views/message_format.nim +++ b/src/app/chat/views/message_format.nim @@ -28,7 +28,7 @@ proc renderBlock(self: ChatMessageList, message: Message): string = for pMsg in message.parsedText: case pMsg.textType: of "paragraph": - result = "

" + result = result & "

" for children in pMsg.children: result = result & self.renderInline(children) result = result & "

" @@ -37,5 +37,5 @@ proc renderBlock(self: ChatMessageList, message: Message): string = var color = if message.isCurrentUser: "#FFFFFF" else: "#666666" result = result & fmt("▍ ") & pMsg.literal & "" of "codeblock": - result = "
" & pMsg.literal & "
" + result = result & "
" & pMsg.literal & "
" result = result.replace("\n", "
") \ No newline at end of file diff --git a/src/app/chat/views/message_list.nim b/src/app/chat/views/message_list.nim index 326bb5f25c..a7e94b87d1 100644 --- a/src/app/chat/views/message_list.nim +++ b/src/app/chat/views/message_list.nim @@ -80,7 +80,6 @@ QtObject: of ChatMessageRoles.Id: result = newQVariant(message.id) of ChatMessageRoles.OutgoingStatus: result = newQVariant(message.outgoingStatus) of ChatMessageRoles.ResponseTo: result = newQVariant(message.responseTo) - of ChatMessageRoles.Text: result = newQVariant(message.text) method roleNames(self: ChatMessageList): Table[int, string] = { @@ -98,8 +97,7 @@ QtObject: ChatMessageRoles.SectionIdentifier.int: "sectionIdentifier", ChatMessageRoles.Id.int: "messageId", ChatMessageRoles.OutgoingStatus.int: "outgoingStatus", - ChatMessageRoles.ResponseTo.int: "responseTo", - ChatMessageRoles.Text.int: "text" + ChatMessageRoles.ResponseTo.int: "responseTo" }.toTable proc getMessageIndex(self: ChatMessageList, messageId: string): int {.slot.} = @@ -111,6 +109,7 @@ QtObject: case data: of "userName": result = message.alias of "message": result = message.text + of "identicon": result = message.identicon else: result = "" proc add*(self: ChatMessageList, message: Message) = diff --git a/ui/app/AppLayouts/Chat/ChatColumn.qml b/ui/app/AppLayouts/Chat/ChatColumn.qml index 044c9decfa..90fd1e49d3 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn.qml @@ -53,7 +53,10 @@ StackLayout { } Action { text: qsTr("Reply to") - onTriggered: chatsModel.enableReplyArea(true, profilePopup.userName, profilePopup.text, profilePopup.identicon) + onTriggered: { + isReply = true; + replyAreaContainer.setup() + } } } @@ -69,28 +72,18 @@ StackLayout { ReplyArea { - id: replyArea + id: replyAreaContainer visible: isReply } ChatInput { height: 40 - anchors.top: !isReply ? inputArea.top : replyArea.bottom + anchors.top: !isReply ? inputArea.top : replyAreaContainer.bottom anchors.topMargin: 4 anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom } - - Connections { - target: chatsModel - onReplyAreaEnabled: { - isReply = enable; - replyArea.userName = userName; - replyArea.identicon = identicon; - replyArea.message = message; - } - } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatButtons.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatButtons.qml index d635bf2c52..5d08b6256f 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatButtons.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatButtons.qml @@ -23,7 +23,7 @@ Item { anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right onClicked: { - chatsModel.sendMessage(txtData.text, chatColumn.isReply) + chatsModel.sendMessage(txtData.text, SelectedMessage.messageId) txtData.text = "" } background: Rectangle { diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml index ac23795ef7..2aa2bbd858 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml @@ -33,7 +33,7 @@ Rectangle { if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) { if(txtData.text.trim().length > 0){ let msg = interpretMessage(txtData.text.trim()) - chatsModel.sendMessage(msg, chatColumn.isReply); + chatsModel.sendMessage(msg, SelectedMessage.messageId); txtData.text = ""; event.accepted = true; sendMessageSound.stop() diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 874af5a6ac..f818d08895 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -39,12 +39,6 @@ ScrollView { Qt.callLater( chatLogView.positionViewAtEnd ) } - onReplyAreaEnabled: { - if (enable){ - Qt.callLater( chatLogView.positionViewAtEnd ) - } - } - onMessagePushed: { if (!chatLogView.atYEnd) { // User has scrolled up, we don't want to scroll back diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index 582ad29195..9b326766d1 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -206,8 +206,8 @@ Item { cursorShape: Qt.PointingHandCursor anchors.fill: parent onClicked: { - chatsModel.setReplyTo(messageId) - profileClick(userName, fromAuthor, identicon, text); + SelectedMessage.set(messageId, fromAuthor); + profileClick(userName, fromAuthor, identicon); messageContextMenu.popup() } } @@ -230,8 +230,8 @@ Item { cursorShape: Qt.PointingHandCursor anchors.fill: parent onClicked: { - chatsModel.setReplyTo(messageId) - profileClick(userName, fromAuthor, identicon, text) + SelectedMessage.set(messageId, fromAuthor); + profileClick(userName, fromAuthor, identicon) messageContextMenu.popup() } } @@ -317,10 +317,11 @@ Item { text: { if(contentType === Constants.stickerType) return ""; if(isEmoji){ - return Emoji.parse(message, "72x72"); + return Emoji.parse(linkify(message), "72x72"); } else { return Emoji.parse(linkify(message), "26x26"); } + } anchors.left: parent.left anchors.leftMargin: parent.chatHorizontalPadding @@ -353,7 +354,15 @@ Item { MouseArea { anchors.fill: parent cursorShape: chatText.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor + acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { + if(mouse.button & Qt.RightButton) { + SelectedMessage.set(messageId, fromAuthor); + profileClick(userName, fromAuthor, identicon); + messageContextMenu.popup() + return; + } + let link = chatText.hoveredLink; if(link.startsWith("#")){ chatsModel.joinChat(link.substring(1), Constants.chatTypePublic); @@ -362,17 +371,12 @@ Item { if (link.startsWith('//')) { let pk = link.replace("//", ""); - profileClick(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk), text) + profileClick(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk)) return; } Qt.openUrlExternally(link) } - onPressAndHold: { - chatsModel.setReplyTo(messageId) - profileClick(userName, fromAuthor, identicon, text); - messageContextMenu.popup() - } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ReplyArea.qml b/ui/app/AppLayouts/Chat/ChatColumn/ReplyArea.qml index 99bac3425e..cef2f25f61 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ReplyArea.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ReplyArea.qml @@ -7,7 +7,7 @@ import "./" Rectangle { property string userName: "Joseph Joestar" - property string message: "Your next line is: is this is a Jojo reference?" + property string message: "Your next line is: this is a Jojo reference" property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" id: replyArea @@ -17,6 +17,21 @@ Rectangle { anchors.top: parent.top color: "#00000000" + function setup(){ + let replyMessageIndex = chatsModel.messageList.getMessageIndex(SelectedMessage.messageId); + if (replyMessageIndex == -1) return; + + userName = chatsModel.messageList.getReplyData(replyMessageIndex, "userName") + message = chatsModel.messageList.getReplyData(replyMessageIndex, "message") + identicon = chatsModel.messageList.getReplyData(replyMessageIndex, "identicon") + } + + function reset(){ + userName = ""; + message= ""; + identicon = ""; + } + Rectangle { id: closeButton height: 32 @@ -37,7 +52,7 @@ Rectangle { } MouseArea { - id: closeModalMouseArea + id: closeReplyArea cursorShape: Qt.PointingHandCursor anchors.fill: parent hoverEnabled: true @@ -47,7 +62,10 @@ Rectangle { onEntered: { closeButton.color = Style.current.grey } - onClicked: chatsModel.enableReplyArea(false, "","","") + onClicked: { + reset(); + chatColumn.isReply = false; + } } } diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml index dc237247e5..4258737cfd 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml @@ -61,6 +61,8 @@ Item { target: chatsModel onActiveChannelChanged: { chatGroupsListView.currentIndex = chatsModel.activeChannelIndex + SelectedMessage.reset(); + chatColumn.isReply = false; } } } diff --git a/ui/imports/SelectedMessage.qml b/ui/imports/SelectedMessage.qml new file mode 100644 index 0000000000..0c9500a4fc --- /dev/null +++ b/ui/imports/SelectedMessage.qml @@ -0,0 +1,18 @@ +pragma Singleton + +import QtQuick 2.13 + +QtObject { + property string messageId: "" + property string author: "" + + function reset(){ + messageId = ""; + author = ""; + } + + function set(_messageId, _author){ + messageId = _messageId; + author = _author; + } +} \ No newline at end of file diff --git a/ui/imports/qmldir b/ui/imports/qmldir index f1e381e234..08f137f4e8 100644 --- a/ui/imports/qmldir +++ b/ui/imports/qmldir @@ -3,3 +3,4 @@ singleton Style 1.0 ./Style.qml singleton Constants 1.0 ./Constants.qml singleton Utils 1.0 ./Utils.qml singleton Emoji 1.0 ./Emoji.qml +singleton SelectedMessage 1.0 ./SelectedMessage.qml