fix add contact and update contact list in the UI when a new contact is added
This commit is contained in:
parent
a128dc4bf5
commit
71cbffea28
|
@ -1,5 +1,5 @@
|
|||
import NimQml
|
||||
import json
|
||||
import json, eventemitter
|
||||
import ../../status/libstatus/mailservers as status_mailservers
|
||||
import ../../signals/types
|
||||
import "../../status/libstatus/types" as status_types
|
||||
|
@ -44,8 +44,11 @@ proc init*(self: ProfileController, account: Account) =
|
|||
|
||||
let contacts = self.status.contacts.getContacts()
|
||||
self.status.chat.updateContacts(contacts)
|
||||
for contact in contacts:
|
||||
self.view.addContactToList(contact)
|
||||
self.view.setContactList(contacts)
|
||||
|
||||
self.status.events.on("contactAdded") do(e: Args):
|
||||
let contacts = self.status.contacts.getContacts()
|
||||
self.view.setContactList(contacts)
|
||||
|
||||
method onSignal(self: ProfileController, data: Signal) =
|
||||
let msgData = MessageSignal(data);
|
||||
|
@ -53,4 +56,3 @@ method onSignal(self: ProfileController, data: Signal) =
|
|||
# TODO: view should react to model changes
|
||||
self.status.chat.updateContacts(msgData.contacts)
|
||||
self.view.updateContactList(msgData.contacts)
|
||||
|
||||
|
|
|
@ -42,15 +42,20 @@ QtObject:
|
|||
proc updateContactList*(self: ProfileView, contacts: seq[Profile]) =
|
||||
for contact in contacts:
|
||||
self.contactList.updateContact(contact)
|
||||
|
||||
proc addContactToList*(self: ProfileView, contact: Profile) =
|
||||
self.contactList.addContactToList(contact)
|
||||
|
||||
proc contactListChanged*(self: ProfileView) {.signal.}
|
||||
|
||||
proc getContactList(self: ProfileView): QVariant {.slot.} =
|
||||
return newQVariant(self.contactList)
|
||||
|
||||
proc setContactList*(self: ProfileView, contactList: seq[Profile]) =
|
||||
self.contactList.setNewData(contactList)
|
||||
self.contactListChanged()
|
||||
|
||||
QtProperty[QVariant] contactList:
|
||||
read = getContactList
|
||||
write = setContactList
|
||||
notify = contactListChanged
|
||||
|
||||
proc getProfile(self: ProfileView): QVariant {.slot.} =
|
||||
return newQVariant(self.profile)
|
||||
|
|
|
@ -83,6 +83,8 @@ QtObject:
|
|||
self.addContactToList(contact)
|
||||
else:
|
||||
self.dataChanged(topLeft, bottomRight, @[ContactRoles.Name.int])
|
||||
|
||||
|
||||
|
||||
proc setNewData*(self: ContactList, contactList: seq[Profile]) =
|
||||
self.beginResetModel()
|
||||
self.contacts = contactList
|
||||
self.endResetModel()
|
||||
|
|
|
@ -31,4 +31,6 @@ proc getContacts*(self: ContactModel): seq[Profile] =
|
|||
|
||||
proc addContact*(self: ContactModel, id: string): string =
|
||||
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())
|
||||
|
|
|
@ -18,11 +18,11 @@ proc blockContact*(contact: Profile): string =
|
|||
])
|
||||
|
||||
proc getContactByID*(id: string): string =
|
||||
callPrivateRPC("getContactByID".prefix, %* [id])
|
||||
result = callPrivateRPC("getContactByID".prefix, %* [id])
|
||||
|
||||
proc getContacts*(): JsonNode =
|
||||
let payload = %* []
|
||||
let response = callPrivateRPC("wakuext_contacts", payload).parseJson
|
||||
let response = callPrivateRPC("contacts".prefix, payload).parseJson
|
||||
if response["result"].kind == JNull:
|
||||
return %* []
|
||||
return response["result"]
|
||||
|
@ -37,4 +37,4 @@ proc saveContact*(id: string, ensVerified: bool, ensVerifiedAt: int, ensVerifica
|
|||
"identicon": identicon,
|
||||
"systemTags": systemTags
|
||||
}]
|
||||
callPrivateRPC("shhext_saveContact", payload)
|
||||
callPrivateRPC("saveContact".prefix, payload)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
import ../libstatus/types
|
||||
import json
|
||||
import ../libstatus/types
|
||||
|
||||
type Profile* = ref object
|
||||
id*, alias*, username*, identicon*, address*, ensName*: string
|
||||
|
@ -33,9 +32,10 @@ proc toProfileModel*(profile: JsonNode): Profile =
|
|||
identicon: profile["identicon"].str,
|
||||
address: profile["id"].str,
|
||||
alias: profile["alias"].str,
|
||||
ensName: profile["name"].str,
|
||||
# ensName: profile["name"].str, // doesn't seems to exist
|
||||
ensName: "",
|
||||
ensVerified: profile["ensVerified"].getBool,
|
||||
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
|
||||
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
|
||||
systemTags: systemTags
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue