fix(@desktop/contacts): Keep only one contacts list

fixes #3485
This commit is contained in:
Anthony Laibe 2021-09-16 15:17:55 +02:00 committed by Iuri Matias
parent 6625ae38be
commit d804e15f27
13 changed files with 46 additions and 42 deletions

View File

@ -42,7 +42,6 @@ proc handleChatEvents(self: ChatController) =
self.status.events.on("chatUpdate") do(e: Args):
var evArgs = ChatUpdateArgs(e)
self.view.hideLoadingIndicator()
self.view.updateUsernames(evArgs.contacts)
self.view.updateChats(evArgs.chats)
self.view.pushMessages(evArgs.messages)
self.view.pushMembers(evArgs.chats)

View File

@ -217,8 +217,8 @@ QtObject:
generateAlias(pubKey)
proc userNameOrAlias*(self: ChatsView, pubKey: string): string {.slot.} =
if self.status.chat.contacts.hasKey(pubKey):
return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey])
if self.status.chat.getContacts().hasKey(pubKey):
return status_ens.userNameOrAlias(self.status.chat.getContacts()[pubKey])
generateAlias(pubKey)
proc activityNotificationsChanged*(self: ChatsView) {.signal.}

View File

@ -110,8 +110,8 @@ QtObject:
self.chats.clearAllMentionsFromChannelWithId(channel.id)
proc userNameOrAlias(self: ChannelView, pubKey: string): string =
if self.status.chat.contacts.hasKey(pubKey):
return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey])
if self.status.chat.getContacts().hasKey(pubKey):
return status_ens.userNameOrAlias(self.status.chat.getContacts()[pubKey])
generateAlias(pubKey)
proc setActiveChannelByIndexWithForce*(self: ChannelView, index: int, forceUpdate: bool) {.slot.} =

View File

@ -64,14 +64,14 @@ QtObject:
proc contactsUpdated*(self: ChatItemView) {.signal}
proc userNameOrAlias(self: ChatItemView, pubKey: string): string {.slot.} =
if self.status.chat.contacts.hasKey(pubKey):
return ens.userNameOrAlias(self.status.chat.contacts[pubKey])
if self.status.chat.getContacts().hasKey(pubKey):
return ens.userNameOrAlias(self.status.chat.getContacts()[pubKey])
generateAlias(pubKey)
proc name*(self: ChatItemView): string {.slot.} =
if self.chatItem != nil and self.chatItem.chatType.isOneToOne:
if self.status.chat.contacts.hasKey(self.chatItem.id) and self.status.chat.contacts[self.chatItem.id].hasNickname():
return self.status.chat.contacts[self.chatItem.id].localNickname
if self.status.chat.getContacts().hasKey(self.chatItem.id) and self.status.chat.getContacts()[self.chatItem.id].hasNickname():
return self.status.chat.getContacts()[self.chatItem.id].localNickname
let username = self.userNameOrAlias(self.chatItem.id)
if username != "":
result = username.userName(true)
@ -87,8 +87,8 @@ QtObject:
proc nickname*(self: ChatItemView): string {.slot.} =
if self.chatItem != nil and self.chatItem.chatType.isOneToOne:
if self.status.chat.contacts.hasKey(self.chatItem.id) and self.status.chat.contacts[self.chatItem.id].hasNickname():
return self.status.chat.contacts[self.chatItem.id].localNickname
if self.status.chat.getContacts().hasKey(self.chatItem.id) and self.status.chat.getContacts()[self.chatItem.id].hasNickname():
return self.status.chat.getContacts()[self.chatItem.id].localNickname
result = ""
QtProperty[string] nickname:
@ -98,8 +98,8 @@ QtObject:
proc ensVerified*(self: ChatItemView): bool {.slot.} =
if self.chatItem != nil and
self.chatItem.chatType.isOneToOne and
self.status.chat.contacts.hasKey(self.chatItem.id):
return self.status.chat.contacts[self.chatItem.id].ensVerified
self.status.chat.getContacts().hasKey(self.chatItem.id):
return self.status.chat.getContacts()[self.chatItem.id].ensVerified
result = false
QtProperty[bool] ensVerified:
@ -109,8 +109,8 @@ QtObject:
proc alias*(self: ChatItemView): string {.slot.} =
if self.chatItem != nil and
self.chatItem.chatType.isOneToOne and
self.status.chat.contacts.hasKey(self.chatItem.id):
return self.status.chat.contacts[self.chatItem.id].alias
self.status.chat.getContacts().hasKey(self.chatItem.id):
return self.status.chat.getContacts()[self.chatItem.id].alias
result = ""
QtProperty[string] alias:

