Skip to content

Commit

Permalink
fix(ChatMessagesView): Usage of StatusMessage WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Aug 19, 2022
1 parent ae339f7 commit f50ad06
Show file tree
Hide file tree
Showing 52 changed files with 1,306 additions and 4,019 deletions.
5 changes: 3 additions & 2 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
chatDetails.communityId, # we don't received community id via `activityCenterNotifications` api call
message.responseTo,
message.`from`,
contactDetails.displayName,
contactDetails.details.displayName,
contactDetails.details.localNickname,
contactDetails.icon,
contactDetails.isCurrentUser,
Expand All @@ -93,7 +93,8 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
message.links,
newTransactionParametersItem("","","","","","",-1,""),
message.mentionedUsersPks,
contactDetails.details.trustStatus
contactDetails.details.trustStatus,
contactDetails.details.ensVerified
))

method convertToItems*(
Expand Down
26 changes: 15 additions & 11 deletions src/app/modules/main/chat_section/chat_content/messages/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ proc createFetchMoreMessagesItem(self: Module): Item =
messageType = -1,
sticker = "",
stickerPack = -1,
@[],
newTransactionParametersItem("","","","","","",-1,""),
@[],
TrustStatus.Unknown
links = @[],
transactionParameters = newTransactionParametersItem("","","","","","",-1,""),
mentionedUsersPks = @[],
senderTrustStatus = TrustStatus.Unknown,
senderEnsVerified = false
)

proc createChatIdentifierItem(self: Module): Item =
Expand Down Expand Up @@ -128,10 +129,11 @@ proc createChatIdentifierItem(self: Module): Item =
messageType = -1,
sticker = "",
stickerPack = -1,
@[],
newTransactionParametersItem("","","","","","",-1,""),
@[],
TrustStatus.Unknown
links = @[],
transactionParameters = newTransactionParametersItem("","","","","","",-1,""),
mentionedUsersPks = @[],
senderTrustStatus = TrustStatus.Unknown,
senderEnsVerified = false
)

proc checkIfMessageLoadedAndScrollToItIfItIs(self: Module): bool =
Expand Down Expand Up @@ -177,7 +179,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.communityId,
m.responseTo,
m.`from`,
sender.displayName,
sender.details.displayName,
sender.details.localNickname,
sender.icon,
isCurrentUser,
Expand All @@ -203,6 +205,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.transactionParameters.signature),
m.mentionedUsersPks(),
sender.details.trustStatus,
sender.details.ensVerified
)

for r in reactions:
Expand Down Expand Up @@ -265,7 +268,7 @@ method messageAdded*(self: Module, message: MessageDto) =
message.communityId,
message.responseTo,
message.`from`,
sender.displayName,
sender.details.displayName,
sender.details.localNickname,
sender.icon,
isCurrentUser,
Expand All @@ -291,6 +294,7 @@ method messageAdded*(self: Module, message: MessageDto) =
message.transactionParameters.signature),
message.mentionedUsersPks,
sender.details.trustStatus,
sender.details.ensVerified
)

