feat: enable setting a nickname to a contact

This commit is contained in:
Jonathan Rainville 2020-09-16 14:50:40 -04:00 committed by Iuri Matias
parent 697ae321d2
commit bc3b7a5533
8 changed files with 44 additions and 23 deletions

View File

@ -280,6 +280,9 @@ QtObject:
proc addContact*(self: ProfileView, pk: string) {.slot.} = proc addContact*(self: ProfileView, pk: string) {.slot.} =
discard self.status.contacts.addContact(pk) discard self.status.contacts.addContact(pk)
proc changeContactNickname*(self: ProfileView, publicKey: string, nickname: string) {.slot.} =
discard self.status.contacts.addContact(publicKey, nickname)
proc unblockContact*(self: ProfileView, id: string) {.slot.} = proc unblockContact*(self: ProfileView, id: string) {.slot.} =
discard self.status.contacts.unblockContact(id) discard self.status.contacts.unblockContact(id)

View File

@ -32,23 +32,31 @@ proc blockContact*(self: ContactModel, id: string): string =
proc unblockContact*(self: ContactModel, id: string): string = proc unblockContact*(self: ContactModel, id: string): string =
var contact = self.getContactByID(id) var contact = self.getContactByID(id)
contact.systemTags.delete(contact.systemTags.find(":contact/blocked")) contact.systemTags.delete(contact.systemTags.find(":contact/blocked"))
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, 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, contact.localNickname)
self.events.emit("contactUnblocked", Args()) self.events.emit("contactUnblocked", Args())
proc getContacts*(self: ContactModel): seq[Profile] = proc getContacts*(self: ContactModel): seq[Profile] =
result = map(status_contacts.getContacts().getElems(), proc(x: JsonNode): Profile = x.toProfileModel()) result = map(status_contacts.getContacts().getElems(), proc(x: JsonNode): Profile = x.toProfileModel())
self.events.emit("contactUpdate", ContactUpdateArgs(contacts: result)) self.events.emit("contactUpdate", ContactUpdateArgs(contacts: result))
proc addContact*(self: ContactModel, id: string): string = proc addContact*(self: ContactModel, id: string, localNickname: string): string =
let contact = self.getContactByID(id) let contact = self.getContactByID(id)
contact.systemTags.add(":contact/added") contact.systemTags.add(":contact/added")
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags) let nickname =
if (localNickname == ""):
contact.localNickname
else:
localNickname
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags, nickname)
self.events.emit("contactAdded", Args()) self.events.emit("contactAdded", Args())
proc addContact*(self: ContactModel, id: string): string =
result = self.addContact(id)
proc removeContact*(self: ContactModel, id: string) = proc removeContact*(self: ContactModel, id: string) =
let contact = self.getContactByID(id) let contact = self.getContactByID(id)
contact.systemTags.delete(contact.systemTags.find(":contact/added")) contact.systemTags.delete(contact.systemTags.find(":contact/added"))
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, 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, contact.localNickname)
self.events.emit("contactRemoved", Args()) self.events.emit("contactRemoved", Args())
proc isAdded*(self: ContactModel, id: string): bool = proc isAdded*(self: ContactModel, id: string): bool =

View File

@ -37,6 +37,8 @@ proc addDomain*(username: string): string =
proc userNameOrAlias*(contact: Profile, removeSuffix: bool = false): string = proc userNameOrAlias*(contact: Profile, removeSuffix: bool = false): string =
if(contact.ensName != "" and contact.ensVerified): if(contact.ensName != "" and contact.ensVerified):
result = "@" & userName(contact.ensName, removeSuffix) result = "@" & userName(contact.ensName, removeSuffix)
elif(contact.localNickname != ""):
result = contact.localNickname
else: else:
result = contact.alias result = contact.alias

View File

