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

View File

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

View File

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