View File

@ -35,8 +35,8 @@ QtObject:
method rowCount(self: ChatMembersView, index: QModelIndex = nil): int = self.members.len
proc userName(self: ChatMembersView, id: string, alias: string): string =
if self.status.chat.contacts.hasKey(id):
result = ens.userNameOrAlias(self.status.chat.contacts[id])
if self.status.chat.getContacts().hasKey(id):
result = ens.userNameOrAlias(self.status.chat.getContacts()[id])
else:
result = alias

View File

@ -55,29 +55,34 @@ QtObject:
self.community.members.len
proc userName(self: CommunityMembersView, pk: string, alias: string): string =
if self.status.chat.contacts.hasKey(pk):
if self.status.chat.contacts[pk].localNickname != "":
result = self.status.chat.contacts[pk].localNickname
let contacts = self.status.chat.getContacts()
if contacts.hasKey(pk):
if contacts[pk].localNickname != "":
result = contacts[pk].localNickname
else:
result = ens.userNameOrAlias(self.status.chat.contacts[pk])
result = ens.userNameOrAlias(contacts[pk])
else:
result = alias
proc identicon(self: CommunityMembersView, pk: string): string =
if self.status.chat.contacts.hasKey(pk):
result = self.status.chat.contacts[pk].identicon
let contacts = self.status.chat.getContacts()
if contacts.hasKey(pk):
result = contacts[pk].identicon
else:
result = self.status.accounts.generateIdenticon(pk)
proc alias(self: CommunityMembersView, pk: string): string =
if self.status.chat.contacts.hasKey(pk):
result = self.status.chat.contacts[pk].alias
let contacts = self.status.chat.getContacts()
if contacts.hasKey(pk):
result = contacts[pk].alias
else:
result = self.status.accounts.generateAlias(pk)
proc localNickname(self: CommunityMembersView, pk: string): string =
if self.status.chat.contacts.hasKey(pk):
result = self.status.chat.contacts[pk].localNickname
let contacts = self.status.chat.getContacts()
if contacts.hasKey(pk):
result = contacts[pk].localNickname
proc memberLastSeen(self: CommunityMembersView, pk: string): string =
if self.community.memberStatus.hasKey(pk):

View File

@ -37,7 +37,7 @@ QtObject:
QtProperty[string] userName:
read = userName
proc message*(self: MessageItem): string {.slot.} = result = renderBlock(self.messageItem, self.status.chat.contacts)
proc message*(self: MessageItem): string {.slot.} = result = renderBlock(self.messageItem, self.status.chat.getContacts())
QtProperty[string] message:
read = message

View File

@ -219,7 +219,7 @@ QtObject:
let isEdited = if self.isEdited.hasKey(message.id): self.isEdited[message.id] else: false
case chatMessageRole:
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
of ChatMessageRoles.Message: result = newQVariant(renderBlock(message, self.status.chat.contacts))
of ChatMessageRoles.Message: result = newQVariant(renderBlock(message, self.status.chat.getContacts()))
of ChatMessageRoles.PlainText: result = newQVariant(message.text)
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
of ChatMessageRoles.Clock: result = newQVariant($message.clock)
@ -316,7 +316,7 @@ QtObject:
of "alias": result = message.alias
of "localName": result = message.localName
of "ensName": result = message.ensName
of "message": result = (renderBlock(message, self.status.chat.contacts))
of "message": result = (renderBlock(message, self.status.chat.getContacts()))
of "identicon": result = message.identicon
of "timestamp": result = $(message.timestamp)
of "image": result = $(message.image)