@ -26,7 +26,7 @@ proc getContacts*(): JsonNode =
return %* [] return %* []
return response["result"] return response["result"]
proc saveContact*(id: string, ensVerified: bool, ensName: string, 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], localNickname: string): string =
let payload = %* [{ let payload = %* [{
"id": id, "id": id,
"name": ensName, "name": ensName,
@ -35,6 +35,7 @@ proc saveContact*(id: string, ensVerified: bool, ensName: string, ensVerifiedAt:
"ensVerificationRetries": ensVerificationRetries, "ensVerificationRetries": ensVerificationRetries,
"alias": alias, "alias": alias,
"identicon": identicon, "identicon": identicon,
"systemTags": systemTags "systemTags": systemTags,
"localNickname": localNickname
}] }]
callPrivateRPC("saveContact".prefix, payload) callPrivateRPC("saveContact".prefix, payload)

View File

@ -2,7 +2,7 @@ import json
import ../libstatus/types import ../libstatus/types
type Profile* = ref object type Profile* = ref object
id*, alias*, username*, identicon*, address*, ensName*: string id*, alias*, username*, identicon*, address*, ensName*, localNickname*: string
ensVerified*: bool ensVerified*: bool
ensVerifiedAt*, ensVerificationRetries*, appearance*: int ensVerifiedAt*, ensVerificationRetries*, appearance*: int
systemTags*: seq[string] systemTags*: seq[string]
@ -48,3 +48,6 @@ proc toProfileModel*(profile: JsonNode): Profile =
if profile.hasKey("name"): if profile.hasKey("name"):
result.ensName = profile["name"].str result.ensName = profile["name"].str
if profile.hasKey("localNickname"):
result.localNickname = profile["localNickname"].str

View File

@ -52,6 +52,7 @@ ModalPopup {
Input { Input {
id: nicknameInput id: nicknameInput
placeholderText: qsTr("Nickname") placeholderText: qsTr("Nickname")
text: nickname
anchors.top: descriptionText.bottom anchors.top: descriptionText.bottom
anchors.topMargin: Style.current.padding anchors.topMargin: Style.current.padding
validationError: popup.nicknameTooLong ? qsTr("Your nickname is too long") : "" validationError: popup.nicknameTooLong ? qsTr("Your nickname is too long") : ""
@ -75,7 +76,9 @@ ModalPopup {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
disabled: popup.nicknameLength === 0 || popup.nicknameTooLong disabled: popup.nicknameLength === 0 || popup.nicknameTooLong
onClicked: { onClicked: {
console.log('Nickname set') userName = nicknameInput.textField.text
profileModel.changeContactNickname(fromAuthor, nicknameInput.textField.text)
popup.close()
} }
} }
} }

View File

@ -8,11 +8,12 @@ import "./"
ModalPopup { ModalPopup {
id: popup id: popup
property var identicon: "" property string identicon: ""
property var userName: "" property string userName: ""
property var fromAuthor: "" property string nickname: ""
property var text: "" property string fromAuthor: ""
property var alias: "" property string text: ""
property string alias: ""
property bool showQR: false property bool showQR: false
property bool isEnsVerified: false property bool isEnsVerified: false
@ -22,13 +23,14 @@ ModalPopup {
signal removeButtonClicked(address: string) signal removeButtonClicked(address: string)
function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam){ function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam){
this.showQR = false showQR = false
this.userName = userNameParam userName = userNameParam || ""
this.fromAuthor = fromAuthorParam nickname = userName.startsWith("@") ? "" : userName
this.identicon = identiconParam fromAuthor = fromAuthorParam || ""
this.text = textParam identicon = identiconParam || ""
this.isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor) text = textParam || ""
this.alias = chatsModel.alias(this.fromAuthor) isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor)
alias = chatsModel.alias(this.fromAuthor) || ""
} }
function openPopup(userNameParam, fromAuthorParam, identiconParam) { function openPopup(userNameParam, fromAuthorParam, identiconParam) {
@ -279,8 +281,8 @@ ModalPopup {
} }
StyledText { StyledText {
id: nickname id: nicknameText
text: qsTr("None") text: nickname ? nickname : qsTr("None")
anchors.right: nicknameCaret.left anchors.right: nicknameCaret.left
anchors.rightMargin: Style.current.padding anchors.rightMargin: Style.current.padding
anchors.verticalCenter: nicknameTitle.verticalCenter anchors.verticalCenter: nicknameTitle.verticalCenter

View File

@ -203,7 +203,6 @@ Item {
footer: StyledButton { footer: StyledButton {
anchors.right: parent.right anchors.right: parent.right
anchors.leftMargin: Style.current.padding anchors.leftMargin: Style.current.padding
//% "Send Message"
//% "Add contact" //% "Add contact"
label: qsTrId("add-contact") label: qsTrId("add-contact")
disabled: !contactToAddInfo.visible disabled: !contactToAddInfo.visible