self.view.model().insertItemBasedOnTimestamp(item)
Expand Down Expand Up @@ -399,7 +403,7 @@ method updateContactDetails*(self: Module, contactId: string) =
let updatedContact = self.controller.getContactDetails(contactId)
for item in self.view.model().modelContactUpdateIterator(contactId):
if(item.senderId == contactId):
item.senderDisplayName = updatedContact.displayName
item.senderDisplayName = updatedContact.details.displayName
item.senderLocalName = updatedContact.details.localNickname
item.senderIcon = updatedContact.icon
item.senderIsAdded = updatedContact.details.added
Expand Down
8 changes: 5 additions & 3 deletions src/app/modules/main/chat_section/chat_content/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
m.communityId,
m.responseTo,
m.`from`,
contactDetails.displayName,
contactDetails.details.displayName,
contactDetails.details.localNickname,
contactDetails.icon,
isCurrentUser,
Expand All @@ -193,6 +193,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
m.transactionParameters.signature),
m.mentionedUsersPks,
contactDetails.details.trustStatus,
contactDetails.details.ensVerified
)
item.pinned = true
item.pinnedBy = actionInitiatedBy
Expand Down Expand Up @@ -318,8 +319,9 @@ method onContactDetailsUpdated*(self: Module, contactId: string) =
let updatedContact = self.controller.getContactDetails(contactId)
for item in self.view.pinnedModel().modelContactUpdateIterator(contactId):
if(item.senderId == contactId):
item.senderDisplayName = updatedContact.displayName
item.senderDisplayName = updatedContact.details.displayName
item.senderLocalName = updatedContact.details.localNickname
item.senderEnsVerified = updatedContact.details.ensVerified
item.senderIcon = updatedContact.icon
item.senderTrustStatus = updatedContact.details.trustStatus
if(item.messageContainsMentions):
Expand All @@ -329,7 +331,7 @@ method onContactDetailsUpdated*(self: Module, contactId: string) =
item.messageContainsMentions = m.containsContactMentions()

if(self.controller.getMyChatId() == contactId):
self.view.updateChatDetailsNameAndIcon(updatedContact.displayName, updatedContact.icon)
self.view.updateChatDetailsNameAndIcon(updatedContact.details.displayName, updatedContact.icon)
self.view.updateTrustStatus(updatedContact.details.trustStatus == TrustStatus.Untrustworthy)

