From b5b02cfd57268f328ad26339d4b81685b086873c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 8 Jun 2020 13:29:28 -0400 Subject: [PATCH] show identifier as the first message of chat view --- src/app/chat/core.nim | 2 +- src/app/chat/view.nim | 2 +- src/app/chat/views/message_list.nim | 15 +++- src/signals/messages.nim | 2 +- src/status/chat/chat_message.nim | 5 +- .../Chat/ChatColumn/ChatMessages.qml | 6 +- ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 87 ++++++++++++++++++- ui/imports/Constants.qml | 1 + 8 files changed, 107 insertions(+), 13 deletions(-) diff --git a/src/app/chat/core.nim b/src/app/chat/core.nim index 82172c1de9..95a45c72ea 100644 --- a/src/app/chat/core.nim +++ b/src/app/chat/core.nim @@ -70,7 +70,7 @@ proc init*(self: ChatController) = proc handleMessage(self: ChatController, data: MessageSignal) = for c in data.chats: - self.view.updateChat(c.toChatItem()) + self.view.updateChat(c.toChatItem()) self.view.pushMessages(data.messages) proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) = diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index c93d74085b..16866e5297 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -76,7 +76,7 @@ QtObject: proc upsertChannel(self: ChatsView, channel: string) = if not self.messageList.hasKey(channel): - self.messageList[channel] = newChatMessageList() + self.messageList[channel] = newChatMessageList(channel) proc pushMessage*(self:ChatsView, message: ChatMessage) = self.upsertChannel(message.chatId) diff --git a/src/app/chat/views/message_list.nim b/src/app/chat/views/message_list.nim index 79d18d3be2..df7931ff3f 100644 --- a/src/app/chat/views/message_list.nim +++ b/src/app/chat/views/message_list.nim @@ -12,6 +12,7 @@ type Sticker = UserRole + 7 FromAuthor = UserRole + 8 Clock = UserRole + 9 + ChatId = UserRole + 10 QtObject: type ChatMessageList* = ref object of QAbstractListModel @@ -26,9 +27,15 @@ QtObject: proc setup(self: ChatMessageList) = self.QAbstractListModel.setup - proc newChatMessageList*(): ChatMessageList = + proc chatIdentifier(self: ChatMessageList, chatId:string): ChatMessage = + result = newChatMessage(); + result.contentType = -1; + result.chatId = chatId + + + proc newChatMessageList*(chatId: string): ChatMessageList = new(result, delete) - result.messages = @[] + result.messages = @[result.chatIdentifier(chatId)] result.setup method rowCount(self: ChatMessageList, index: QModelIndex = nil): int = @@ -51,6 +58,7 @@ QtObject: of ChatMessageRoles.ContentType: result = newQVariant(message.contentType) of ChatMessageRoles.Sticker: result = newQVariant(message.sticker) of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor) + of ChatMessageRoles.ChatId: result = newQVariant(message.chatId) method roleNames(self: ChatMessageList): Table[int, string] = { @@ -62,7 +70,8 @@ QtObject: ChatMessageRoles.IsCurrentUser.int:"isCurrentUser", ChatMessageRoles.ContentType.int:"contentType", ChatMessageRoles.Sticker.int:"sticker", - ChatMessageRoles.FromAuthor.int:"fromAuthor" + ChatMessageRoles.FromAuthor.int:"fromAuthor", + ChatMessageRoles.ChatId.int:"chatId" }.toTable proc add*(self: ChatMessageList, message: ChatMessage) = diff --git a/src/signals/messages.nim b/src/signals/messages.nim index ffd472b2b3..7e39e77492 100644 --- a/src/signals/messages.nim +++ b/src/signals/messages.nim @@ -36,7 +36,7 @@ proc toChat*(jsonChat: JsonNode): Chat = proc toMessage*(jsonMsg: JsonNode): Message = result = Message( alias: jsonMsg{"alias"}.getStr, - chatId: jsonMsg{"chatId"}.getStr, + chatId: jsonMsg{"localChatId"}.getStr, clock: jsonMsg{"clock"}.getInt, contentType: jsonMsg{"contentType"}.getInt, ensName: jsonMsg{"ensName"}.getStr, diff --git a/src/status/chat/chat_message.nim b/src/status/chat/chat_message.nim index ca7eb1628e..da75aac696 100644 --- a/src/status/chat/chat_message.nim +++ b/src/status/chat/chat_message.nim @@ -32,13 +32,14 @@ proc newChatMessage*(): ChatMessage = proc toChatMessage*(payload: JsonNode): ChatMessage = result = ChatMessage( - chatId: payload["chatId"].str, + chatId: payload["localChatId"].str, + fromAuthor: payload["from"].getStr, userName: payload["alias"].str, message: payload["text"].str, timestamp: $payload["timestamp"], clock: payload["clock"].getInt, identicon: payload["identicon"].str, - isCurrentUser: false, + isCurrentUser: false, # TODO: compare the "from" to the current user contentType: payload["contentType"].getInt, sticker: "" # TODO: implement when implementing stickers from user ) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 9e77fbc3e1..65f247656b 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -37,7 +37,7 @@ ScrollView { Qt.callLater( chatLogView.positionViewAtEnd ) } model: messageListDelegate - section.property: "userName" + section.property: "fromAuthor" section.criteria: ViewSection.FullString } @@ -88,8 +88,10 @@ ScrollView { } } model: messageList - delegate: Message { + + Message { id: msgDelegate + chatId: model.chatId userName: model.userName message: model.message identicon: model.identicon diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index ed8054d502..9cd33ffaff 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -15,16 +15,96 @@ Item { property int timestamp: 1234567 property string sticker: "Qme8vJtyrEHxABcSVGPF95PtozDgUyfr1xGjePmFdZgk9v" property int contentType: 1 // constants don't work in default props + property string chatId: "chatId" property string authorCurrentMsg: "authorCurrentMsg" property string authorPrevMsg: "authorPrevMsg" width: parent.width - height: contentType == Constants.stickerType ? stickerId.height + 50 : (isCurrentUser || (!isCurrentUser && authorCurrentMsg == authorPrevMsg) ? chatBox.height : 24 + chatBox.height) + height: { + switch(contentType){ + case Constants.chatIdentifier: + return 196; + case Constants.stickerType: + return stickerId.height + 50 + default: + return (isCurrentUser || (!isCurrentUser && authorCurrentMsg == authorPrevMsg) ? chatBox.height : 24 + chatBox.height) + } + } + ProfilePopup { id: profilePopup } + Item { + id: channelIdentifier + visible: authorCurrentMsg == "" + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 20 + anchors.top: parent.top + + Rectangle { + id: circleId + anchors.horizontalCenter: parent.horizontalCenter + width: 120 + height: 120 + radius: 120 + border.width: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne ? 2 : 0 + border.color: Theme.grey + color: { + const color = chatsModel.getChannelColor(chatId) + if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne || !color) { + return Theme.transparent + } + return color + } + + Image { + visible: chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + width: 120 + height: 120 + fillMode: Image.PreserveAspectFit + source: chatsModel.activeChannel.identicon + } + + Text { + visible: chatsModel.activeChannel.chatType != Constants.chatTypeOneToOne + text: { + if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne) { + return chatsModel.activeChannel.name; + } else { + return (chatId.charAt(0) == "#" ? chatId.charAt(1) : chatId.charAt(0)).toUpperCase(); + } + } + opacity: 0.7 + font.weight: Font.Bold + font.pixelSize: 51 + color: "white" + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + } + } + + Text { + wrapMode: Text.Wrap + text: { + if (chatsModel.activeChannel.chatType == Constants.chatTypeOneToOne) { + return chatsModel.activeChannel.name; + } else { + return "#" + chatId; + } + } + font.weight: Font.Bold + font.pixelSize: 22 + color: Theme.black + anchors.top: circleId.bottom + anchors.topMargin: 16 + anchors.horizontalCenter: parent.horizontalCenter + } + } + Image { id: chatImage width: 36 @@ -35,7 +115,7 @@ Item { anchors.top: parent.top fillMode: Image.PreserveAspectFit source: identicon - visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser + visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser MouseArea { cursorShape: Qt.PointingHandCursor @@ -58,7 +138,7 @@ Item { readOnly: true wrapMode: Text.WordWrap selectByMouse: true - visible: authorCurrentMsg != authorPrevMsg && !isCurrentUser + visible: contentType > -1 && authorCurrentMsg != authorPrevMsg && !isCurrentUser } Rectangle { @@ -77,6 +157,7 @@ Item { anchors.rightMargin: !isCurrentUser ? 0 : Theme.padding anchors.top: authorCurrentMsg != authorPrevMsg && !isCurrentUser ? chatImage.top : parent.top anchors.topMargin: 0 + visible: contentType > -1 // Thi`s rectangle's only job is to mask the corner to make it less rounded... yep Rectangle { diff --git a/ui/imports/Constants.qml b/ui/imports/Constants.qml index 2a96db9fe0..0e1b7da602 100644 --- a/ui/imports/Constants.qml +++ b/ui/imports/Constants.qml @@ -7,6 +7,7 @@ QtObject { readonly property int chatTypePublic: 2 readonly property int chatTypePrivateGroupChat: 3 + readonly property int chatIdentifier: -1 readonly property int messageType: 1 readonly property int stickerType: 2