This commit is contained in:
Pascal Precht 2022-08-18 11:20:43 +02:00
parent a4c7656618
commit 010f51d844
No known key found for this signature in database
GPG Key ID: 3017C135E0731E5A
16 changed files with 159 additions and 73 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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...

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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 =

View File

@ -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)

View File

@ -240,8 +240,6 @@ Item {
model: messageStore.messagesModel
Component.onCompleted: chatLogView.scrollToBottom(true)
delegate: MessageView {
id: msgDelegate
objectName: "chatMessageViewDelegate"

View File

@ -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()
}
}
}

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -63,7 +63,7 @@ Loader {
Global.privacyModuleInst.profilePicturesVisibility !==
Constants.profilePicturesVisibility.everyone)) {
return ""
}
}
return senderIcon
}
property string message: ""