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 Jul 23, 2022
1 parent 1dfd153 commit fbeb3e8
Show file tree
Hide file tree
Showing 34 changed files with 1,244 additions and 2,082 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ proc createFetchMoreMessagesItem(self: Module): Item =
@[],
newTransactionParametersItem("","","","","","",-1,""),
@[],
TrustStatus.Unknown
TrustStatus.Unknown,
false
)

proc createChatIdentifierItem(self: Module): Item =
Expand Down Expand Up @@ -131,7 +132,8 @@ proc createChatIdentifierItem(self: Module): Item =
@[],
newTransactionParametersItem("","","","","","",-1,""),
@[],
TrustStatus.Unknown
TrustStatus.Unknown,
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 @@ -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):
displayName = displayName & " (You)"
let currentUserStatus = intToEnum(singletonInstance.userProfile.getCurrentUserStatus(), StatusType.Unknown)
Expand All @@ -143,7 +143,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 @@ -181,7 +181,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 @@ -37,6 +37,7 @@ type
TransactionParameters
MentionedUsersPks
SenderTrustStatus
SenderEnsVerified

QtObject:
type
Expand Down Expand Up @@ -70,7 +71,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 @@ -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.SenderEnsVerified.int: "senderEnsVerified"
}.toTable

method data(self: Model, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -197,6 +199,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 @@ -369,8 +373,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 36 files
+6 −6 sandbox/controls/Controls.qml
+4 −4 sandbox/controls/ListItems.qml
+1 −1 sandbox/controls/Others.qml
+4 −5 sandbox/controls/Popups.qml
+48 −21 sandbox/demoapp/ChatChannelView.qml
+1 −1 sandbox/demoapp/DemoCommunityDetailModal.qml
+1 −1 sandbox/demoapp/StatusAppCommunityView.qml
+323 −113 sandbox/demoapp/data/Models.qml
+ sandbox/demoapp/data/profile-image-1.jpeg
+ sandbox/demoapp/data/profile-image-2.jpeg
+1 −1 sandbox/pages/StatusChatInfoToolBarPage.qml
+2 −2 sandbox/pages/StatusExpandableSettingsItemPage.qml
+2 −2 sandbox/pages/StatusPopupMenuPage.qml
+1 −1 sandbox/pages/StatusTagSelectorPage.qml
+4 −0 sandbox/qml.qrc
+64 −0 src/StatusQ/Components/StatusDateGroupLabel.qml
+213 −63 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
+60 −0 src/StatusQ/Components/private/DateGroup.qml
+21 −8 src/StatusQ/Components/private/statusMessage/StatusEditMessage.qml
+238 −0 src/StatusQ/Components/private/statusMessage/StatusMessageEmojiReactions.qml
+14 −14 src/StatusQ/Components/private/statusMessage/StatusMessageHeader.qml
+7 −3 src/StatusQ/Components/private/statusMessage/StatusMessageReply.qml
+16 −12 src/StatusQ/Components/private/statusMessage/StatusTextMessage.qml
+1 −0 src/StatusQ/Components/qmldir
+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
+63 −0 src/StatusQ/Core/Utils/Utils.qml
+1 −0 src/StatusQ/Core/Utils/qmldir
+1,318 −0 src/StatusQ/Core/Utils/xss.js
+1 −0 src/StatusQ/Core/qmldir
+3 −3 src/StatusQ/Popups/StatusPopupMenu.qml
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.filterXSS(name))) :
"#" + StatusQUtils.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/popups/PinnedMessagesPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ModalPopup {

MessageView {
id: messageItem
store: popup.store
rootStore: popup.store
messageStore: popup.messageStore
messageContextMenu: msgContextMenu

Expand All @@ -115,7 +115,7 @@ ModalPopup {
senderLocalName: model.senderLocalName
senderIcon: model.senderIcon
amISender: model.amISender
message: model.messageText
messageText: model.messageText
messageImage: model.messageImage
messageTimestamp: model.timestamp
messageOutgoingStatus: model.outgoingStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Dialogs 1.3

import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1 as StatusQUtils
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
Expand Down Expand Up @@ -216,9 +217,9 @@ StatusModal {

let error = ""
if (isEdit) {
error = root.store.editCommunityCategory(root.categoryId, Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
error = root.store.editCommunityCategory(root.categoryId, StatusQUtils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
} else {
error = root.store.createCommunityCategory(Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
error = root.store.createCommunityCategory(StatusQUtils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
}

if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ StatusModal {

if (!isEdit) {
//popup.contentItem.communityColor.color.toString().toUpperCase()
popup.createCommunityChannel(Utils.filterXSS(popup.contentItem.channelName.input.text),
Utils.filterXSS(popup.contentItem.channelDescription.input.text),
popup.createCommunityChannel(StatusQUtils.filterXSS(popup.contentItem.channelName.input.text),
StatusQUtils.filterXSS(popup.contentItem.channelDescription.input.text),
emoji,
popup.contentItem.channelColorDialog.color.toString().toUpperCase(),
popup.categoryId)
} else {
popup.editCommunityChannel(Utils.filterXSS(popup.contentItem.channelName.input.text),
Utils.filterXSS(popup.contentItem.channelDescription.input.text),
popup.editCommunityChannel(StatusQUtils.filterXSS(popup.contentItem.channelName.input.text),
StatusQUtils.filterXSS(popup.contentItem.channelDescription.input.text),
emoji,
popup.contentItem.channelColorDialog.color.toString().toUpperCase(),
popup.categoryId)
Expand Down
2 changes: 2 additions & 0 deletions ui/app/AppLayouts/Chat/stores/MessageStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ QtObject {
return messageModule.toggleReaction(messageId, emojiId)
}

// TODO: Remove. Moved to StatusQ.
function lastTwoItems(nodes) {
return nodes.join(qsTr(" and "));
}

// TODO: Remove. Moved to StatusQ.
function showReactionAuthors(jsonArrayOfUsersReactedWithThisEmoji, emojiId) {
let listOfUsers = JSON.parse(jsonArrayOfUsersReactedWithThisEmoji)
if (listOfUsers.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ Item {
MessageView {
id: notificationMessage
anchors.right: undefined
store: root.store
rootStore: root.store
messageStore: root.store.messageStore
messageId: model.id
senderDisplayName: model.message.senderDisplayName
message: model.message.messageText
messageText: model.message.messageText
responseToMessageWithId: model.message.responseToMessageWithId
senderId: model.message.senderId
senderLocalName: model.message.senderLocalName
Expand All @@ -143,7 +143,7 @@ Item {
read: model.read
onImageClicked: Global.openImagePopup(image, root.messageContextMenu)
scrollToBottom: null
clickMessage: function (isProfileClick) {
messageClickHandler: {
if (isProfileClick) {
return Global.openProfilePopup(model.message.senderId);
}
Expand Down
Loading

0 comments on commit fbeb3e8

Please sign in to comment.