feat(Contacts): ContactVerificationRequestPopup reacts on model's update

This commit is contained in:
MishkaRogachev 2022-12-09 16:33:20 +04:00 committed by Mikhail Rogachev
parent ddf27d3038
commit bc446f93b7
4 changed files with 39 additions and 16 deletions

View File

@ -39,6 +39,7 @@ QtObject:
result.setup
proc countChanged(self: Model) {.signal.}
proc itemChanged(self: Model, pubKey: string) {.signal.}
proc setItems*(self: Model, items: seq[UserItem]) =
self.beginResetModel()
@ -51,6 +52,7 @@ QtObject:
result &= fmt"""User Model:
[{i}]:({$self.items[i]})
"""
proc getCount*(self: Model): int {.slot.} =
self.items.len
QtProperty[int]count:
@ -138,6 +140,9 @@ QtObject:
self.endInsertRows()
self.countChanged()
for item in items:
self.itemChanged(item.pubKey)
proc addItem*(self: Model, item: UserItem) =
# we need to maintain online contact on top, that means
# if we add an item online status we add it as the last online item (before the first offline item)
@ -158,6 +163,7 @@ QtObject:
self.items.insert(item, position)
self.endInsertRows()
self.countChanged()
self.itemChanged(item.pubKey)
proc clear*(self: Model) =
self.beginResetModel()
@ -176,10 +182,13 @@ QtObject:
defer: parentModelIndex.delete
self.beginRemoveRows(parentModelIndex, index, index)
let pubKey = self.items[index].pubKey
self.items.delete(index)
self.endRemoveRows()
self.countChanged()
self.itemChanged(pubKey)
# TODO: rename to `containsItem`
proc isContactWithIdAdded*(self: Model, id: string): bool =
return self.findIndexByPubKey(id) != -1
@ -200,6 +209,7 @@ QtObject:
ModelRole.EnsName.int,
ModelRole.LocalNickname.int,
])
self.itemChanged(pubKey)
proc setIcon*(self: Model, pubKey: string, icon: string) =
let ind = self.findIndexByPubKey(pubKey)
@ -210,6 +220,7 @@ QtObject:
let index = self.createIndex(ind, 0, nil)
self.dataChanged(index, index, @[ModelRole.Icon.int])
self.itemChanged(pubKey)
proc updateItem*(
self: Model,
@ -241,7 +252,8 @@ QtObject:
ModelRole.Icon.int,
ModelRole.IsUntrustworthy.int,
])
self.itemChanged(pubKey)
proc updateName*(
self: Model,
pubKey: string,
@ -257,7 +269,8 @@ QtObject:
self.dataChanged(index, index, @[
ModelRole.DisplayName.int
])
self.itemChanged(pubKey)
proc updateIncomingRequestStatus*(
self: Model,
pubKey: string,
@ -273,6 +286,7 @@ QtObject:
self.dataChanged(index, index, @[
ModelRole.IncomingVerificationStatus.int
])
self.itemChanged(pubKey)
proc updateTrustStatus*(self: Model, pubKey: string, isUntrustworthy: bool) =
let ind = self.findIndexByPubKey(pubKey)
@ -283,6 +297,7 @@ QtObject:
let last = self.createIndex(ind, 0, nil)
self.items[ind].isUntrustworthy = isUntrustworthy
self.dataChanged(first, last, @[ModelRole.IsUntrustworthy.int])
self.itemChanged(pubKey)
proc setOnlineStatus*(self: Model, pubKey: string,
onlineStatus: OnlineStatus) =

View File

@ -20,7 +20,7 @@ StatusModal {
signal verificationRefused(string senderPublicKey)
signal responseSent(string senderPublicKey, string response)
function updateContactDetails() {
function updateVerificationDetails() {
try {
const request = root.contactsStore.getVerificationDetailsFromAsJson(root.publicKey)
@ -42,8 +42,10 @@ StatusModal {
Connections {
target: root.contactsStore.receivedContactRequestsModel
function onCountChanged() {
root.updateContactDetails()
function onItemChanged(pubKey) {
if (pubKey === root.publicKey)
root.updateVerificationDetails()
}
}
@ -68,7 +70,7 @@ StatusModal {
height: 230 + verificationMessage.height + verificationResponse.height
onOpened: {
root.updateContactDetails()
root.updateVerificationDetails()
verificationResponse.input.edit.forceActiveFocus(Qt.MouseFocusReason)
}
@ -77,7 +79,7 @@ StatusModal {
anchors.right: parent.right
anchors.leftMargin: Style.current.padding
anchors.rightMargin: Style.current.padding
StatusBaseText {
id: description
width: parent.width

View File

@ -86,15 +86,21 @@ Pane {
}
readonly property var conns: Connections {
target: Global
function onNickNameChanged(publicKey, nickname) {
if (publicKey === root.publicKey) d.reload()
target: root.contactsStore.myContactsModel
function onItemChanged(pubKey) {
if (pubKey === root.publicKey)
d.reload()
}
function onContactBlocked(publicKey) {
if (publicKey === root.publicKey) d.reload()
}
function onContactUnblocked(publicKey) {
if (publicKey === root.publicKey) d.reload()
}
// FIXME: use myContactsModel for identity verification
readonly property var conns2: Connections {
target: root.contactsStore.receivedContactRequestsModel
function onItemChanged(pubKey) {
if (pubKey === root.publicKey)
d.reload()
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit dd8be1d8b041f967a0707cfb70ac96c5a71d93a8
Subproject commit 8593866862175eeab6f30765e5f0b813f3b1b4db