fix(@desktop/chat): Improving displaying user names in chat

1. Rename contactDetails.displayName -> defaultDisplayName
2. Add contactDetails.optionalName (filled in contact service)
3. Set in message_model defaultDisplayName and optionalName values
4. Adjust UI

Issue #7241
This commit is contained in:
Michal Iskierko 2022-09-14 09:35:26 +02:00 committed by Michał Iskierko
parent a45770cc98
commit 62c2b56fc8
20 changed files with 98 additions and 81 deletions

View File

@ -75,8 +75,8 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, chatDetails: Ch
chatDetails.communityId, # we don't received community id via `activityCenterNotifications` api call chatDetails.communityId, # we don't received community id via `activityCenterNotifications` api call
message.responseTo, message.responseTo,
message.`from`, message.`from`,
contactDetails.details.displayName, contactDetails.defaultDisplayName,
contactDetails.details.localNickname, contactDetails.optionalName,
contactDetails.icon, contactDetails.icon,
contactDetails.isCurrentUser, contactDetails.isCurrentUser,
contactDetails.details.added, contactDetails.details.added,

View File

@ -78,7 +78,7 @@ proc createFetchMoreMessagesItem(self: Module): Item =
responseToMessageWithId = "", responseToMessageWithId = "",
senderId = chatDto.id, senderId = chatDto.id,
senderDisplayName = "", senderDisplayName = "",
senderLocalName = "", senderOptionalName = "",
senderIcon = "", senderIcon = "",
amISender = false, amISender = false,
senderIsAdded = false, senderIsAdded = false,
@ -117,7 +117,7 @@ proc createChatIdentifierItem(self: Module): Item =
responseToMessageWithId = "", responseToMessageWithId = "",
senderId = chatDto.id, senderId = chatDto.id,
senderDisplayName = chatName, senderDisplayName = chatName,
senderLocalName = "", senderOptionalName = "",
senderIcon = chatIcon, senderIcon = chatIcon,
amISender = false, amISender = false,
senderIsAdded, senderIsAdded,
@ -182,8 +182,8 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
m.communityId, m.communityId,
m.responseTo, m.responseTo,
m.`from`, m.`from`,
sender.details.displayName, sender.defaultDisplayName,
sender.details.localNickname, sender.optionalName,
sender.icon, sender.icon,
isCurrentUser, isCurrentUser,
sender.details.added, sender.details.added,
@ -219,7 +219,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
let userWhoAddedThisReaction = self.controller.getContactById(r.`from`) let userWhoAddedThisReaction = self.controller.getContactById(r.`from`)
let didIReactWithThisEmoji = userWhoAddedThisReaction.id == singletonInstance.userProfile.getPubKey() let didIReactWithThisEmoji = userWhoAddedThisReaction.id == singletonInstance.userProfile.getPubKey()
item.addReaction(emojiIdAsEnum, didIReactWithThisEmoji, userWhoAddedThisReaction.id, item.addReaction(emojiIdAsEnum, didIReactWithThisEmoji, userWhoAddedThisReaction.id,
userWhoAddedThisReaction.userNameOrAlias(), r.id) userWhoAddedThisReaction.userDefaultDisplayName(), r.id)
else: else:
error "wrong emoji id found when loading messages", methodName="newMessagesLoaded" error "wrong emoji id found when loading messages", methodName="newMessagesLoaded"
@ -273,8 +273,8 @@ method messageAdded*(self: Module, message: MessageDto) =
message.communityId, message.communityId,
message.responseTo, message.responseTo,
message.`from`, message.`from`,
sender.details.displayName, sender.defaultDisplayName,
sender.details.localNickname, sender.optionalName,
sender.icon, sender.icon,
isCurrentUser, isCurrentUser,
sender.details.added, sender.details.added,
@ -356,7 +356,7 @@ method toggleReactionFromOthers*(self: Module, messageId: string, emojiId: int,
if(item.shouldAddReaction(emojiIdAsEnum, reactionFrom)): if(item.shouldAddReaction(emojiIdAsEnum, reactionFrom)):
let userWhoAddedThisReaction = self.controller.getContactById(reactionFrom) let userWhoAddedThisReaction = self.controller.getContactById(reactionFrom)
self.view.model().addReaction(messageId, emojiIdAsEnum, didIReactWithThisEmoji = false, self.view.model().addReaction(messageId, emojiIdAsEnum, didIReactWithThisEmoji = false,
userWhoAddedThisReaction.id, userWhoAddedThisReaction.userNameOrAlias(), reactionId) userWhoAddedThisReaction.id, userWhoAddedThisReaction.userDefaultDisplayName(), reactionId)
else: else:
self.view.model().removeReaction(messageId, emojiIdAsEnum, reactionId, didIRemoveThisReaction = false) self.view.model().removeReaction(messageId, emojiIdAsEnum, reactionId, didIRemoveThisReaction = false)
else: else:
@ -413,8 +413,8 @@ method updateContactDetails*(self: Module, contactId: string) =
let updatedContact = self.controller.getContactDetails(contactId) let updatedContact = self.controller.getContactDetails(contactId)
for item in self.view.model().modelContactUpdateIterator(contactId): for item in self.view.model().modelContactUpdateIterator(contactId):
if(item.senderId == contactId): if(item.senderId == contactId):
item.senderDisplayName = updatedContact.details.displayName item.senderDisplayName = updatedContact.defaultDisplayName
item.senderLocalName = updatedContact.details.localNickname item.senderOptionalName = updatedContact.optionalName
item.senderIcon = updatedContact.icon item.senderIcon = updatedContact.icon
item.senderIsAdded = updatedContact.details.added item.senderIsAdded = updatedContact.details.added
item.senderTrustStatus = updatedContact.details.trustStatus item.senderTrustStatus = updatedContact.details.trustStatus

View File

@ -79,7 +79,7 @@ method load*(self: Module) =
var trustStatus = TrustStatus.Unknown var trustStatus = TrustStatus.Unknown
if(chatDto.chatType == ChatType.OneToOne): if(chatDto.chatType == ChatType.OneToOne):
let contactDto = self.controller.getContactById(self.controller.getMyChatId()) let contactDto = self.controller.getContactById(self.controller.getMyChatId())
chatName = contactDto.userNameOrAlias() chatName = contactDto.userDefaultDisplayName()
isContact = contactDto.isContact isContact = contactDto.isContact
trustStatus = contactDto.trustStatus trustStatus = contactDto.trustStatus
if(contactDto.image.thumbnail.len > 0): if(contactDto.image.thumbnail.len > 0):
@ -167,8 +167,8 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
m.communityId, m.communityId,
m.responseTo, m.responseTo,
m.`from`, m.`from`,
contactDetails.details.displayName, contactDetails.defaultDisplayName,
contactDetails.details.localNickname, contactDetails.optionalName,
contactDetails.icon, contactDetails.icon,
isCurrentUser, isCurrentUser,
contactDetails.details.added, contactDetails.details.added,
@ -206,7 +206,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, actionInitiatedBy:
let userWhoAddedThisReaction = self.controller.getContactById(r.`from`) let userWhoAddedThisReaction = self.controller.getContactById(r.`from`)
let didIReactWithThisEmoji = userWhoAddedThisReaction.id == singletonInstance.userProfile.getPubKey() let didIReactWithThisEmoji = userWhoAddedThisReaction.id == singletonInstance.userProfile.getPubKey()
item.addReaction(emojiIdAsEnum, didIReactWithThisEmoji, userWhoAddedThisReaction.id, item.addReaction(emojiIdAsEnum, didIReactWithThisEmoji, userWhoAddedThisReaction.id,
userWhoAddedThisReaction.userNameOrAlias(), r.id) userWhoAddedThisReaction.userDefaultDisplayName(), r.id)
else: else:
error "wrong emoji id found when loading messages", methodName="buildPinnedMessageItem" error "wrong emoji id found when loading messages", methodName="buildPinnedMessageItem"
@ -296,7 +296,7 @@ method toggleReactionFromOthers*(self: Module, messageId: string, emojiId: int,
if(item.shouldAddReaction(emojiIdAsEnum, reactionFrom)): if(item.shouldAddReaction(emojiIdAsEnum, reactionFrom)):
let userWhoAddedThisReaction = self.controller.getContactById(reactionFrom) let userWhoAddedThisReaction = self.controller.getContactById(reactionFrom)
self.view.pinnedModel().addReaction(messageId, emojiIdAsEnum, didIReactWithThisEmoji = false, self.view.pinnedModel().addReaction(messageId, emojiIdAsEnum, didIReactWithThisEmoji = false,
userWhoAddedThisReaction.id, userWhoAddedThisReaction.userNameOrAlias(), reactionId) userWhoAddedThisReaction.id, userWhoAddedThisReaction.userDefaultDisplayName(), reactionId)
else: else:
self.view.pinnedModel().removeReaction(messageId, emojiIdAsEnum, reactionId, didIRemoveThisReaction = false) self.view.pinnedModel().removeReaction(messageId, emojiIdAsEnum, reactionId, didIRemoveThisReaction = false)
else: else:
@ -320,8 +320,8 @@ method onContactDetailsUpdated*(self: Module, contactId: string) =
let updatedContact = self.controller.getContactDetails(contactId) let updatedContact = self.controller.getContactDetails(contactId)
for item in self.view.pinnedModel().modelContactUpdateIterator(contactId): for item in self.view.pinnedModel().modelContactUpdateIterator(contactId):
if(item.senderId == contactId): if(item.senderId == contactId):
item.senderDisplayName = updatedContact.details.displayName item.senderDisplayName = updatedContact.defaultDisplayName
item.senderLocalName = updatedContact.details.localNickname item.senderOptionalName = updatedContact.optionalName
item.senderEnsVerified = updatedContact.details.ensVerified item.senderEnsVerified = updatedContact.details.ensVerified
item.senderIcon = updatedContact.icon item.senderIcon = updatedContact.icon
item.senderTrustStatus = updatedContact.details.trustStatus item.senderTrustStatus = updatedContact.details.trustStatus

View File

@ -75,7 +75,7 @@ method onNewMessagesLoaded*(self: Module, messages: seq[MessageDto]) =
let status = toOnlineStatus(statusUpdateDto.statusType) let status = toOnlineStatus(statusUpdateDto.statusType)
self.view.model().addItem(initMemberItem( self.view.model().addItem(initMemberItem(
pubKey = m.`from`, pubKey = m.`from`,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, # is it correct? ensName = contactDetails.details.name, # is it correct?
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -91,7 +91,7 @@ method contactNicknameChanged*(self: Module, publicKey: string) =
let contactDetails = self.controller.getContactDetails(publicKey) let contactDetails = self.controller.getContactDetails(publicKey)
self.view.model().setName( self.view.model().setName(
publicKey, publicKey,
contactDetails.displayName, contactDetails.defaultDisplayName,
contactDetails.details.name, contactDetails.details.name,
contactDetails.details.localNickname contactDetails.details.localNickname
) )
@ -105,7 +105,7 @@ method contactUpdated*(self: Module, publicKey: string) =
let contactDetails = self.controller.getContactDetails(publicKey) let contactDetails = self.controller.getContactDetails(publicKey)
self.view.model().updateItem( self.view.model().updateItem(
pubKey = publicKey, pubKey = publicKey,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -142,7 +142,7 @@ method addChatMember*(self: Module, member: ChatMember) =
self.view.model().addItem(initMemberItem( self.view.model().addItem(initMemberItem(
pubKey = member.id, pubKey = member.id,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -191,7 +191,7 @@ method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined
let contactDetails = self.controller.getContactDetails(publicKey) let contactDetails = self.controller.getContactDetails(publicKey)
self.view.model().updateItem( self.view.model().updateItem(
pubKey = publicKey, pubKey = publicKey,
displayName = contactDetails.details.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,

View File

@ -143,7 +143,7 @@ proc buildChatSectionUI(
let belongToCommunity = chatDto.communityId != "" let belongToCommunity = chatDto.communityId != ""
if(chatDto.chatType == ChatType.OneToOne): if(chatDto.chatType == ChatType.OneToOne):
let contactDetails = self.controller.getContactDetails(chatDto.id) let contactDetails = self.controller.getContactDetails(chatDto.id)
chatName = contactDetails.displayName chatName = contactDetails.defaultDisplayName
chatImage = contactDetails.icon chatImage = contactDetails.icon
blocked = contactDetails.details.isBlocked() blocked = contactDetails.details.isBlocked()
colorHash = self.controller.getColorHash(chatDto.id) colorHash = self.controller.getColorHash(chatDto.id)
@ -217,7 +217,7 @@ proc createItemFromPublicKey(self: Module, publicKey: string): UserItem =
return initUserItem( return initUserItem(
pubKey = contactDetails.details.id, pubKey = contactDetails.details.id,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
icon = contactDetails.icon, icon = contactDetails.icon,
colorId = contactDetails.colorId, colorId = contactDetails.colorId,
onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType), onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType),
@ -682,10 +682,10 @@ method onContactDetailsUpdated*(self: Module, publicKey: string) =
self.view.contactRequestsModel().addItem(item) self.view.contactRequestsModel().addItem(item)
self.updateParentBadgeNotifications() self.updateParentBadgeNotifications()
singletonInstance.globalEvents.showNewContactRequestNotification("New Contact Request", singletonInstance.globalEvents.showNewContactRequestNotification("New Contact Request",
fmt "{contactDetails.displayName} added you as contact", fmt "{contactDetails.defaultDisplayName} added you as contact",
singletonInstance.userProfile.getPubKey()) singletonInstance.userProfile.getPubKey())
let chatName = contactDetails.displayName let chatName = contactDetails.defaultDisplayName
let chatImage = contactDetails.icon let chatImage = contactDetails.icon
let trustStatus = contactDetails.details.trustStatus let trustStatus = contactDetails.details.trustStatus
self.view.chatsModel().updateItemDetails(publicKey, chatName, chatImage, trustStatus) self.view.chatsModel().updateItemDetails(publicKey, chatName, chatImage, trustStatus)
@ -711,7 +711,7 @@ method onNewMessagesReceived*(self: Module, sectionIdMsgBelongsTo: string, chatI
let contactDetails = self.controller.getContactDetails(message.`from`) let contactDetails = self.controller.getContactDetails(message.`from`)
let renderedMessageText = self.controller.getRenderedText(message.parsedText) let renderedMessageText = self.controller.getRenderedText(message.parsedText)
let plainText = singletonInstance.utils.plainText(renderedMessageText) let plainText = singletonInstance.utils.plainText(renderedMessageText)
singletonInstance.globalEvents.showMessageNotification(contactDetails.displayName, plainText, sectionIdMsgBelongsTo, singletonInstance.globalEvents.showMessageNotification(contactDetails.defaultDisplayName, plainText, sectionIdMsgBelongsTo,
self.controller.isCommunity(), messageBelongsToActiveSection, chatIdMsgBelongsTo, messageBelongsToActiveChat, self.controller.isCommunity(), messageBelongsToActiveSection, chatIdMsgBelongsTo, messageBelongsToActiveChat,
message.id, notificationType.int, message.id, notificationType.int,
chatTypeMsgBelongsTo == ChatType.OneToOne, chatTypeMsgBelongsTo == ChatType.PrivateGroupChat) chatTypeMsgBelongsTo == ChatType.OneToOne, chatTypeMsgBelongsTo == ChatType.PrivateGroupChat)

View File

@ -83,7 +83,7 @@ proc createMemberItem(self: Module, memberId, requestId: string): MemberItem =
let contactDetails = self.controller.getContactDetails(memberId) let contactDetails = self.controller.getContactDetails(memberId)
result = initMemberItem( result = initMemberItem(
pubKey = memberId, pubKey = memberId,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,

View File

@ -251,7 +251,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
let contactDetails = self.controller.getContactDetails(member.id) let contactDetails = self.controller.getContactDetails(member.id)
result = initMemberItem( result = initMemberItem(
pubKey = member.id, pubKey = member.id,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -275,7 +275,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
let contactDetails = self.controller.getContactDetails(bannedMemberId) let contactDetails = self.controller.getContactDetails(bannedMemberId)
result = initMemberItem( result = initMemberItem(
pubKey = bannedMemberId, pubKey = bannedMemberId,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -289,7 +289,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
let contactDetails = self.controller.getContactDetails(requestDto.publicKey) let contactDetails = self.controller.getContactDetails(requestDto.publicKey)
result = initMemberItem( result = initMemberItem(
pubKey = requestDto.publicKey, pubKey = requestDto.publicKey,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -304,7 +304,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem
let contactDetails = self.controller.getContactDetails(requestDto.publicKey) let contactDetails = self.controller.getContactDetails(requestDto.publicKey)
result = initMemberItem( result = initMemberItem(
pubKey = requestDto.publicKey, pubKey = requestDto.publicKey,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
ensName = contactDetails.details.name, ensName = contactDetails.details.name,
localNickname = contactDetails.details.localNickname, localNickname = contactDetails.details.localNickname,
alias = contactDetails.details.alias, alias = contactDetails.details.alias,
@ -820,7 +820,7 @@ method contactUpdated*[T](self: Module[T], publicKey: string) =
let contactDetails = self.controller.getContactDetails(publicKey) let contactDetails = self.controller.getContactDetails(publicKey)
self.view.activeSection().updateMember( self.view.activeSection().updateMember(
publicKey, publicKey,
contactDetails.displayName, contactDetails.defaultDisplayName,
contactDetails.details.name, contactDetails.details.name,
contactDetails.details.localNickname, contactDetails.details.localNickname,
contactDetails.details.alias, contactDetails.details.alias,

View File

@ -46,7 +46,7 @@ proc createItemFromPublicKey(self: Module, publicKey: string): UserItem =
return initUserItem( return initUserItem(
pubKey = contact.id, pubKey = contact.id,
displayName = contactDetails.displayName, displayName = contactDetails.defaultDisplayName,
icon = contactDetails.icon, icon = contactDetails.icon,
colorId = contactDetails.colorId, colorId = contactDetails.colorId,
onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType), onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType),

View File

@ -37,7 +37,7 @@ type
responseToMessageWithId: string responseToMessageWithId: string
senderId: string senderId: string
senderDisplayName: string senderDisplayName: string
senderLocalName: string senderOptionalName: string
amISender: bool amISender: bool
senderIsAdded: bool senderIsAdded: bool
senderIcon: string senderIcon: string
@ -71,7 +71,7 @@ proc initItem*(
responseToMessageWithId, responseToMessageWithId,
senderId, senderId,
senderDisplayName, senderDisplayName,
senderLocalName, senderOptionalName,
senderIcon: string, senderIcon: string,
amISender: bool, amISender: bool,
senderIsAdded: bool, senderIsAdded: bool,
@ -98,7 +98,7 @@ proc initItem*(
result.responseToMessageWithId = responseToMessageWithId result.responseToMessageWithId = responseToMessageWithId
result.senderId = senderId result.senderId = senderId
result.senderDisplayName = senderDisplayName result.senderDisplayName = senderDisplayName
result.senderLocalName = senderLocalName result.senderOptionalName = senderOptionalName
result.amISender = amISender result.amISender = amISender
result.senderIsAdded = senderIsAdded result.senderIsAdded = senderIsAdded
result.senderIcon = senderIcon result.senderIcon = senderIcon
@ -132,7 +132,7 @@ proc `$`*(self: Item): string =
responseToMessageWithId: {self.responseToMessageWithId}, responseToMessageWithId: {self.responseToMessageWithId},
senderId: {self.senderId}, senderId: {self.senderId},
senderDisplayName: {$self.senderDisplayName}, senderDisplayName: {$self.senderDisplayName},
senderLocalName: {self.senderLocalName}, senderOptionalName: {self.senderOptionalName},
amISender: {$self.amISender}, amISender: {$self.amISender},
senderIsAdded: {$self.senderIsAdded}, senderIsAdded: {$self.senderIsAdded},
seen: {$self.seen}, seen: {$self.seen},
@ -173,11 +173,11 @@ proc senderDisplayName*(self: Item): string {.inline.} =
proc `senderDisplayName=`*(self: Item, value: string) {.inline.} = proc `senderDisplayName=`*(self: Item, value: string) {.inline.} =
self.senderDisplayName = value self.senderDisplayName = value
proc senderLocalName*(self: Item): string {.inline.} = proc senderOptionalName*(self: Item): string {.inline.} =
self.senderLocalName self.senderOptionalName
proc `senderLocalName=`*(self: Item, value: string) {.inline.} = proc `senderOptionalName=`*(self: Item, value: string) {.inline.} =
self.senderLocalName = value self.senderOptionalName = value
proc senderIcon*(self: Item): string {.inline.} = proc senderIcon*(self: Item): string {.inline.} =
self.senderIcon self.senderIcon
@ -295,7 +295,7 @@ proc toJsonNode*(self: Item): JsonNode =
"responseToMessageWithId": self.responseToMessageWithId, "responseToMessageWithId": self.responseToMessageWithId,
"senderId": self.senderId, "senderId": self.senderId,
"senderDisplayName": self.senderDisplayName, "senderDisplayName": self.senderDisplayName,
"senderLocalName": self.senderLocalName, "senderOptionalName": self.senderOptionalName,
"amISender": self.amISender, "amISender": self.amISender,
"senderIsAdded": self.senderIsAdded, "senderIsAdded": self.senderIsAdded,
"senderIcon": self.senderIcon, "senderIcon": self.senderIcon,

View File

@ -45,9 +45,9 @@ QtObject:
QtProperty[string] senderDisplayName: QtProperty[string] senderDisplayName:
read = senderDisplayName read = senderDisplayName
proc senderLocalName*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.senderLocalName proc senderOptionalName*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.senderOptionalName
QtProperty[string] senderLocalName: QtProperty[string] senderOptionalName:
read = senderLocalName read = senderOptionalName
proc senderEnsVerified*(self: MessageItem): bool {.slot.} = result = ?.self.messageItem.senderEnsVerified proc senderEnsVerified*(self: MessageItem): bool {.slot.} = result = ?.self.messageItem.senderEnsVerified
QtProperty[bool] senderEnsVerified: QtProperty[bool] senderEnsVerified:

View File

@ -12,7 +12,7 @@ type
ResponseToMessageWithId ResponseToMessageWithId
SenderId SenderId
SenderDisplayName SenderDisplayName
SenderLocalName SenderOptionalName
SenderIcon SenderIcon
AmISender AmISender
SenderIsAdded SenderIsAdded
@ -89,7 +89,7 @@ QtObject:
ModelRole.ResponseToMessageWithId.int:"responseToMessageWithId", ModelRole.ResponseToMessageWithId.int:"responseToMessageWithId",
ModelRole.SenderId.int:"senderId", ModelRole.SenderId.int:"senderId",
ModelRole.SenderDisplayName.int:"senderDisplayName", ModelRole.SenderDisplayName.int:"senderDisplayName",
ModelRole.SenderLocalName.int:"senderLocalName", ModelRole.SenderOptionalName.int:"senderOptionalName",
ModelRole.SenderIcon.int:"senderIcon", ModelRole.SenderIcon.int:"senderIcon",
ModelRole.AmISender.int:"amISender", ModelRole.AmISender.int:"amISender",
ModelRole.SenderIsAdded.int:"senderIsAdded", ModelRole.SenderIsAdded.int:"senderIsAdded",
@ -150,8 +150,8 @@ QtObject:
result = newQVariant(item.senderDisplayName) result = newQVariant(item.senderDisplayName)
of ModelRole.SenderTrustStatus: of ModelRole.SenderTrustStatus:
result = newQVariant(item.senderTrustStatus.int) result = newQVariant(item.senderTrustStatus.int)
of ModelRole.SenderLocalName: of ModelRole.SenderOptionalName:
result = newQVariant(item.senderLocalName) result = newQVariant(item.senderOptionalName)
of ModelRole.SenderIcon: of ModelRole.SenderIcon:
result = newQVariant(item.senderIcon) result = newQVariant(item.senderIcon)
of ModelRole.AmISender: of ModelRole.AmISender:
@ -401,7 +401,7 @@ QtObject:
var roles: seq[int] var roles: seq[int]
if(self.items[i].senderId == contactId): if(self.items[i].senderId == contactId):
roles = @[ModelRole.SenderDisplayName.int, roles = @[ModelRole.SenderDisplayName.int,
ModelRole.SenderLocalName.int, ModelRole.SenderOptionalName.int,
ModelRole.SenderIcon.int, ModelRole.SenderIcon.int,
ModelRole.SenderIsAdded.int, ModelRole.SenderIsAdded.int,
ModelRole.SenderTrustStatus.int, ModelRole.SenderTrustStatus.int,

View File

@ -11,10 +11,10 @@ proc replaceMentionsWithPubKeys*(allKnownContacts: seq[ContactsDto], message: st
let nameMentions = findAll(message, namePattern) let nameMentions = findAll(message, namePattern)
var updatedMessage = message var updatedMessage = message
# In the following lines we're free to compare to `x.userNameOrAlias()` cause that's actually what we're displaying # In the following lines we're free to compare to `x.userDefaultDisplayName()` cause that's actually what we're displaying
# in the mentions suggestion list. # in the mentions suggestion list.
for mention in aliasMentions: for mention in aliasMentions:
let listOfMatched = allKnownContacts.filter(x => "@" & x.userNameOrAlias().toLowerAscii == mention.toLowerAscii) let listOfMatched = allKnownContacts.filter(x => "@" & x.userDefaultDisplayName().toLowerAscii == mention.toLowerAscii)
if(listOfMatched.len > 0): if(listOfMatched.len > 0):
updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id) updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id)
@ -24,8 +24,8 @@ proc replaceMentionsWithPubKeys*(allKnownContacts: seq[ContactsDto], message: st
updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id) updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id)
for mention in nameMentions: for mention in nameMentions:
let listOfMatched = allKnownContacts.filter(x => x.userNameOrAlias().toLowerAscii == mention.toLowerAscii or let listOfMatched = allKnownContacts.filter(x => x.userDefaultDisplayName().toLowerAscii == mention.toLowerAscii or
"@" & x.userNameOrAlias().toLowerAscii == mention.toLowerAscii) "@" & x.userDefaultDisplayName().toLowerAscii == mention.toLowerAscii)
if(listOfMatched.len > 0): if(listOfMatched.len > 0):
updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id) updatedMessage = updatedMessage.replaceWord(mention, '@' & listOfMatched[0].id)
return updatedMessage return updatedMessage

View File

@ -6,7 +6,8 @@ export contacts
type type
ContactDetails* = object ContactDetails* = object
displayName*: string defaultDisplayName*: string
optionalName*: string
icon*: string icon*: string
isCurrentUser*: bool isCurrentUser*: bool
colorId*: int colorId*: int

View File

@ -149,16 +149,24 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
discard jsonObj.getProp("IsSyncing", result.isSyncing) discard jsonObj.getProp("IsSyncing", result.isSyncing)
discard jsonObj.getProp("Removed", result.removed) discard jsonObj.getProp("Removed", result.removed)
proc userNameOrAlias*(contact: ContactsDto): string = proc userExtractedName(contact: ContactsDto): string =
if(contact.localNickname.len > 0): if(contact.name.len > 0 and contact.ensVerified):
result = contact.localNickname
elif(contact.name.len > 0 and contact.ensVerified):
result = prettyEnsName(contact.name) result = prettyEnsName(contact.name)
elif contact.displayName.len > 0: elif contact.displayName.len > 0:
result = contact.displayName result = contact.displayName
else: else:
result = contact.alias result = contact.alias
proc userDefaultDisplayName*(contact: ContactsDto): string =
if(contact.localNickname.len > 0):
result = contact.localNickname
else:
result = userExtractedName(contact)
proc userOptionalName*(contact: ContactsDto): string =
if(contact.localNickname.len > 0):
result = userExtractedName(contact)
proc isContactRequestReceived*(self: ContactsDto): bool = proc isContactRequestReceived*(self: ContactsDto): bool =
return self.hasAddedUs return self.hasAddedUs

View File

@ -351,17 +351,23 @@ QtObject:
return self.contactsStatus[publicKey] return self.contactsStatus[publicKey]
proc getContactNameAndImage*(self: Service, publicKey: string): proc getContactNameAndImageInternal(self: Service, publicKey: string):
tuple[name: string, image: string, largeImage: string] = tuple[name: string, optionalName: string, image: string, largeImage: string] =
## This proc should be used accross the app in order to have for the same contact ## This proc should be used accross the app in order to have for the same contact
## same image and name displayed everywhere in the app. ## same image and name displayed everywhere in the app.
let contactDto = self.getContactById(publicKey) let contactDto = self.getContactById(publicKey)
result.name = contactDto.userNameOrAlias() result.name = contactDto.userDefaultDisplayName()
result.optionalName = contactDto.userOptionalName()
if(contactDto.image.thumbnail.len > 0): if(contactDto.image.thumbnail.len > 0):
result.image = contactDto.image.thumbnail result.image = contactDto.image.thumbnail
if(contactDto.image.large.len > 0): if(contactDto.image.large.len > 0):
result.largeImage = contactDto.image.large result.largeImage = contactDto.image.large
proc getContactNameAndImage*(self: Service, publicKey: string):
tuple[name: string, image: string, largeImage: string] =
let tempRes = self.getContactNameAndImageInternal(publicKey)
return (tempRes.name, tempRes.image, tempRes.largeImage)
proc saveContact(self: Service, contact: ContactsDto) = proc saveContact(self: Service, contact: ContactsDto) =
# we must keep local contacts updated # we must keep local contacts updated
self.contacts[contact.id] = contact self.contacts[contact.id] = contact
@ -513,8 +519,9 @@ QtObject:
proc getContactDetails*(self: Service, pubKey: string): ContactDetails = proc getContactDetails*(self: Service, pubKey: string): ContactDetails =
result = ContactDetails() result = ContactDetails()
let (name, icon, _) = self.getContactNameAndImage(pubKey) let (name, optionalName, icon, _) = self.getContactNameAndImageInternal(pubKey)
result.displayName = name result.defaultDisplayName = name
result.optionalName = optionalName
result.icon = icon result.icon = icon
result.colorId = procs_from_visual_identity_service.colorIdOf(pubKey) result.colorId = procs_from_visual_identity_service.colorIdOf(pubKey)
result.isCurrentUser = pubKey == singletonInstance.userProfile.getPubKey() result.isCurrentUser = pubKey == singletonInstance.userProfile.getPubKey()

View File

@ -687,7 +687,7 @@ proc renderInline(self: Service, parsedText: ParsedText): string =
if isCompressedPubKey(id): if isCompressedPubKey(id):
id = status_accounts.decompressPk(id).result id = status_accounts.decompressPk(id).result
let contactDto = self.contactService.getContactById(id) let contactDto = self.contactService.getContactById(id)
result = fmt("<a href=\"//{id}\" class=\"mention\">{contactDto.userNameOrAlias()}</a>") result = fmt("<a href=\"//{id}\" class=\"mention\">{contactDto.userDefaultDisplayName()}</a>")
of PARSED_TEXT_CHILD_TYPE_STATUS_TAG: of PARSED_TEXT_CHILD_TYPE_STATUS_TAG:
result = fmt("<a href=\"#{value}\" class=\"status-tag\">#{value}</a>") result = fmt("<a href=\"#{value}\" class=\"status-tag\">#{value}</a>")
of PARSED_TEXT_CHILD_TYPE_DEL: of PARSED_TEXT_CHILD_TYPE_DEL:

View File

@ -72,8 +72,8 @@ StatusDialog {
responseToMessageWithId: model.responseToMessageWithId responseToMessageWithId: model.responseToMessageWithId
senderId: model.senderId senderId: model.senderId
senderDisplayName: model.senderDisplayName senderDisplayName: model.senderDisplayName
senderLocalName: model.senderLocalName senderOptionalName: model.senderOptionalName
senderEnsName: model.senderEnsVerified ? model.senderDisplayName : "" senderIsEnsVerified: model.senderEnsVerified
senderIcon: model.senderIcon senderIcon: model.senderIcon
amISender: model.amISender amISender: model.amISender
messageText: model.messageText messageText: model.messageText

View File

@ -275,8 +275,8 @@ Item {
responseToMessageWithId: model.responseToMessageWithId responseToMessageWithId: model.responseToMessageWithId
senderId: model.senderId senderId: model.senderId
senderDisplayName: model.senderDisplayName senderDisplayName: model.senderDisplayName
senderLocalName: model.senderLocalName senderOptionalName: model.senderOptionalName
senderEnsName: model.senderEnsVerified ? model.senderDisplayName : "" senderIsEnsVerified: model.senderEnsVerified
senderIcon: model.senderIcon senderIcon: model.senderIcon
senderIsAdded: model.senderIsAdded senderIsAdded: model.senderIsAdded
amISender: model.amISender amISender: model.amISender

View File

@ -130,7 +130,8 @@ Item {
messageText: model.message.messageText messageText: model.message.messageText
responseToMessageWithId: model.message.responseToMessageWithId responseToMessageWithId: model.message.responseToMessageWithId
senderId: model.message.senderId senderId: model.message.senderId
senderLocalName: model.message.senderLocalName senderOptionalName: model.message.senderOptionalName
senderIsEnsVerified: model.message.senderEnsVerified
senderIcon: model.message.senderIcon senderIcon: model.message.senderIcon
amISender: model.message.amISender amISender: model.message.amISender
messageImage: model.message.messageImage messageImage: model.message.messageImage

View File

@ -39,8 +39,8 @@ Loader {
property string responseToMessageWithId: "" property string responseToMessageWithId: ""
property string senderId: "" property string senderId: ""
property string senderDisplayName: "" property string senderDisplayName: ""
property string senderLocalName: "" property string senderOptionalName: ""
property string senderEnsName: "" property bool senderIsEnsVerified: false
property string senderIcon: "" property string senderIcon: ""
property bool amISender: false property bool amISender: false
property bool senderIsAdded: false property bool senderIsAdded: false
@ -542,9 +542,9 @@ Loader {
amISender: root.amISender amISender: root.amISender
sender.id: root.senderId sender.id: root.senderId
sender.userName: root.senderDisplayName sender.displayName: root.senderDisplayName
sender.localName: root.senderLocalName sender.secondaryName: root.senderOptionalName
sender.ensName: root.senderEnsName sender.isEnsVerified: root.senderIsEnsVerified
sender.isContact: root.senderIsAdded sender.isContact: root.senderIsAdded
sender.trustIndicator: root.senderTrustStatus sender.trustIndicator: root.senderTrustStatus
sender.profileImage { sender.profileImage {
@ -575,9 +575,9 @@ Loader {
amISender: delegate.replyMessage && delegate.replyMessage.amISender amISender: delegate.replyMessage && delegate.replyMessage.amISender
sender.id: delegate.replyMessage ? delegate.replyMessage.senderId : "" sender.id: delegate.replyMessage ? delegate.replyMessage.senderId : ""
sender.isContact: delegate.replyMessage && delegate.replyMessage.senderIsAdded sender.isContact: delegate.replyMessage && delegate.replyMessage.senderIsAdded
sender.userName: delegate.replyMessage ? delegate.replyMessage.senderDisplayName: "" sender.displayName: delegate.replyMessage ? delegate.replyMessage.senderDisplayName: ""
sender.ensName: delegate.replyMessage && delegate.replyMessage.ensVerified ? delegate.replyMessage.senderDisplayName : "" sender.isEnsVerified: delegate.replyMessage && delegate.replyMessage.senderEnsVerified
sender.localName: delegate.replyMessage ? delegate.replyMessage.senderLocalName : "" sender.secondaryName: delegate.replyMessage ? delegate.replyMessage.senderOptionalName : ""
sender.profileImage { sender.profileImage {
width: 20 width: 20
height: 20 height: 20