From 49f7accbc21012cc00fb06b3d693a4c6f6e26917 Mon Sep 17 00:00:00 2001 From: Mykhailo Prakhov Date: Wed, 6 Mar 2024 19:19:12 +0100 Subject: [PATCH] chore: send emphemeral notification from QML side --- src/app/modules/main/module.nim | 14 ++------------ src/app/modules/main/view.nim | 8 +++++++- ui/app/mainui/AppMain.qml | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 6ae8e194be..46b55e526d 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -1252,18 +1252,8 @@ method onMembershipStatusUpdated*[T](self: Module[T], communityId: string, membe let item = self.view.model().getItemById(communityId) if item.id != "": item.updateMembershipStatus(memberPubkey, status) - - case status: - of MembershipRequestState.Banned: - self.displayEphemeralNotification(fmt "{contactName} was banned from {communityDto.name}", "" , "checkmark-circle", false, EphemeralNotificationType.Success.int, "") - - of MembershipRequestState.Kicked: - self.displayEphemeralNotification(fmt "{contactName} was kicked from {communityDto.name}", "" , "checkmark-circle", false, EphemeralNotificationType.Success.int, "") - - of MembershipRequestState.Unbanned: - self.displayEphemeralNotification(fmt "{contactName} unbanned from {communityDto.name}", "" , "checkmark-circle", false, EphemeralNotificationType.Success.int, "") - else: - discard + if status == MembershipRequestState.Banned or status == MembershipRequestState.Kicked or status == MembershipRequestState.Unbanned: + self.view.emitCommunityMemberStatusEphemeralNotification(communityDto.name, contactName, status.int) method calculateProfileSectionHasNotification*[T](self: Module[T]): bool = return not self.controller.isMnemonicBackedUp() diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 5be94a02a6..b72bb2ac24 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -353,4 +353,10 @@ QtObject: self.delegate.addressWasShown(address) proc onCheckIfAddressWasCopied*(self: View, value: string) {.slot.} = - self.delegate.checkIfAddressWasCopied(value) \ No newline at end of file + self.delegate.checkIfAddressWasCopied(value) + + proc communityMemberStatusEphemeralNotification*(self:View, communityName: string, memberName: string, membershipState: int) {.signal.} + + proc emitCommunityMemberStatusEphemeralNotification*(self:View, communityName: string, memberName: string, + membershipState: int) = + self.communityMemberStatusEphemeralNotification(communityName, memberName, membershipState) diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index 143e152d1a..71eba50a4b 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -224,6 +224,31 @@ Item { "%1/%2".arg(appMain.rootStore.getEtherscanLink(chainId)).arg(txHash)) } } + + function onCommunityMemberStatusEphemeralNotification(communityName: string, memberName: string, state: CommunityMembershipRequestState) { + var text = "" + switch (state) { + case Constants.CommunityMembershipRequestState.Banned: + text = qsTr("%1 was banned from %2").arg(memberName).arg(communityName) + break + case Constants.CommunityMembershipRequestState.Unbanned: + text = qsTr("%1 unbanned from %2").arg(memberName).arg(communityName) + break + case Constants.CommunityMembershipRequestState.Kicked: + text = qsTr("%1 was kicked from %2").arg(memberName).arg(communityName) + break + default: return + } + + Global.displayToastMessage( + text, + "", + "checkmark-circle", + false, + Constants.ephemeralNotificationType.success, + "" + ) + } } QtObject {