display real contacts on profile

display real contacts on profile

query contacts

add contact in form

fixes

fixes

display contacts

cleanup

cleanup

remove echo

refactor to use profile instead of contact model
This commit is contained in:
Iuri Matias 2020-06-13 09:49:20 -04:00
parent 9a03038126
commit e802159a6a
17 changed files with 156 additions and 52 deletions

View File

@ -61,7 +61,6 @@ proc handleMailserverEvents(self: ChatController) =
proc init*(self: ChatController) = proc init*(self: ChatController) =
self.handleMailserverEvents() self.handleMailserverEvents()
self.handleChatEvents() self.handleChatEvents()
self.status.mailservers.init() self.status.mailservers.init()
self.status.chat.init() self.status.chat.init()

View File

@ -135,3 +135,6 @@ QtObject:
proc blockContact*(self: ChatsView, id: string): string {.slot.} = proc blockContact*(self: ChatsView, id: string): string {.slot.} =
return self.status.contacts.blockContact(id) return self.status.contacts.blockContact(id)
proc addContact*(self: ChatsView, id: string): string {.slot.} =
return self.status.contacts.addContact(id)

View File

@ -1,4 +1,5 @@
import NimQml import NimQml
import json
import ../../status/libstatus/mailservers as status_mailservers import ../../status/libstatus/mailservers as status_mailservers
import ../../signals/types import ../../signals/types
import "../../status/libstatus/types" as status_types import "../../status/libstatus/types" as status_types
@ -41,6 +42,6 @@ proc init*(self: ProfileController, account: Account) =
let mailserver = MailServer(name: mailserver_config[0], endpoint: mailserver_config[1]) let mailserver = MailServer(name: mailserver_config[0], endpoint: mailserver_config[1])
self.view.addMailServerToList(mailserver) self.view.addMailServerToList(mailserver)
self.view.addContactToList(Contact(name: "username1", address: "0x12345")) let contactList = self.status.contacts.getContacts().elems
self.view.addContactToList(Contact(name: "username2", address: "0x23456")) for contact in contactList:
self.view.addContactToList(Contact(name: "username3", address: "0x34567")) self.view.addContactToList(contact.toProfileModel())

View File

@ -4,7 +4,6 @@ import views/contact_list
import views/profile_info import views/profile_info
import ../../status/profile import ../../status/profile
import ../../status/accounts as status_accounts import ../../status/accounts as status_accounts
import ../../status/contacts as status_contacts
import ../../status/status import ../../status/status
QtObject: QtObject:
@ -38,7 +37,7 @@ QtObject:
QtProperty[QVariant] mailserversList: QtProperty[QVariant] mailserversList:
read = getMailserversList read = getMailserversList
proc addContactToList*(self: ProfileView, contact: Contact) = proc addContactToList*(self: ProfileView, contact: Profile) =
self.contactList.addContactToList(contact) self.contactList.addContactToList(contact)
proc getContactList(self: ProfileView): QVariant {.slot.} = proc getContactList(self: ProfileView): QVariant {.slot.} =

View File

@ -2,16 +2,16 @@ import NimQml
import Tables import Tables
import strformat import strformat
import ../../../status/profile import ../../../status/profile
import ../../../status/contacts
type type
ContactRoles {.pure.} = enum ContactRoles {.pure.} = enum
Name = UserRole + 1, Name = UserRole + 1,
Address = UserRole + 2 Address = UserRole + 2
Identicon = UserRole + 3
QtObject: QtObject:
type ContactList* = ref object of QAbstractListModel type ContactList* = ref object of QAbstractListModel
contacts*: seq[Contact] contacts*: seq[Profile]
proc setup(self: ContactList) = self.QAbstractListModel.setup proc setup(self: ContactList) = self.QAbstractListModel.setup
@ -32,16 +32,18 @@ QtObject:
return return
let contact = self.contacts[index.row] let contact = self.contacts[index.row]
case role.ContactRoles: case role.ContactRoles:
of ContactRoles.Name: result = newQVariant(contact.name) of ContactRoles.Name: result = newQVariant(contact.username)
of ContactRoles.Address: result = newQVariant(contact.address) of ContactRoles.Address: result = newQVariant(contact.address)
of ContactRoles.Identicon: result = newQVariant(contact.identicon)
method roleNames(self: ContactList): Table[int, string] = method roleNames(self: ContactList): Table[int, string] =
{ {
ContactRoles.Name.int:"name", ContactRoles.Name.int:"name",
ContactRoles.Address.int:"address", ContactRoles.Address.int:"address",
ContactRoles.Identicon.int:"identicon",
}.toTable }.toTable
proc addContactToList*(self: ContactList, contact: Contact) = proc addContactToList*(self: ContactList, contact: Profile) =
self.beginInsertRows(newQModelIndex(), self.contacts.len, self.contacts.len) self.beginInsertRows(newQModelIndex(), self.contacts.len, self.contacts.len)
self.contacts.add(contact) self.contacts.add(contact)
self.endInsertRows() self.endInsertRows()