method onNotificationsUpdated*(self: Module, hasUnreadMessages: bool, notificationCount: int) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ method onNewMessagesLoaded*(self: Module, messages: seq[MessageDto]) =
let status = toOnlineStatus(statusUpdateDto.statusType)
self.view.model().addItem(initMemberItem(
pubKey = m.`from`,
displayName = contactDetails.displayName,
displayName = contactDetails.details.displayName,
ensName = contactDetails.details.name, # is it correct?
localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias,
Expand Down Expand Up @@ -132,7 +132,7 @@ method addChatMember*(self: Module, member: ChatMember) =
let isMe = member.id == singletonInstance.userProfile.getPubKey()
let contactDetails = self.controller.getContactDetails(member.id)
var status = OnlineStatus.Online
var displayName = contactDetails.displayName
var displayName = contactDetails.details.displayName
if (isMe):
let currentUserStatus = intToEnum(singletonInstance.userProfile.getCurrentUserStatus(), StatusType.Unknown)
status = toOnlineStatus(currentUserStatus)
Expand All @@ -142,7 +142,7 @@ method addChatMember*(self: Module, member: ChatMember) =

self.view.model().addItem(initMemberItem(
pubKey = member.id,
displayName = displayName,
displayName = contactDetails.details.displayName,
ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias,
Expand Down Expand Up @@ -180,7 +180,7 @@ method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined
let contactDetails = self.controller.getContactDetails(publicKey)
self.view.model().updateItem(
pubKey = publicKey,
displayName = contactDetails.displayName,
displayName = contactDetails.details.displayName,
ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ proc createChatItem(self: Module, chatDto: ChatDto): Item =
var itemType = item.Type.GroupChat
if(chatDto.chatType == ChatType.OneToOne):
let contactDetails = self.controller.getContactDetails(chatDto.id)
chatName = contactDetails.displayName
chatName = contactDetails.details.displayName
chatImage = contactDetails.icon
itemType = item.Type.OneToOneChat

Expand Down
15 changes: 13 additions & 2 deletions src/app/modules/shared_models/message_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type
transactionParameters: TransactionParametersItem
mentionedUsersPks: seq[string]
senderTrustStatus: TrustStatus
senderEnsVerified: bool

proc initItem*(
id,
Expand All @@ -61,7 +62,8 @@ proc initItem*(
links: seq[string],
transactionParameters: TransactionParametersItem,
mentionedUsersPks: seq[string],
senderTrustStatus: TrustStatus
senderTrustStatus: TrustStatus,
senderEnsVerified: bool
): Item =
result = Item()
result.id = id
Expand Down Expand Up @@ -93,6 +95,7 @@ proc initItem*(
result.gapFrom = 0
result.gapTo = 0
result.senderTrustStatus = senderTrustStatus
result.senderEnsVerified = senderEnsVerified

proc `$`*(self: Item): string =
result = fmt"""Item(
Expand Down Expand Up @@ -120,6 +123,7 @@ proc `$`*(self: Item): string =
transactionParameters:{$self.transactionParameters},
mentionedUsersPks:{$self.mentionedUsersPks},
senderTrustStatus:{$self.senderTrustStatus},
senderEnsVerified: {self.senderEnsVerified},
)"""

proc id*(self: Item): string {.inline.} =
Expand Down Expand Up @@ -167,6 +171,12 @@ proc senderTrustStatus*(self: Item): TrustStatus {.inline.} =
proc `senderTrustStatus=`*(self: Item, value: TrustStatus) {.inline.} =
self.senderTrustStatus = value

proc senderEnsVerified*(self: Item): bool {.inline.} =
self.senderEnsVerified

proc `senderEnsVerified=`*(self: Item, value: bool) {.inline.} =
self.senderEnsVerified = value

proc outgoingStatus*(self: Item): string {.inline.} =
self.outgoingStatus

Expand Down Expand Up @@ -274,7 +284,8 @@ proc toJsonNode*(self: Item): JsonNode =
"editMode": self.editMode,
"isEdited": self.isEdited,
"links": self.links,
"mentionedUsersPks": self.mentionedUsersPks
"mentionedUsersPks": self.mentionedUsersPks,
"senderEnsVerified": self.senderEnsVerified
}

proc editMode*(self: Item): bool {.inline.} =
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/shared_models/message_item_qobject.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ QtObject:
QtProperty[string] senderLocalName:
read = senderLocalName

proc senderEnsVerified*(self: MessageItem): bool {.slot.} = result = ?.self.messageItem.senderEnsVerified
QtProperty[bool] senderEnsVerified:
read = senderEnsVerified

proc amISender*(self: MessageItem): bool {.slot.} = result = ?.self.messageItem.amISender
QtProperty[bool] amISender:
read = amISender
Expand Down
16 changes: 12 additions & 4 deletions src/app/modules/shared_models/message_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type
TransactionParameters
MentionedUsersPks
SenderTrustStatus
SenderEnsVerified

QtObject:
type
Expand Down Expand Up @@ -71,7 +72,7 @@ QtObject:
proc countChanged(self: Model) {.signal.}
proc getCount(self: Model): int {.slot.} =
self.items.len
QtProperty[int] count:
QtProperty[int]count:
read = getCount
notify = countChanged

Expand Down Expand Up @@ -112,7 +113,8 @@ QtObject:
ModelRole.Links.int: "links",
ModelRole.TransactionParameters.int: "transactionParameters",
ModelRole.MentionedUsersPks.int: "mentionedUsersPks",
ModelRole.SenderTrustStatus.int: "senderTrustStatus"
ModelRole.SenderTrustStatus.int: "senderTrustStatus",
ModelRole.SenderEnsVerified.int: "senderEnsVerified"
}.toTable

method data(self: Model, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -205,6 +207,8 @@ QtObject:
}))
of ModelRole.MentionedUsersPks:
result = newQVariant(item.mentionedUsersPks.join(" "))
of ModelRole.SenderEnsVerified:
result = newQVariant(item.senderEnsVerified)

proc updateItemAtIndex(self: Model, index: int) =
let ind = self.createIndex(index, 0, nil)
Expand Down Expand Up @@ -393,8 +397,12 @@ QtObject:

var roles: seq[int]
if(self.items[i].senderId == contactId):
roles = @[ModelRole.SenderDisplayName.int, ModelRole.SenderLocalName.int,
ModelRole.SenderIcon.int, ModelRole.SenderIsAdded.int, ModelRole.SenderTrustStatus.int]
roles = @[ModelRole.SenderDisplayName.int,
ModelRole.SenderLocalName.int,
ModelRole.SenderIcon.int,
ModelRole.SenderIsAdded.int,
ModelRole.SenderTrustStatus.int,
ModelRole.SenderEnsVerified.int]
if(self.items[i].pinnedBy == contactId):
roles.add(ModelRole.PinnedBy.int)
if(self.items[i].messageContainsMentions):
Expand Down
2 changes: 1 addition & 1 deletion ui/StatusQ
Submodule StatusQ updated 31 files
+24 −3 sandbox/controls/ListItems.qml
+48 −21 sandbox/demoapp/ChatChannelView.qml
+319 −109 sandbox/demoapp/data/Models.qml
+54 −0 src/StatusQ/Components/StatusDateGroupLabel.qml
+15 −7 src/StatusQ/Components/StatusListItem.qml
+290 −83 src/StatusQ/Components/StatusMessage.qml
+4 −15 src/StatusQ/Components/StatusMessageDetails.qml
+33 −0 src/StatusQ/Components/StatusMessageSenderDetails.qml
+4 −0 src/StatusQ/Components/StatusSmartIdenticon.qml
+27 −9 src/StatusQ/Components/private/statusMessage/StatusEditMessage.qml
+4 −4 src/StatusQ/Components/private/statusMessage/StatusImageMessage.qml
+227 −0 src/StatusQ/Components/private/statusMessage/StatusMessageEmojiReactions.qml
+30 −29 src/StatusQ/Components/private/statusMessage/StatusMessageHeader.qml
+13 −13 src/StatusQ/Components/private/statusMessage/StatusMessageQuickActions.qml
+17 −12 src/StatusQ/Components/private/statusMessage/StatusMessageReply.qml
+29 −8 src/StatusQ/Components/private/statusMessage/StatusPinMessageDetails.qml
+27 −18 src/StatusQ/Components/private/statusMessage/StatusTextMessage.qml
+2 −0 src/StatusQ/Components/qmldir
+7 −0 src/StatusQ/Controls/StatusComboBox.qml
+10 −4 src/StatusQ/Controls/StatusItemDelegate.qml
+40 −0 src/StatusQ/Core/StatusProfileImageSettings.qml
+7 −0 src/StatusQ/Core/Theme/StatusDarkTheme.qml
+7 −0 src/StatusQ/Core/Theme/StatusLightTheme.qml
+2 −1 src/StatusQ/Core/Theme/ThemePalette.qml
+71 −0 src/StatusQ/Core/Utils/Utils.qml
+2 −0 src/StatusQ/Core/Utils/qmldir
+1,318 −0 src/StatusQ/Core/Utils/xss.js
+1 −0 src/StatusQ/Core/qmldir
+1 −0 src/StatusQ/Popups/StatusSearchPopup.qml
+10 −0 src/assets/img/icons/key_pair_private_key.svg
+4 −0 src/assets/img/icons/key_pair_seed_phrase.svg
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Item {
StyledText {
id: contactInfo
text: realChatType !== Constants.chatType.publicChat ?
StatusQUtils.Emoji.parse(Utils.removeStatusEns(Utils.filterXSS(name))) :
"#" + Utils.filterXSS(name)
StatusQUtils.Emoji.parse(Utils.removeStatusEns(StatusQUtils.Utils.filterXSS(name))) :
"#" + StatusQUtils.Utils.filterXSS(name)
anchors.left: contactImage.right
anchors.leftMargin: 4
color: textColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Item {
}

StyledTextEdit {
text: Utils.getReplyMessageStyle(StatusQUtils.Emoji.parse(Utils.linkifyAndXSS(repliedMessageContent), StatusQUtils.Emoji.size.small), false)
text: Utils.getReplyMessageStyle(StatusQUtils.Emoji.parse(StatusQUtils.Utils.linkifyAndXSS(repliedMessageContent), StatusQUtils.Emoji.size.small), false)
textFormat: Text.RichText
height: 18
width: implicitWidth > 300 ? 300 : implicitWidth
Expand Down
4 changes: 2 additions & 2 deletions ui/app/AppLayouts/Chat/panels/ChatTimePanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ StyledText {
color: Style.current.secondaryText
text: Utils.formatShortTime(timestamp)
font.pixelSize: Style.current.asideTextFontSize
property string timestamp
property int timestamp

StatusQ.StatusToolTip {
visible: hhandler.hovered
text: Utils.formatLongDateTime(parseInt(chatTime.timestamp, 10), RootStore.accountSensitiveSettings.isDDMMYYDateFormat, RootStore.accountSensitiveSettings.is24hTimeFormat)
text: Utils.formatLongDateTime(chatTime.timestamp, RootStore.accountSensitiveSettings.isDDMMYYDateFormat, RootStore.accountSensitiveSettings.is24hTimeFormat)
maxWidth: 350
}

Expand Down
4 changes: 1 addition & 3 deletions ui/app/AppLayouts/Chat/panels/UserListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ Item {
if (mouse.button === Qt.RightButton) {
// Set parent, X & Y positions for the messageContextMenu
messageContextMenu.parent = this
messageContextMenu.setXPosition = function() { return 0; }
messageContextMenu.setYPosition = function() { return mouse.y + (Style.current.halfPadding/2); }
messageContextMenu.isProfile = true
messageContextMenu.myPublicKey = userProfile.pubKey
messageContextMenu.selectedUserPublicKey = model.pubKey
messageContextMenu.selectedUserDisplayName = model.displayName
messageContextMenu.selectedUserIcon = image.source
messageContextMenu.popup()
messageContextMenu.popup(4, 4)
} else if (mouse.button === Qt.LeftButton && !!messageContextMenu) {
Global.openProfilePopup(model.pubKey);
}
Expand Down
16 changes: 10 additions & 6 deletions ui/app/AppLayouts/Chat/popups/PinnedMessagesPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ ModalPopup {

delegate: Item {
id: messageDelegate
property var listView: ListView.view
width: parent.width

width: ListView.view.width
height: messageItem.height

MessageView {
id: messageItem
store: popup.store

width: parent.width

rootStore: popup.store
messageStore: popup.messageStore
messageContextMenu: msgContextMenu

Expand All @@ -113,9 +116,10 @@ ModalPopup {
senderId: model.senderId
senderDisplayName: model.senderDisplayName
senderLocalName: model.senderLocalName
senderEnsName: model.senderEnsVerified ? model.senderDisplayName : ""
senderIcon: model.senderIcon
amISender: model.amISender
message: model.messageText
messageText: model.messageText
messageImage: model.messageImage
messageTimestamp: model.timestamp
messageOutgoingStatus: model.outgoingStatus
Expand All @@ -125,7 +129,6 @@ ModalPopup {
reactionsModel: model.reactions
senderTrustStatus: model.senderTrustStatus
linkUrls: model.links
isInPinnedPopup: true
transactionParams: model.transactionParameters

// This is possible since we have all data loaded before we load qml.
Expand All @@ -136,7 +139,8 @@ ModalPopup {
nextMessageAsJsonObj: popup.messageStore? popup.messageStore.getMessageByIndexAsJson(index + 1) : {}

// Additional params
forceHoverHandler: !popup.messageToPin
isInPinnedPopup: true
disableHover: !!popup.messageToPin
}

MouseArea {
Expand Down
Loading

0 comments on commit f50ad06

Please sign in to comment.