View File

@ -97,11 +97,11 @@ QtObject:
var identicon: string
var localName: string
if self.status.chat.contacts.hasKey(pk):
userName = ens.userNameOrAlias(self.status.chat.contacts[pk])
alias = self.status.chat.contacts[pk].alias
identicon = self.status.chat.contacts[pk].identicon
localName = self.status.chat.contacts[pk].localNickname
if self.status.chat.getContacts().hasKey(pk):
userName = ens.userNameOrAlias(self.status.chat.getContacts()[pk])
alias = self.status.chat.getContacts()[pk].alias
identicon = self.status.chat.getContacts()[pk].identicon
localName = self.status.chat.getContacts()[pk].localNickname
else:
userName = m.username
alias = m.username

View File

@ -56,7 +56,6 @@ proc init*(self: ProfileController, account: Account) =
profile.currentUserStatus = currentUserStatus
let identityImage = self.status.profile.getIdentityImage(profile.address)
if (identityImage.thumbnail != ""):
profile.identityImage = identityImage
@ -76,7 +75,6 @@ proc init*(self: ProfileController, account: Account) =
self.view.mailservers.add(mailserver)
let contacts = self.status.contacts.getContacts()
self.status.chat.updateContacts(contacts)
self.view.contacts.setContactList(contacts)
self.status.events.on("channelLoaded") do(e: Args):
@ -129,8 +127,8 @@ proc init*(self: ProfileController, account: Account) =
let msgData = MessageSignal(e);
if msgData.contacts.len > 0:
# TODO: view should react to model changes
self.view.contacts.updateContactList(msgData.contacts)
self.status.chat.updateContacts(msgData.contacts)
let contacts = self.status.contacts.getContacts(false)
self.view.contacts.updateContactList(contacts)
if msgData.installations.len > 0:
self.view.devices.addDevices(msgData.installations)

View File

@ -82,6 +82,7 @@ QtObject:
proc setNewProfile*(self: ProfileView, profile: Profile) =
self.profile.setProfile(profile)
self.contacts.accountKeyUID = profile.address
self.profileChanged()
QtProperty[QVariant] profile:

View File

@ -40,6 +40,7 @@ QtObject:
addedContacts*: ContactList
blockedContacts*: ContactList
contactToAdd*: Profile
accountKeyUID*: string
proc setup(self: ContactsView) =
self.QObject.setup
@ -198,7 +199,7 @@ QtObject:
proc contactChanged(self: ContactsView, publicKey: string, isAdded: bool) {.signal.}
proc addContact*(self: ContactsView, publicKey: string): string {.slot.} =
result = self.status.contacts.addContact(publicKey)
result = self.status.contacts.addContact(publicKey, self.accountKeyUID)
self.status.chat.join(status_utils.getTimelineChatId(publicKey), ChatType.Profile, "", publicKey)
self.contactChanged(publicKey, true)
@ -219,7 +220,7 @@ QtObject:
var nicknameToSet = nickname
if (nicknameToSet == ""):
nicknameToSet = DELETE_CONTACT
discard self.status.contacts.setNickName(publicKey, nicknameToSet)
discard self.status.contacts.setNickName(publicKey, nicknameToSet, self.accountKeyUID)
proc unblockContact*(self: ContactsView, publicKey: string) {.slot.} =
self.contactListChanged()

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit 3655396b572e389a7e4b7e1d2311afa90514ad98
Subproject commit 20ca77ac009e4b1bab432a4cc5d5e8cfb85a2e70