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.} =
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.} =
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 =
var contact = self.getContactByID(id)
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())
proc getContacts*(self: ContactModel): seq[Profile] =
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 =
proc addContact*(self: ContactModel, id: string, localNickname: string): string =
let contact = self.getContactByID(id)
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())
proc addContact*(self: ContactModel, id: string): string =
result = self.addContact(id)
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.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())
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 =
if(contact.ensName != "" and contact.ensVerified):
result = "@" & userName(contact.ensName, removeSuffix)
elif(contact.localNickname != ""):
result = contact.localNickname
else:
result = contact.alias

View File

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

View File

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

View File

@ -52,6 +52,7 @@ ModalPopup {
Input {
id: nicknameInput
placeholderText: qsTr("Nickname")
text: nickname
anchors.top: descriptionText.bottom
anchors.topMargin: Style.current.padding
validationError: popup.nicknameTooLong ? qsTr("Your nickname is too long") : ""
@ -75,7 +76,9 @@ ModalPopup {
anchors.bottom: parent.bottom
disabled: popup.nicknameLength === 0 || popup.nicknameTooLong
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 {
id: popup
property var identicon: ""
property var userName: ""
property var fromAuthor: ""
property var text: ""
property var alias: ""
property string identicon: ""
property string userName: ""
property string nickname: ""
property string fromAuthor: ""
property string text: ""
property string alias: ""
property bool showQR: false
property bool isEnsVerified: false
@ -22,13 +23,14 @@ ModalPopup {
signal removeButtonClicked(address: string)
function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam){
this.showQR = false
this.userName = userNameParam
this.fromAuthor = fromAuthorParam
this.identicon = identiconParam
this.text = textParam
this.isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor)
this.alias = chatsModel.alias(this.fromAuthor)
showQR = false
userName = userNameParam || ""
nickname = userName.startsWith("@") ? "" : userName
fromAuthor = fromAuthorParam || ""
identicon = identiconParam || ""
text = textParam || ""
isEnsVerified = chatsModel.isEnsVerified(this.fromAuthor)
alias = chatsModel.alias(this.fromAuthor) || ""
}
function openPopup(userNameParam, fromAuthorParam, identiconParam) {
@ -279,8 +281,8 @@ ModalPopup {
}
StyledText {
id: nickname
text: qsTr("None")
id: nicknameText
text: nickname ? nickname : qsTr("None")
anchors.right: nicknameCaret.left
anchors.rightMargin: Style.current.padding
anchors.verticalCenter: nicknameTitle.verticalCenter

View File

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