feat: show nickname in the modal from the contact list

This commit is contained in:
Jonathan Rainville 2020-09-16 15:52:48 -04:00 committed by Iuri Matias
parent bc3b7a5533
commit 6e357cb5e2
8 changed files with 42 additions and 13 deletions

View File

@ -13,6 +13,7 @@ type
IsBlocked = UserRole + 6 IsBlocked = UserRole + 6
Alias = UserRole + 7 Alias = UserRole + 7
EnsVerified = UserRole + 8 EnsVerified = UserRole + 8
LocalNickname = UserRole + 9
QtObject: QtObject:
type ContactList* = ref object of QAbstractListModel type ContactList* = ref object of QAbstractListModel
@ -52,6 +53,7 @@ QtObject:
of "isBlocked": result = $contact.isBlocked() of "isBlocked": result = $contact.isBlocked()
of "alias": result = contact.alias of "alias": result = contact.alias
of "ensVerified": result = $contact.ensVerified of "ensVerified": result = $contact.ensVerified
of "localNickname": result = $contact.localNickname
method data(self: ContactList, index: QModelIndex, role: int): QVariant = method data(self: ContactList, index: QModelIndex, role: int): QVariant =
if not index.isValid: if not index.isValid:
@ -68,6 +70,7 @@ QtObject:
of ContactRoles.IsBlocked: result = newQVariant(contact.isBlocked()) of ContactRoles.IsBlocked: result = newQVariant(contact.isBlocked())
of ContactRoles.Alias: result = newQVariant(contact.alias) of ContactRoles.Alias: result = newQVariant(contact.alias)
of ContactRoles.EnsVerified: result = newQVariant(contact.ensVerified) of ContactRoles.EnsVerified: result = newQVariant(contact.ensVerified)
of ContactRoles.LocalNickname: result = newQVariant(contact.localNickname)
method roleNames(self: ContactList): Table[int, string] = method roleNames(self: ContactList): Table[int, string] =
{ {
@ -78,6 +81,7 @@ QtObject:
ContactRoles.IsContact.int:"isContact", ContactRoles.IsContact.int:"isContact",
ContactRoles.IsBlocked.int:"isBlocked", ContactRoles.IsBlocked.int:"isBlocked",
ContactRoles.Alias.int:"alias", ContactRoles.Alias.int:"alias",
ContactRoles.LocalNickname.int:"localNickname",
ContactRoles.EnsVerified.int:"ensVerified" ContactRoles.EnsVerified.int:"ensVerified"
}.toTable }.toTable

View File

