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): self.status.events.on("chatUpdate") do(e: Args):
var evArgs = ChatUpdateArgs(e) var evArgs = ChatUpdateArgs(e)
self.view.hideLoadingIndicator() self.view.hideLoadingIndicator()
self.view.updateUsernames(evArgs.contacts)
self.view.updateChats(evArgs.chats) self.view.updateChats(evArgs.chats)
self.view.pushMessages(evArgs.messages) self.view.pushMessages(evArgs.messages)
self.view.pushMembers(evArgs.chats) self.view.pushMembers(evArgs.chats)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ QtObject:
QtProperty[string] userName: QtProperty[string] userName:
read = 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: QtProperty[string] message:
read = message read = message

View File

@ -219,7 +219,7 @@ QtObject:
let isEdited = if self.isEdited.hasKey(message.id): self.isEdited[message.id] else: false let isEdited = if self.isEdited.hasKey(message.id): self.isEdited[message.id] else: false
case chatMessageRole: case chatMessageRole:
of ChatMessageRoles.UserName: result = newQVariant(message.userName) 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.PlainText: result = newQVariant(message.text)
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp) of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
of ChatMessageRoles.Clock: result = newQVariant($message.clock) of ChatMessageRoles.Clock: result = newQVariant($message.clock)
@ -316,7 +316,7 @@ QtObject:
of "alias": result = message.alias of "alias": result = message.alias
of "localName": result = message.localName of "localName": result = message.localName
of "ensName": result = message.ensName 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 "identicon": result = message.identicon
of "timestamp": result = $(message.timestamp) of "timestamp": result = $(message.timestamp)
of "image": result = $(message.image) of "image": result = $(message.image)

View File

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

View File

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

View File

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

View File

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

2
vendor/status-lib vendored

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