fix add contact and update contact list in the UI when a new contact is added

This commit is contained in:
Iuri Matias 2020-06-18 12:38:30 -04:00
parent a128dc4bf5
commit 71cbffea28
6 changed files with 28 additions and 17 deletions

View File

@ -1,5 +1,5 @@
import NimQml import NimQml
import json import json, eventemitter
import ../../status/libstatus/mailservers as status_mailservers import ../../status/libstatus/mailservers as status_mailservers
import ../../signals/types import ../../signals/types
import "../../status/libstatus/types" as status_types import "../../status/libstatus/types" as status_types
@ -44,8 +44,11 @@ proc init*(self: ProfileController, account: Account) =
let contacts = self.status.contacts.getContacts() let contacts = self.status.contacts.getContacts()
self.status.chat.updateContacts(contacts) self.status.chat.updateContacts(contacts)
for contact in contacts: self.view.setContactList(contacts)
self.view.addContactToList(contact)
self.status.events.on("contactAdded") do(e: Args):
let contacts = self.status.contacts.getContacts()
self.view.setContactList(contacts)
method onSignal(self: ProfileController, data: Signal) = method onSignal(self: ProfileController, data: Signal) =
let msgData = MessageSignal(data); let msgData = MessageSignal(data);
@ -53,4 +56,3 @@ method onSignal(self: ProfileController, data: Signal) =
# TODO: view should react to model changes # TODO: view should react to model changes
self.status.chat.updateContacts(msgData.contacts) self.status.chat.updateContacts(msgData.contacts)
self.view.updateContactList(msgData.contacts) self.view.updateContactList(msgData.contacts)

View File

@ -42,15 +42,20 @@ QtObject:
proc updateContactList*(self: ProfileView, contacts: seq[Profile]) = proc updateContactList*(self: ProfileView, contacts: seq[Profile]) =
for contact in contacts: for contact in contacts:
self.contactList.updateContact(contact) self.contactList.updateContact(contact)
proc addContactToList*(self: ProfileView, contact: Profile) = proc contactListChanged*(self: ProfileView) {.signal.}
self.contactList.addContactToList(contact)
proc getContactList(self: ProfileView): QVariant {.slot.} = proc getContactList(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.contactList) return newQVariant(self.contactList)
proc setContactList*(self: ProfileView, contactList: seq[Profile]) =
self.contactList.setNewData(contactList)
self.contactListChanged()
QtProperty[QVariant] contactList: QtProperty[QVariant] contactList:
read = getContactList read = getContactList
write = setContactList
notify = contactListChanged
proc getProfile(self: ProfileView): QVariant {.slot.} = proc getProfile(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.profile) return newQVariant(self.profile)

View File

@ -83,6 +83,8 @@ QtObject:
self.addContactToList(contact) self.addContactToList(contact)
else: else:
self.dataChanged(topLeft, bottomRight, @[ContactRoles.Name.int]) self.dataChanged(topLeft, bottomRight, @[ContactRoles.Name.int])
proc setNewData*(self: ContactList, contactList: seq[Profile]) =
self.beginResetModel()
self.contacts = contactList
self.endResetModel()

View File

@ -31,4 +31,6 @@ proc getContacts*(self: ContactModel): seq[Profile] =
proc addContact*(self: ContactModel, id: string): string = proc addContact*(self: ContactModel, id: string): string =
let contact = self.getContactByID(id) let contact = self.getContactByID(id)
status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags) contact.systemTags.add(":contact/added")
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags)
self.events.emit("contactAdded", Args())

View File

@ -18,11 +18,11 @@ proc blockContact*(contact: Profile): string =
]) ])
proc getContactByID*(id: string): string = proc getContactByID*(id: string): string =
callPrivateRPC("getContactByID".prefix, %* [id]) result = callPrivateRPC("getContactByID".prefix, %* [id])
proc getContacts*(): JsonNode = proc getContacts*(): JsonNode =
let payload = %* [] let payload = %* []
let response = callPrivateRPC("wakuext_contacts", payload).parseJson let response = callPrivateRPC("contacts".prefix, payload).parseJson
if response["result"].kind == JNull: if response["result"].kind == JNull:
return %* [] return %* []
return response["result"] return response["result"]
@ -37,4 +37,4 @@ proc saveContact*(id: string, ensVerified: bool, ensVerifiedAt: int, ensVerifica
"identicon": identicon, "identicon": identicon,
"systemTags": systemTags "systemTags": systemTags
}] }]
callPrivateRPC("shhext_saveContact", payload) callPrivateRPC("saveContact".prefix, payload)

View File

@ -1,6 +1,5 @@
import ../libstatus/types
import json import json
import ../libstatus/types
type Profile* = ref object type Profile* = ref object
id*, alias*, username*, identicon*, address*, ensName*: string id*, alias*, username*, identicon*, address*, ensName*: string
@ -33,9 +32,10 @@ proc toProfileModel*(profile: JsonNode): Profile =
identicon: profile["identicon"].str, identicon: profile["identicon"].str,
address: profile["id"].str, address: profile["id"].str,
alias: profile["alias"].str, alias: profile["alias"].str,
ensName: profile["name"].str, # ensName: profile["name"].str, // doesn't seems to exist
ensName: "",
ensVerified: profile["ensVerified"].getBool, ensVerified: profile["ensVerified"].getBool,
ensVerifiedAt: profile["ensVerifiedAt"].getInt, ensVerifiedAt: profile["ensVerifiedAt"].getInt,
ensVerificationRetries: profile["ensVerificationRetries"].getInt, ensVerificationRetries: profile["ensVerificationRetries"].getInt,
systemTags: systemTags systemTags: systemTags
) )