fix: manage contacts without systemTag

This commit is contained in:
Richard Ramos 2020-06-22 08:16:44 -04:00 committed by Iuri Matias
parent af2584c53c
commit 33b3c4dc97
9 changed files with 31 additions and 13 deletions

View File

@ -10,6 +10,7 @@ type
Name = UserRole + 2,
Address = UserRole + 3
Identicon = UserRole + 4
IsContact = UserRole + 5
QtObject:
type ContactList* = ref object of QAbstractListModel
@ -45,6 +46,7 @@ QtObject:
of "address": result = contact.address
of "identicon": result = contact.identicon
of "pubKey": result = contact.id
of "isContact": result = $contact.isContact()
method data(self: ContactList, index: QModelIndex, role: int): QVariant =
if not index.isValid:
@ -57,13 +59,15 @@ QtObject:
of ContactRoles.Address: result = newQVariant(contact.address)
of ContactRoles.Identicon: result = newQVariant(contact.identicon)
of ContactRoles.PubKey: result = newQVariant(contact.id)
of ContactRoles.IsContact: result = newQVariant(contact.isContact())
method roleNames(self: ContactList): Table[int, string] =
{
ContactRoles.Name.int:"name",
ContactRoles.Address.int:"address",
ContactRoles.Identicon.int:"identicon",
ContactRoles.PubKey.int:"pubKey"
ContactRoles.PubKey.int:"pubKey",
ContactRoles.IsContact.int:"isContact"
}.toTable
proc addContactToList*(self: ContactList, contact: Profile) =

View File

@ -26,19 +26,19 @@ proc blockContact*(self: ContactModel, id: string): string =
status_contacts.blockContact(contact)
proc getContacts*(self: ContactModel): seq[Profile] =
result = map(status_contacts.getContacts().getElems(), proc(x: JsonNode): Profile = x.toProfileModel()).filterIt(it.systemTags.contains(":contact/added"))
result = map(status_contacts.getContacts().getElems(), proc(x: JsonNode): Profile = x.toProfileModel())
self.events.emit("contactUpdate", ContactUpdateArgs(contacts: result))
proc addContact*(self: ContactModel, id: string): string =
let contact = self.getContactByID(id)
contact.systemTags.add(":contact/added")
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags)
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags)
self.events.emit("contactAdded", Args())
proc removeContact*(self: ContactModel, id: string) =
let contact = self.getContactByID(id)
contact.systemTags.delete(contact.systemTags.find(":contact/added"))
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags)
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags)
self.events.emit("contactRemoved", Args())
proc isAdded*(self: ContactModel, id: string): bool =

View File

@ -13,7 +13,7 @@ proc userName*(ensName: string, removeSuffix: bool = false): string =
result = ensName
proc userNameOrAlias*(contact: Profile): string =
if(contact.ensName != "" and contact.ensVerified):
result = "@" & userName(contact.ensName, true)
else:
result = contact.alias
if(contact.ensName != "" and contact.ensVerified):
result = "@" & userName(contact.ensName, true)
else:
result = contact.alias

View File

@ -27,9 +27,10 @@ proc getContacts*(): JsonNode =
return %* []
return response["result"]
proc saveContact*(id: string, ensVerified: bool, ensVerifiedAt: int, ensVerificationRetries: int, alias: string, identicon: string, systemTags: seq[string]): string =
proc saveContact*(id: string, ensVerified: bool, ensName: string, ensVerifiedAt: int, ensVerificationRetries: int, alias: string, identicon: string, systemTags: seq[string]): string =
let payload = %* [{
"id": id,
"name": ensName,
"ensVerified": ensVerified,
"ensVerifiedAt": ensVerifiedAt,
"ensVerificationRetries": ensVerificationRetries,

View File

@ -8,6 +8,12 @@ type Profile* = ref object
ensVerificationRetries*: int
systemTags*: seq[string]
proc isContact*(self: Profile): bool =
result = self.systemTags.contains(":contact/added") and not self.systemTags.contains(":contact/blocked")
proc isBlocked*(self: Profile): bool =
result = self.systemTags.contains(":contact/blocked")
proc toProfileModel*(account: Account): Profile =
result = Profile(
id: "",
@ -38,5 +44,6 @@ proc toProfileModel*(profile: JsonNode): Profile =
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
systemTags: systemTags
)
if profile.hasKey("name"):
result.ensName = profile["name"].str

View File

@ -11,6 +11,7 @@ Rectangle {
property string address: "0x04d8c07dd137bd1b73a6f51df148b4f77ddaa11209d36e43d8344c0a7d6db1cad6085f27cfb75dd3ae21d86ceffebe4cf8a35b9ce8d26baa19dc264efe6d8f221b"
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
property bool isContact: true
property bool isUser: false
property bool isVisible: true
@ -19,8 +20,8 @@ Rectangle {
property var onItemChecked: (function(pubKey, itemChecked) { console.log(pubKey, itemChecked) })
visible: isVisible
height: isVisible ? 64 : 0
visible: isVisible && (isContact || isUser)
height: visible ? 64 : 0
anchors.right: parent.right
anchors.left: parent.left
border.width: 0

View File

@ -34,7 +34,8 @@ ModalPopup {
pubKey: profileModel.contactList.rowData(i, "pubKey"),
address: profileModel.contactList.rowData(i, "address"),
identicon: profileModel.contactList.rowData(i, "identicon"),
isUser: false
isUser: false,
isContact: profileModel.contactList.rowData(i, "isContact") !== "false"
});
}
data.append({
@ -117,6 +118,7 @@ ModalPopup {
}
showCheckbox: selectChatMembers && memberCount < maxMembers
pubKey: model.pubKey
isContact: model.isContact
isUser: model.isUser
name: model.name
address: model.address

View File

@ -10,8 +10,10 @@ Rectangle {
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
property bool selectable: false
property var profileClick: function() {}
property bool isContact: true
height: 64
visible: isContact
height: visible ? 64 : 0
anchors.right: parent.right
anchors.left: parent.left
border.width: 0

View File

@ -22,6 +22,7 @@ ListView {
name: model.name
address: model.address
identicon: model.identicon
isContact: model.isContact
selectable: contactList.selectable
profileClick: profilePopup.openPopup.bind(profilePopup)
}