Skip to content

Commit

Permalink
fix: No toast on removal of untrusted mark
Browse files Browse the repository at this point in the history
- listen to the NIM's signal `SIGNAL_REMOVED_TRUST_STATUS`
- emit a signal for QML signal accordingly
- emit a toast/notification as a result

Fixes #16949
  • Loading branch information
caybro committed Dec 16, 2024
1 parent d4e2d4d commit d9006a7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/app/modules/main/profile_section/contacts/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_REMOVED_TRUST_STATUS) do(e: Args):
var args = TrustArgs(e)
self.delegate.contactTrustStatusChanged(args.publicKey, args.trustStatus)
self.delegate.onTrustStatusRemoved(args.publicKey)

self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
var args = ContactArgs(e)
Expand Down Expand Up @@ -160,4 +161,4 @@ proc fetchProfileShowcaseAccountsByAddress*(self: Controller, address: string) =
self.contactsService.fetchProfileShowcaseAccountsByAddress(address)

proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getEnabledChainIds()
return self.networkService.getEnabledChainIds()
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ method contactNicknameChanged*(self: AccessInterface, publicKey: string) {.base.
method contactTrustStatusChanged*(self: AccessInterface, publicKey: string, trustStatus: TrustStatus) {.base.} =
raise newException(ValueError, "No implementation available")

method onTrustStatusRemoved*(self: AccessInterface, publicKey: string): void {.base.} =
raise newException(ValueError, "No implementation available")

method contactsStatusUpdated*(self: AccessInterface, statusUpdates: seq[StatusUpdateDto]) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down Expand Up @@ -117,4 +120,4 @@ method getShowcaseCollectiblesModel*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

method isShowcaseForAContactLoading*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
3 changes: 3 additions & 0 deletions src/app/modules/main/profile_section/contacts/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ method contactNicknameChanged*(self: Module, publicKey: string) =
method contactTrustStatusChanged*(self: Module, publicKey: string, trustStatus: TrustStatus) =
self.view.contactsModel().updateTrustStatus(publicKey, trustStatus)

method onTrustStatusRemoved(self: Module, publicKey: string) =
self.view.trustStatusRemoved(publicKey)

method markAsTrusted*(self: Module, publicKey: string): void =
self.controller.markAsTrusted(publicKey)

Expand Down
2 changes: 2 additions & 0 deletions src/app/modules/main/profile_section/contacts/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ QtObject:
proc removeTrustStatus*(self: View, publicKey: string) {.slot.} =
self.delegate.removeTrustStatus(publicKey)

proc trustStatusRemoved*(self: View, publicKey: string) {.signal.}

proc shareUserUrlWithData*(self: View, pubkey: string): string {.slot.} =
return self.delegate.shareUserUrlWithData(pubkey)

Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Chat/panels/UserListPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Item {
emojiHash: model.emojiHash,
colorHash: model.colorHash,
colorId: model.colorId,
displayName: nickName || userName,
displayName: model.preferredDisplayName,
userIcon: model.icon,
trustStatus: model.trustStatus,
onlineStatus: model.onlineStatus,
Expand Down
11 changes: 11 additions & 0 deletions ui/app/AppLayouts/Profile/stores/ContactsStore.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import QtQuick 2.15

import StatusQ 0.1
import StatusQ.Core.Utils 0.1 as SQUtils

import utils 1.0

QtObject {
Expand All @@ -16,6 +18,15 @@ QtObject {
Component.onCompleted: {
mainModuleInst.resolvedENS.connect(root.resolvedENS)
}

readonly property var conn: Connections {
target: d.contactsModuleInst
function onTrustStatusRemoved(pubKey: string) {
const contactDetails = Utils.getContactDetailsAsJson(pubKey, false, false, true)
const displayName = SQUtils.Emoji.parse(ProfileUtils.displayName(contactDetails.localNickname, contactDetails.name, contactDetails.displayName, contactDetails.alias))
Global.displaySuccessToastMessage(qsTr("Trust mark removed for %1").arg(displayName))
}
}
}

readonly property string myPublicKey: userProfile.pubKey
Expand Down
4 changes: 1 addition & 3 deletions ui/app/mainui/Popups.qml
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ QtObject {
utilsStore: root.utilsStore

onAccepted: {
rootStore.contactStore.removeTrustStatus(publicKey)

if (markAsUntrusted && removeContact) {
rootStore.contactStore.markUntrustworthy(publicKey)
rootStore.contactStore.removeContact(publicKey)
Expand All @@ -471,7 +469,7 @@ QtObject {
rootStore.contactStore.removeContact(publicKey)
Global.displaySuccessToastMessage(qsTr("%1 trust mark removed and removed from contacts").arg(mainDisplayName))
} else {
Global.displaySuccessToastMessage(qsTr("%1 trust mark removed").arg(mainDisplayName))
rootStore.contactStore.removeTrustStatus(publicKey)
}
close()
}
Expand Down

0 comments on commit d9006a7

Please sign in to comment.