View File

@ -121,7 +121,6 @@ proc leave*(self: ChatModel, chatId: string) =
self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) self.events.emit("channelLeft", ChatIdArg(chatId: chatId))
self.events.emit("activeChannelChanged", ChatIdArg(chatId: "")) self.events.emit("activeChannelChanged", ChatIdArg(chatId: ""))
proc setActiveChannel*(self: ChatModel, chatId: string) = proc setActiveChannel*(self: ChatModel, chatId: string) =
self.events.emit("activeChannelChanged", ChatIdArg(chatId: chatId)) self.events.emit("activeChannelChanged", ChatIdArg(chatId: chatId))
@ -162,7 +161,6 @@ proc confirmJoiningGroup*(self: ChatModel, chatId: string) =
var response = parseJson(status_chat.confirmJoiningGroup(chatId)) var response = parseJson(status_chat.confirmJoiningGroup(chatId))
var (chats, messages) = formatChatUpdate(response) var (chats, messages) = formatChatUpdate(response)
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats)) self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats))
# self.events.emit("pushMessage", PushMessageArgs(messages: messages, chats: chats))
proc blockContact*(self: ChatModel, id: string): string = proc blockContact*(self: ChatModel, id: string): string =
var contact = status_profile.getContactByID(id) var contact = status_profile.getContactByID(id)

View File

@ -3,10 +3,6 @@ import json
import libstatus/contacts as status_contacts import libstatus/contacts as status_contacts
import profile import profile
type
Contact* = ref object
name*, address*: string
type type
ContactModel* = ref object ContactModel* = ref object
events*: EventEmitter events*: EventEmitter
@ -23,3 +19,10 @@ proc blockContact*(self: ContactModel, id: string): string =
var contact = self.getContactByID(id) var contact = self.getContactByID(id)
contact.systemTags.add(":contact/blocked") contact.systemTags.add(":contact/blocked")
status_contacts.blockContact(contact) status_contacts.blockContact(contact)
proc getContacts*(self: ContactModel): JsonNode =
status_contacts.getContacts()
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)

View File

@ -19,3 +19,22 @@ proc blockContact*(contact: Profile): string =
proc getContactByID*(id: string): string = proc getContactByID*(id: string): string =
callPrivateRPC("getContactByID".prefix, %* [id]) callPrivateRPC("getContactByID".prefix, %* [id])
proc getContacts*(): JsonNode =
let payload = %* []
let response = callPrivateRPC("wakuext_contacts", payload).parseJson
if response["result"].kind == JNull:
return %* []
return response["result"]
proc saveContact*(id: string, ensVerified: bool, ensVerifiedAt: int, ensVerificationRetries: int, alias: string, identicon: string, systemTags: seq[string]): string =
let payload = %* [{
"id": id,
"ensVerified": ensVerified,
"ensVerifiedAt": ensVerifiedAt,
"ensVerificationRetries": ensVerificationRetries,
"alias": alias,
"identicon": identicon,
"systemTags": systemTags
}]
callPrivateRPC("shhext_saveContact", payload)

View File

@ -9,7 +9,7 @@ type
name*, endpoint*: string name*, endpoint*: string
type Profile* = ref object type Profile* = ref object
id*, alias*, username*, identicon*: string id*, alias*, username*, identicon*, address*: string
ensVerified*: bool ensVerified*: bool
ensVerifiedAt*: int ensVerifiedAt*: int
ensVerificationRetries*: int ensVerificationRetries*: int
@ -36,6 +36,7 @@ proc toProfileModel*(profile: JsonNode): Profile =
id: profile["id"].str, id: profile["id"].str,
username: profile["alias"].str, username: profile["alias"].str,
identicon: profile["identicon"].str, identicon: profile["identicon"].str,
address: profile["id"].str,
alias: profile["alias"].str, alias: profile["alias"].str,
ensVerified: profile["ensVerified"].getBool, ensVerified: profile["ensVerified"].getBool,
ensVerifiedAt: profile["ensVerifiedAt"].getInt, ensVerifiedAt: profile["ensVerifiedAt"].getInt,

View File

@ -222,6 +222,9 @@ ModalPopup {
label: "Add to contacts" label: "Add to contacts"
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
onClicked: { onClicked: {
chatsModel.addContact(fromAuthor)
// TODO(iuri): Change add contact button state based
// on contact already added or not
profilePopup.close() profilePopup.close()
} }
} }

View File

