From 010f51d844f7dcddb29ceff7aeae3bb0eef650f8 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Thu, 18 Aug 2022 11:20:43 +0200 Subject: [PATCH] WIP --- .../modules/main/activity_center/module.nim | 17 +++--- .../chat_content/messages/module.nim | 44 +++++++++------ .../main/chat_section/chat_content/module.nim | 18 ++++--- .../modules/main/chat_section/controller.nim | 2 +- .../discord_message_author_item.nim | 15 +++++- .../shared_models/discord_message_item.nim | 53 +++++++++++++++---- .../modules/shared_models/message_item.nim | 6 ++- .../modules/shared_models/message_model.nim | 6 ++- .../service/message/async_tasks.nim | 1 + .../service/message/dto/message.nim | 2 - src/app_service/service/message/service.nim | 1 + .../Chat/views/ChatMessagesView.qml | 2 - ui/imports/shared/controls/chat/UserImage.qml | 19 ++++--- .../shared/controls/chat/UsernameLabel.qml | 21 ++++---- .../shared/views/chat/CompactMessageView.qml | 23 ++++++-- ui/imports/shared/views/chat/MessageView.qml | 2 +- 16 files changed, 159 insertions(+), 73 deletions(-) diff --git a/src/app/modules/main/activity_center/module.nim b/src/app/modules/main/activity_center/module.nim index ff6f9155fc..24d250acf6 100644 --- a/src/app/modules/main/activity_center/module.nim +++ b/src/app/modules/main/activity_center/module.nim @@ -96,14 +96,15 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch newTransactionParametersItem("","","","","","",-1,""), message.mentionedUsersPks, contactDetails.details.trustStatus, - newDiscordMessageItem("","","","","", - newDiscordMessageAuthorItem( - message.discordMessage.author.id, - message.discordMessage.author.name, - message.discordMessage.author.discriminator, - message.discordMessage.author.nickname, - message.discordMessage.author.avatarUrl - )))) + newDiscordMessageItem("","","","","","","", ""))) + # newDiscordMessageAuthorItem( + # message.discordMessage.author.id, + # message.discordMessage.author.name, + # message.discordMessage.author.discriminator, + # message.discordMessage.author.nickname, + # message.discordMessage.author.avatarUrl, + # message.discordMessage.author.avatarImageBase64 + # )))) method convertToItems*( self: Module, diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index 74ffc1b1ca..8d3a47f3e4 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -97,7 +97,8 @@ proc createFetchMoreMessagesItem(self: Module): Item = newTransactionParametersItem("","","","","","",-1,""), @[], TrustStatus.Unknown, - newDiscordMessageItem("", "", "", "", "", newDiscordMessageAuthorItem("", "", "", "", "")) + # newDiscordMessageItem("", "", "", "", "", newDiscordMessageAuthorItem("", "", "", "", "", "")) + newDiscordMessageItem("", "", "", "", "", "", "", "") ) proc createChatIdentifierItem(self: Module): Item = @@ -135,7 +136,8 @@ proc createChatIdentifierItem(self: Module): Item = newTransactionParametersItem("","","","","","",-1,""), @[], TrustStatus.Unknown, - newDiscordMessageItem("","","","","", newDiscordMessageAuthorItem("", "", "", "", "")) + # newDiscordMessageItem("","","","","", newDiscordMessageAuthorItem("", "", "", "", "", "")) + newDiscordMessageItem("","","","","","","","") ) proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module): bool = @@ -212,13 +214,18 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se m.discordMessage.timestamp, m.discordMessage.timestampEdited, m.discordMessage.content, - newDiscordMessageAuthorItem( - m.discordMessage.author.id, - m.discordMessage.author.name, - m.discordMessage.author.discriminator, - m.discordMessage.author.nickname, - m.discordMessage.author.avatarUrl, - )) + m.discordmessage.author.avatarUrl, + m.discordmessage.author.name, + m.discordMessage.author.avatarImageBase64 + ) + # newDiscordMessageAuthorItem( + # m.discordMessage.author.id, + # m.discordMessage.author.name, + # m.discordMessage.author.discriminator, + # m.discordMessage.author.nickname, + # m.discordMessage.author.avatarUrl, + # m.discordMessage.author.avatarImageBase64 + # )) ) for r in reactions: @@ -312,13 +319,18 @@ method messageAdded*(self: Module, message: MessageDto) = message.discordMessage.timestamp, message.discordMessage.timestampEdited, message.discordMessage.content, - newDiscordMessageAuthorItem( - message.discordMessage.author.id, - message.discordMessage.author.name, - message.discordMessage.author.discriminator, - message.discordMessage.author.nickname, - message.discordMessage.author.avatarUrl - )) + message.discordMessage.author.avatarUrl, + message.discordMessage.author.name, + message.discordMessage.author.avatarImageBase64 + ) + # newDiscordMessageAuthorItem( + # message.discordMessage.author.id, + # message.discordMessage.author.name, + # message.discordMessage.author.discriminator, + # message.discordMessage.author.nickname, + # message.discordMessage.author.avatarUrl, + # message.discordMessage.author.avatarImageBase64 + # )) ) self.view.model().insertItemBasedOnTimestamp(item) diff --git a/src/app/modules/main/chat_section/chat_content/module.nim b/src/app/modules/main/chat_section/chat_content/module.nim index fc668bc321..63ef81fca7 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -200,13 +200,17 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy: m.discordMessage.timestamp, m.discordMessage.timestampEdited, m.discordMessage.content, - newDiscordMessageAuthorItem( - m.discordMessage.author.id, - m.discordMessage.author.name, - m.discordMessage.author.discriminator, - m.discordMessage.author.nickname, - m.discordMessage.author.avatarUrl - )) + m.discordMessage.author.avatarUrl, + m.discordMessage.author.name, + m.discordMessage.author.avatarImageBase64 + # newDiscordMessageAuthorItem( + # m.discordMessage.author.id, + # m.discordMessage.author.name, + # m.discordMessage.author.discriminator, + # m.discordMessage.author.nickname, + # m.discordMessage.author.avatarUrl, + # m.discordMessage.author.avatarImageBase64) + ) ) item.pinned = true item.pinnedBy = actionInitiatedBy diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index dc333d3afe..b1b41acae6 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -170,7 +170,6 @@ proc init*(self: Controller) = self.events.on(SIGNAL_RELOAD_MESSAGES) do(e: Args): let args = ReloadMessagesArgs(e) if (args.communityId == self.sectionId): - echo "RELOADING MESSAGES!" self.messageService.asyncLoadInitialMessagesForChat(self.getActiveChatId()) self.events.on(SIGNAL_CATEGORY_MUTED) do(e: Args): @@ -255,6 +254,7 @@ proc setActiveItemSubItem*(self: Controller, itemId: string, subItemId: string) let chatId = self.getActiveChatId() if chatId != "": + echo "LOADING MESSAGES" self.messageService.asyncLoadInitialMessagesForChat(chatId) # We need to take other actions here like notify status go that unviewed mentions count is updated and so... diff --git a/src/app/modules/shared_models/discord_message_author_item.nim b/src/app/modules/shared_models/discord_message_author_item.nim index cf46f59d3a..af31c461cc 100644 --- a/src/app/modules/shared_models/discord_message_author_item.nim +++ b/src/app/modules/shared_models/discord_message_author_item.nim @@ -8,6 +8,7 @@ QtObject: discriminator: string nickname*: string avatarUrl*: string + avatarImageBase64*: string proc setup(self: DiscordMessageAuthorItem) = self.QObject.setup @@ -20,7 +21,8 @@ QtObject: name: string, discriminator: string, nickname: string, - avatarUrl: string + avatarUrl: string, + avatarImageBase64: string, ): DiscordMessageAuthorItem = new(result, delete) result.setup @@ -29,6 +31,7 @@ QtObject: result.discriminator = discriminator result.nickname = nickname result.avatarUrl = avatarUrl + result.avatarImageBase64 = avatarImageBase64 proc `$`*(self: DiscordMessageAuthorItem): string = result = fmt"""DiscordMessageAuthorItem( @@ -37,6 +40,7 @@ QtObject: discriminator: {$self.discriminator}, nickname: {$self.nickname}, avatarUrl: {$self.avatarUrl}, + avatarImageBase64: {$self.avatarImageBase64}, )""" proc id*(self: DiscordMessageAuthorItem): string {.inline.} = @@ -83,3 +87,12 @@ QtObject: QtProperty[string] avatarUrl: read = avatarUrl notify = avatarUrlChanged + + proc avatarImageBase64*(self: DiscordMessageAuthorItem): string {.inline.} = + self.avatarImageBase64 + + proc avatarImageBase64Changed*(self: DiscordMessageAuthorItem) {.signal.} + + QtProperty[string] avatarImageBase64: + read = avatarImageBase64 + notify = avatarImageBase64Changed diff --git a/src/app/modules/shared_models/discord_message_item.nim b/src/app/modules/shared_models/discord_message_item.nim index e91c40a1e5..2a79d4f402 100644 --- a/src/app/modules/shared_models/discord_message_item.nim +++ b/src/app/modules/shared_models/discord_message_item.nim @@ -11,7 +11,10 @@ QtObject: timestamp: string timestampEdited: string content: string - author: DiscordMessageAuthorItem + # author: DiscordMessageAuthorItem + authorName: string + authorAvatarUrl: string + authorAvatarImageBase64: string proc setup(self: DiscordMessageItem) = self.QObject.setup @@ -25,7 +28,10 @@ QtObject: timestamp: string, timestampEdited: string, content: string, - author: DiscordMessageAuthorItem, + # author: DiscordMessageAuthorItem, + authorAvatarUrl: string, + authorName: string, + authorAvatarImageBase64: string ): DiscordMessageItem = new(result, delete) result.setup @@ -34,7 +40,10 @@ QtObject: result.timestamp = timestamp result.timestampEdited = timestampEdited result.content = content - result.author = author + # result.author = author + result.authorAvatarUrl = authorAvatarUrl + result.authorName = authorName + result.authorAvatarImageBase64 = authorAvatarImageBase64 proc `$`*(self: DiscordMessageItem): string = result = fmt"""DiscordMessageItem( @@ -43,7 +52,8 @@ QtObject: timestamp: {$self.timestamp}, timestampEdited: {$self.timestampEdited}, content: {$self.content}, - author: {$self.author} + authorAvatarUrl: {$self.authorAvatarUrl}, + authorAvatarImageBase64: {$self.authorAvatarImageBase64}, )""" proc idChanged*(self: DiscordMessageItem) {.signal.} @@ -82,10 +92,33 @@ QtObject: read = content notify = contentChanged - proc authorChanged*(self: DiscordMessageItem) {.signal.} - proc author*(self: DiscordMessageItem): DiscordMessageAuthorItem {.inline.} = - self.author + proc authoAvatarUrlChanged*(self: DiscordMessageItem) {.signal.} + proc authorAvatarUrl*(self: DiscordMessageItem): string {.inline.} = + self.authorAvatarUrl - QtProperty[string] author: - read = author - notify = authorChanged + QtProperty[string] authorAvatarUrl: + read = authorAvatarUrl + notify = authorAvatarUrlChanged + + proc authorNameChanged*(self: DiscordMessageItem) {.signal.} + proc authorName*(self: DiscordMessageItem): string {.inline.} = + self.authorName + + QtProperty[string] authorName: + read = authorName + notify = authorNameChanged + + proc authorAvatarImageBase64Changed*(self: DiscordMessageItem) {.signal.} + proc authorAvatarImageBase64*(self: DiscordMessageItem): string {.inline.} = + self.authorAvatarImageBase64 + + QtProperty[string] authorAvatarImageBase64: + read = authorAvatarImageBase64 + notify = authorAvatarImageBase64Changed + # proc authorChanged*(self: DiscordMessageItem) {.signal.} + # proc author*(self: DiscordMessageItem): DiscordMessageAuthorItem {.inline.} = + # self.author + + # QtProperty[QVariant] author: + # read = author + # notify = authorChanged diff --git a/src/app/modules/shared_models/message_item.nim b/src/app/modules/shared_models/message_item.nim index df9e886d21..5fbb852281 100644 --- a/src/app/modules/shared_models/message_item.nim +++ b/src/app/modules/shared_models/message_item.nim @@ -99,8 +99,10 @@ proc initItem*( if ContentType.DiscordMessage == contentType: result.messageText = discordMessage.content - result.senderDisplayName = discordMessage.author.nickname - result.senderIcon = discordMessage.author.avatarUrl + result.senderDisplayName = discordMessage.authorName + result.senderIcon = discordMessage.authorAvatarUrl + if discordMessage.authorAvatarImageBase64 != "": + result.senderIcon = discordMessage.authorAvatarImageBase64 result.timestamp = parseInt(discordMessage.timestamp)*1000 if discordMessage.timestampEdited != "": result.timestamp = parseInt(discordMessage.timestampEdited)*1000 diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index 3a00f7d6f2..100ade21a9 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -37,6 +37,7 @@ type TransactionParameters MentionedUsersPks SenderTrustStatus + DiscordMessage QtObject: type @@ -110,7 +111,8 @@ QtObject: ModelRole.Links.int: "links", ModelRole.TransactionParameters.int: "transactionParameters", ModelRole.MentionedUsersPks.int: "mentionedUsersPks", - ModelRole.SenderTrustStatus.int: "senderTrustStatus" + ModelRole.SenderTrustStatus.int: "senderTrustStatus", + ModelRole.DiscordMessage.int: "discordMessage" }.toTable method data(self: Model, index: QModelIndex, role: int): QVariant = @@ -197,6 +199,8 @@ QtObject: })) of ModelRole.MentionedUsersPks: result = newQVariant(item.mentionedUsersPks.join(" ")) + of ModelRole.DiscordMessage: + result = newQVariant(item.discordMessage) proc updateItemAtIndex(self: Model, index: int) = let ind = self.createIndex(index, 0, nil) diff --git a/src/app_service/service/message/async_tasks.nim b/src/app_service/service/message/async_tasks.nim index 381bb7af47..9cfb2aa292 100644 --- a/src/app_service/service/message/async_tasks.nim +++ b/src/app_service/service/message/async_tasks.nim @@ -21,6 +21,7 @@ const asyncFetchChatMessagesTask: Task = proc(argEncoded: string) {.gcsafe, nimc "chatId": arg.chatId } + echo "FETCHING FOR REAL!" # handle messages if(arg.msgCursor != CURSOR_VALUE_IGNORE): var messagesArr: JsonNode diff --git a/src/app_service/service/message/dto/message.nim b/src/app_service/service/message/dto/message.nim index 0859442088..0845ac7a2e 100644 --- a/src/app_service/service/message/dto/message.nim +++ b/src/app_service/service/message/dto/message.nim @@ -34,7 +34,6 @@ type DiscordMessageAuthor* = object discriminator*: string nickname*: string avatarUrl*: string - avatarImagePayload*: string avatarImageBase64*: string type DiscordMessageReference* = object @@ -116,7 +115,6 @@ proc toDiscordMessageAuthor*(jsonObj: JsonNode): DiscordMessageAuthor = discard jsonObj.getProp("discriminator", result.discriminator) discard jsonObj.getProp("nickname", result.nickname) discard jsonObj.getProp("avatarUrl", result.avatarUrl) - discard jsonObj.getProp("avatarImagePayload", result.avatarImagePayload) discard jsonObj.getProp("avatarImageBase64", result.avatarImageBase64) proc toDiscordMessage*(jsonObj: JsonNode): DiscordMessage = diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index 9eff8b0118..977479e7a0 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -420,6 +420,7 @@ QtObject: if(self.getCurrentMessageCursor(chatId).len > 0): return + echo "ASYNC LOAD CHAT MESSAGES: ", chatId # we're here if initial messages are not loaded yet self.asyncLoadMoreMessagesForChat(chatId) diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index bb9362ce73..984a24d633 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -240,8 +240,6 @@ Item { model: messageStore.messagesModel - Component.onCompleted: chatLogView.scrollToBottom(true) - delegate: MessageView { id: msgDelegate objectName: "chatMessageViewDelegate" diff --git a/ui/imports/shared/controls/chat/UserImage.qml b/ui/imports/shared/controls/chat/UserImage.qml index fc8ddd768d..a97ee5fc54 100644 --- a/ui/imports/shared/controls/chat/UserImage.qml +++ b/ui/imports/shared/controls/chat/UserImage.qml @@ -18,6 +18,7 @@ Loader { property string image property bool showRing: true property bool interactive: true + property bool disabled: false property var messageContextMenu property int colorId: Utils.colorIdForPubkey(pubkey) @@ -48,16 +49,18 @@ Loader { active: root.interactive sourceComponent: MouseArea { - cursorShape: Qt.PointingHandCursor - hoverEnabled: true + cursorShape: hoverEnabled ? Qt.PointingHandCursor : Qt.ArrowCursor + hoverEnabled: !root.disabled onClicked: { - if (!!root.messageContextMenu) { - // Set parent, X & Y positions for the messageContextMenu - root.messageContextMenu.parent = root - root.messageContextMenu.setXPosition = function() { return root.width + 4 } - root.messageContextMenu.setYPosition = function() { return 0 } + if (!root.disabled) { + if (!!root.messageContextMenu) { + // Set parent, X & Y positions for the messageContextMenu + root.messageContextMenu.parent = root + root.messageContextMenu.setXPosition = function() { return root.width + 4 } + root.messageContextMenu.setYPosition = function() { return 0 } + } + root.clicked() } - root.clicked() } } } diff --git a/ui/imports/shared/controls/chat/UsernameLabel.qml b/ui/imports/shared/controls/chat/UsernameLabel.qml index 1af72d7f2d..f7ab2575e3 100644 --- a/ui/imports/shared/controls/chat/UsernameLabel.qml +++ b/ui/imports/shared/controls/chat/UsernameLabel.qml @@ -16,6 +16,7 @@ Item { property string displayName property string localName property bool amISender + property bool disabled signal clickMessage(bool isProfileClick) @@ -25,15 +26,15 @@ Item { color: text.startsWith("@") || root.amISender || localName !== "" ? Style.current.blue : Style.current.secondaryText font.weight: Font.Medium font.pixelSize: Style.current.secondaryTextFontSize - font.underline: root.isHovered + font.underline: root.isHovered && !root.disabled readOnly: true wrapMode: Text.WordWrap selectByMouse: true MouseArea { - cursorShape: Qt.PointingHandCursor + cursorShape: hoverEnabled ? Qt.PointingHandCursor : Qt.ArrowCursor acceptedButtons: Qt.LeftButton | Qt.RightButton anchors.fill: parent - hoverEnabled: true + hoverEnabled: !root.disabled onEntered: { root.isHovered = true } @@ -41,13 +42,15 @@ Item { root.isHovered = false } onClicked: { - if (!!root.messageContextMenu) { - // Set parent, X & Y positions for the messageContextMenu - root.messageContextMenu.parent = root - root.messageContextMenu.setXPosition = function() { return 0} - root.messageContextMenu.setYPosition = function() { return root.height + 4} + if (!root.disabled) { + if (!!root.messageContextMenu) { + // Set parent, X & Y positions for the messageContextMenu + root.messageContextMenu.parent = root + root.messageContextMenu.setXPosition = function() { return 0} + root.messageContextMenu.setYPosition = function() { return root.height + 4} + } + root.clickMessage(true); } - root.clickMessage(true); } } } diff --git a/ui/imports/shared/views/chat/CompactMessageView.qml b/ui/imports/shared/views/chat/CompactMessageView.qml index 15a94e5d3b..f5a8d5ebc9 100644 --- a/ui/imports/shared/views/chat/CompactMessageView.qml +++ b/ui/imports/shared/views/chat/CompactMessageView.qml @@ -11,6 +11,7 @@ import shared.controls.chat 1.0 import StatusQ.Controls 0.1 as StatusQControls import StatusQ.Core.Utils 0.1 as StatusQUtils +import StatusQ.Core 0.1 import StatusQ.Components 0.1 Item { @@ -366,8 +367,10 @@ Item { image: root.senderIcon pubkey: senderId + showRing: root.contentType != Constants.messageContentType.discordMessageType name: senderDisplayName messageContextMenu: root.messageContextMenu + disabled: root.contentType == Constants.messageContentType.discordMessageType onClicked: root.clickMessage(true, false, false, null, false, false, false, false, "") } @@ -382,9 +385,19 @@ Item { displayName: senderDisplayName localName: senderLocalName amISender: root.amISender - onClickMessage: { - root.clickMessage(true, false, false, null, false, false, false, false, "") - } + disabled: root.contentType == Constants.messageContentType.discordMessageType + onClickMessage: root.clickMessage(true, false, false, null, false, false, false, false, "") + } + + StatusBaseText { + id: importedLabel + text: qsTr("Imported from discord •") + color: Style.current.secondaryText + font.pixelSize: Style.current.asideTextFontSize + visible: root.contentType == Constants.messageContentType.discordMessageType + anchors.left: chatName.right + anchors.leftMargin: 4 + anchors.verticalCenter: chatName.verticalCenter } VerificationLabel { @@ -393,7 +406,7 @@ Item { anchors.leftMargin: 4 anchors.bottom: chatName.bottom anchors.bottomMargin: 4 - visible: !root.amISender && chatName.visible + visible: !root.amISender && chatName.visible && root.contentType != Constants.messageContentType.discordMessageType trustStatus: senderTrustStatus } @@ -401,7 +414,7 @@ Item { id: chatTime visible: !editModeOn && headerRepeatCondition anchors.verticalCenter: chatName.verticalCenter - anchors.left: trustStatus.right + anchors.left: importedLabel.visible ? importedLabel.right : trustStatus.right anchors.leftMargin: 4 color: Style.current.secondaryText timestamp: messageTimestamp diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 3e3b6cc576..39d2807cfe 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -63,7 +63,7 @@ Loader { Global.privacyModuleInst.profilePicturesVisibility !== Constants.profilePicturesVisibility.everyone)) { return "" - } + } return senderIcon } property string message: ""