@ -15,6 +15,7 @@ type ChatMember* = object
joined*: bool joined*: bool
identicon*: string identicon*: string
userName*: string userName*: string
localNickname*: string
proc toJsonNode*(self: ChatMember): JsonNode = proc toJsonNode*(self: ChatMember): JsonNode =
result = %* { result = %* {

View File

@ -65,7 +65,18 @@ Item {
if (!isProfileClick) { if (!isProfileClick) {
SelectedMessage.set(messageId, fromAuthor); SelectedMessage.set(messageId, fromAuthor);
} }
profileClick(userName, fromAuthor, identicon); // Get contact nickname
const contactList = profileModel.contactList
const contactCount = contactList.rowCount()
let nickname = ""
for (let i = 0; i < contactCount; i++) {
if (contactList.rowData(i, 'pubKey') === fromAuthor) {
nickname = contactList.rowData(i, 'localNickname')
break;
}
}
profileClick(userName, fromAuthor, identicon, "", nickname);
messageContextMenu.isProfile = !!isProfileClick messageContextMenu.isProfile = !!isProfileClick
messageContextMenu.isSticker = isSticker messageContextMenu.isSticker = isSticker
messageContextMenu.popup() messageContextMenu.popup()

View File

@ -21,7 +21,7 @@ ModalPopup {
data.clear(); data.clear();
for(let i = 0; i < profileModel.contactList.rowCount(); i++){ for(let i = 0; i < profileModel.contactList.rowCount(); i++){
if(chatsModel.activeChannel.contains(profileModel.contactList.rowData(i, "pubKey"))) continue; if(chatsModel.activeChannel.contains(profileModel.contactList.rowData(i, "pubKey"))) continue;
if(profileModel.contactList.rowData(i, "isContact") == "false") continue; if(profileModel.contactList.rowData(i, "isContact") === "false") continue;
data.append({ data.append({
name: profileModel.contactList.rowData(i, "name"), name: profileModel.contactList.rowData(i, "name"),
pubKey: profileModel.contactList.rowData(i, "pubKey"), pubKey: profileModel.contactList.rowData(i, "pubKey"),
@ -309,12 +309,22 @@ ModalPopup {
Layout.fillWidth: true Layout.fillWidth: true
font.pixelSize: 13 font.pixelSize: 13
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
popup.profileClick(model.userName, model.pubKey, model.identicon) // Get contact nickname
popup.close() const contactList = profileModel.contactList
} const contactCount = contactList.rowCount()
let nickname = ""
for (let i = 0; i < contactCount; i++) {
if (contactList.rowData(i, 'pubKey') === model.pubKey) {
nickname = contactList.rowData(i, 'localNickname')
break;
}
}
popup.profileClick(model.userName, model.pubKey, model.identicon, '', nickname)
popup.close()
}
} }
} }

View File

@ -12,6 +12,7 @@ ModalPopup {
property bool nicknameTooLong: nicknameLength > maxNicknameLength property bool nicknameTooLong: nicknameLength > maxNicknameLength
id: popup id: popup
height: 325
header: Item { header: Item {
height: childrenRect.height height: childrenRect.height

View File

@ -22,10 +22,10 @@ ModalPopup {
signal blockButtonClicked(name: string, address: string) signal blockButtonClicked(name: string, address: string)
signal removeButtonClicked(address: string) signal removeButtonClicked(address: string)
function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam){ function setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) {
showQR = false showQR = false
userName = userNameParam || "" userName = userNameParam || ""
nickname = userName.startsWith("@") ? "" : userName nickname = nicknameParam || ""
fromAuthor = fromAuthorParam || "" fromAuthor = fromAuthorParam || ""
identicon = identiconParam || "" identicon = identiconParam || ""
text = textParam || "" text = textParam || ""
@ -33,8 +33,8 @@ ModalPopup {
alias = chatsModel.alias(this.fromAuthor) || "" alias = chatsModel.alias(this.fromAuthor) || ""
} }
function openPopup(userNameParam, fromAuthorParam, identiconParam) { function openPopup(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) {
setPopupData(userNameParam, fromAuthorParam, identiconParam, ""); setPopupData(userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam);
popup.open() popup.open()
} }

View File

@ -9,6 +9,7 @@ Rectangle {
property string name: "Jotaro Kujo" property string name: "Jotaro Kujo"
property string address: "0x04d8c07dd137bd1b73a6f51df148b4f77ddaa11209d36e43d8344c0a7d6db1cad6085f27cfb75dd3ae21d86ceffebe4cf8a35b9ce8d26baa19dc264efe6d8f221b" property string address: "0x04d8c07dd137bd1b73a6f51df148b4f77ddaa11209d36e43d8344c0a7d6db1cad6085f27cfb75dd3ae21d86ceffebe4cf8a35b9ce8d26baa19dc264efe6d8f221b"
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
property string localNickname: "JoJo"
property bool selectable: false property bool selectable: false
property var profileClick: function() {} property var profileClick: function() {}
property bool isContact: true property bool isContact: true
@ -92,7 +93,7 @@ Rectangle {
icon.width: menuButton.iconSize icon.width: menuButton.iconSize
icon.height: menuButton.iconSize icon.height: menuButton.iconSize
text: qsTrId("view-profile") text: qsTrId("view-profile")
onTriggered: profileClick(name, address, identicon) onTriggered: profileClick(name, address, identicon, "", localNickname)
enabled: true enabled: true
} }
Action { Action {

View File

@ -23,6 +23,7 @@ ListView {
delegate: Contact { delegate: Contact {
name: Utils.removeStatusEns(model.name) name: Utils.removeStatusEns(model.name)
address: model.address address: model.address
localNickname: model.localNickname
identicon: model.identicon identicon: model.identicon
isContact: model.isContact isContact: model.isContact
isBlocked: model.isBlocked isBlocked: model.isBlocked