@ -0,0 +1,49 @@
import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.1
import "../../../../../imports"
import "../../../../../shared"
Rectangle {
property string name: "Jotaro Kujo"
property string address: "0x04d8c07dd137bd1b73a6f51df148b4f77ddaa11209d36e43d8344c0a7d6db1cad6085f27cfb75dd3ae21d86ceffebe4cf8a35b9ce8d26baa19dc264efe6d8f221b"
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
height: 64
anchors.right: parent.right
anchors.left: parent.left
border.width: 0
radius: Theme.radius
RoundImage {
id: accountImage
anchors.left: parent.left
anchors.leftMargin: Theme.padding
anchors.verticalCenter: parent.verticalCenter
source: identicon
}
Text {
id: usernameText
text: name
elide: Text.ElideRight
anchors.right: parent.right
anchors.rightMargin: Theme.padding
font.pixelSize: 17
anchors.top: accountImage.top
anchors.left: accountImage.right
anchors.leftMargin: Theme.padding
}
Text {
id: addressText
width: 108
text: address
elide: Text.ElideMiddle
anchors.bottom: accountImage.bottom
anchors.bottomMargin: 0
anchors.left: usernameText.left
anchors.leftMargin: 0
font.pixelSize: 15
color: Theme.darkGrey
}
}

View File

@ -0,0 +1,27 @@
import QtQuick 2.14
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.1
import "./samples/"
import "../../../../../imports"
import "../../../../../shared"
ListView {
property var contacts: ContactsData {}
anchors.topMargin: 48
anchors.top: element2.bottom
anchors.fill: parent
model: contacts
delegate: Contact {
name: model.name
address: model.address
identicon: model.identicon
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/

View File

@ -0,0 +1,2 @@
Contact 1.0 Contact.qml
ContactList 1.0 ContactList.qml

View File

@ -0,0 +1,23 @@
import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.1
ListModel {
ListElement {
name: "Ferocious Herringbone Sinewave2"
identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAg0lEQVR4nOzXwQmAMBAFURV7sQybsgybsgyr0QYUlE1g+Mw7ioQMe9lMQwhDaAyhMYTGEJqYkPnrj/t5XE/ft2UdW1yken7MRAyhMYTGEBpDaAyhKe9JbzvSX9WdLWYihtAYQuMLkcYQGkPUScxEDKExhMYQGkNoDKExhMYQmjsAAP//ZfIUZgXTZXQAAAAASUVORK5CYII="
address: "0x123456789009876543211234567890"
}
ListElement {
name: "Another Account"
identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAg0lEQVR4nOzXwQmAMBAFURV7sQybsgybsgyr0QYUlE1g+Mw7ioQMe9lMQwhDaAyhMYTGEJqYkPnrj/t5XE/ft2UdW1yken7MRAyhMYTGEBpDaAyhKe9JbzvSX9WdLWYihtAYQuMLkcYQGkPUScxEDKExhMYQGkNoDKExhMYQmjsAAP//ZfIUZgXTZXQAAAAASUVORK5CYII="
address: "0x123456789009876543211234567890"
}
}
/*##^##
Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/

View File

@ -0,0 +1 @@
ContactsData 1.0 ContactsData.qml

View File

@ -2,6 +2,7 @@ import QtQuick 2.3
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import "../../../../imports" import "../../../../imports"
import "./Contacts"
Item { Item {
id: contactsContainer id: contactsContainer
@ -21,40 +22,8 @@ Item {
font.pixelSize: 20 font.pixelSize: 20
} }
Component { ContactList {
id: contactsList
Item {
height: 56
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
Column {
Row {
Text {
text: name
font.weight: Font.Bold
font.pixelSize: 14
}
}
Row {
Text {
text: address
font.weight: Font.Bold
font.pixelSize: 12
}
}
}
}
}
ListView {
id: contactListView id: contactListView
anchors.topMargin: 48 contacts: profileModel.contactList
anchors.top: element2.bottom
anchors.fill: parent
model: profileModel.contactList
delegate: contactsList
} }
} }

View File

@ -77,6 +77,11 @@ DISTFILES += \
app/AppLayouts/Profile/LeftTab/Profile.qml \ app/AppLayouts/Profile/LeftTab/Profile.qml \
app/AppLayouts/Profile/LeftTab/qmldir \ app/AppLayouts/Profile/LeftTab/qmldir \
app/AppLayouts/Profile/ProfileLayout.qml \ app/AppLayouts/Profile/ProfileLayout.qml \
app/AppLayouts/Profile/Sections/Contacts/Contact.qml \
app/AppLayouts/Profile/Sections/Contacts/ContactList.qml \
app/AppLayouts/Profile/Sections/Contacts/qmldir \
app/AppLayouts/Profile/Sections/Contacts/samples/ContactsData.qml \
app/AppLayouts/Profile/Sections/Contacts/samples/qmldir \
app/AppLayouts/Wallet/AccountSettingsModal.qml \ app/AppLayouts/Wallet/AccountSettingsModal.qml \
app/AppLayouts/Wallet/AddCustomTokenModal.qml \ app/AppLayouts/Wallet/AddCustomTokenModal.qml \
app/AppLayouts/Wallet/AssetsTab.qml \ app/AppLayouts/Wallet/AssetsTab.qml \