From 2e9872464198d5dc778f05e632575e627d30fa3a Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 29 Jun 2021 13:42:13 -0400 Subject: [PATCH] feat(community): add notification setting to community Fixes #2421 --- src/app/chat/views/communities.nim | 12 ++++- src/app/chat/views/community_item.nim | 15 ++++++- src/app/chat/views/community_list.nim | 3 ++ src/status/chat.nim | 3 ++ src/status/chat/chat.nim | 1 + src/status/libstatus/chat.nim | 2 + src/status/signals/messages.nim | 1 + ui/app/AppLayouts/Chat/CommunityColumn.qml | 18 +++++++- .../BackUpCommuntyBanner.qml | 10 ----- .../CommunityProfilePopupOverview.qml | 45 +++++++++---------- vendor/status-go | 2 +- 11 files changed, 74 insertions(+), 38 deletions(-) diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index 38c008f0a9..963fea24bd 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -425,6 +425,16 @@ QtObject: for community in self.joinedCommunityList.communities: for chat in community.chats: if (chat.id == channelId): + if community.muted: + chat.muted = true return chat - + + proc setCommunityMuted*(self: CommunitiesView, communityId: string, muted: bool) {.slot.} = + self.status.chat.setCommunityMuted(communityId, muted) + if (communityId == self.activeCommunity.communityItem.id): + self.activeCommunity.setMuted(muted) + + var community = self.joinedCommunityList.getCommunityById(communityId) + community.muted = muted + self.joinedCommunityList.replaceCommunity(community) \ No newline at end of file diff --git a/src/app/chat/views/community_item.nim b/src/app/chat/views/community_item.nim index bc569f7238..97c7d5772f 100644 --- a/src/app/chat/views/community_item.nim +++ b/src/app/chat/views/community_item.nim @@ -55,7 +55,6 @@ QtObject: self.status.events.emit("communityActiveChanged", CommunityActiveChangedArgs(active: value)) self.activeChanged() - proc removeMember*(self: CommunityItemView, pubKey: string) = self.members.removeMember(pubKey) self.nbMembersChanged() @@ -102,6 +101,18 @@ QtObject: QtProperty[bool] verified: read = verified + proc mutedChanged*(self: CommunityItemView) {.signal.} + + proc setMuted*(self: CommunityItemView, muted: bool) {.slot.} = + self.communityItem.muted = muted + self.mutedChanged() + + proc muted*(self: CommunityItemView): bool {.slot.} = result = ?.self.communityItem.muted + + QtProperty[bool] muted: + read = muted + notify = mutedChanged + proc ensOnly*(self: CommunityItemView): bool {.slot.} = result = ?.self.communityItem.ensOnly QtProperty[bool] ensOnly: @@ -216,4 +227,4 @@ QtObject: result = self.communityItem.communityImage.large QtProperty[string] largeImage: - read = largeImage \ No newline at end of file + read = largeImage diff --git a/src/app/chat/views/community_list.nim b/src/app/chat/views/community_list.nim index 18aa938b17..b025e14d51 100644 --- a/src/app/chat/views/community_list.nim +++ b/src/app/chat/views/community_list.nim @@ -26,6 +26,7 @@ type IsMember = UserRole + 15 UnviewedMessagesCount = UserRole + 16 CommunityColor = UserRole + 17 + Muted = UserRole + 18 QtObject: type @@ -106,6 +107,7 @@ QtObject: of CommunityRoles.CanRequestAccess: result = newQVariant(communityItem.canRequestAccess.bool) of CommunityRoles.CanManageUsers: result = newQVariant(communityItem.canManageUsers.bool) of CommunityRoles.CanJoin: result = newQVariant(communityItem.canJoin.bool) + of CommunityRoles.Muted: result = newQVariant(communityItem.muted.bool) of CommunityRoles.IsMember: result = newQVariant(communityItem.isMember.bool) of CommunityRoles.NumMembers: result = newQVariant(communityItem.members.len) of CommunityRoles.UnviewedMessagesCount: result = newQVariant(communityItem.unviewedMessagesCount) @@ -140,6 +142,7 @@ QtObject: CommunityRoles.CanManageUsers.int: "canManageUsers", CommunityRoles.CanJoin.int: "canJoin", CommunityRoles.IsMember.int: "isMember", + CommunityRoles.Muted.int: "muted", CommunityRoles.NumMembers.int: "nbMembers", CommunityRoles.UnviewedMessagesCount.int: "unviewedMessagesCount", CommunityRoles.ThumbnailImage.int:"thumbnailImage", diff --git a/src/status/chat.nim b/src/status/chat.nim index 0726876f7d..d953633b94 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -520,6 +520,9 @@ proc declineRequestToJoinCommunity*(self: ChatModel, requestId: string) = proc pendingRequestsToJoinForCommunity*(self: ChatModel, communityKey: string): seq[CommunityMembershipRequest] = result = status_chat.pendingRequestsToJoinForCommunity(communityKey) +proc setCommunityMuted*(self: ChatModel, communityId: string, muted: bool) = + status_chat.setCommunityMuted(communityId, muted) + proc myPendingRequestsToJoin*(self: ChatModel): seq[CommunityMembershipRequest] = result = status_chat.myPendingRequestsToJoin() diff --git a/src/status/chat/chat.nim b/src/status/chat/chat.nim index 8e6665224e..1e49449b67 100644 --- a/src/status/chat/chat.nim +++ b/src/status/chat/chat.nim @@ -125,6 +125,7 @@ type Community* = object canManageUsers*: bool canJoin*: bool isMember*: bool + muted*: bool communityImage*: IdentityImage membershipRequests*: seq[CommunityMembershipRequest] communityColor*: string diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index 0466ed7978..236f2d28e6 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -524,6 +524,8 @@ proc banUserFromCommunity*(pubKey: string, communityId: string): string = "user": pubKey }]) +proc setCommunityMuted*(communityId: string, muted: bool) = + discard callPrivateRPC("setCommunityMuted".prefix, %*[communityId, muted]) proc parseChatPinnedMessagesResponse*(rpcResult: JsonNode): (string, seq[Message]) = var messages: seq[Message] = @[] diff --git a/src/status/signals/messages.nim b/src/status/signals/messages.nim index e82c434a4a..4829db7a52 100644 --- a/src/status/signals/messages.nim +++ b/src/status/signals/messages.nim @@ -212,6 +212,7 @@ proc toCommunity*(jsonCommunity: JsonNode): Community = canManageUsers: jsonCommunity{"canManageUsers"}.getBool, canJoin: jsonCommunity{"canJoin"}.getBool, isMember: jsonCommunity{"isMember"}.getBool, + muted: jsonCommunity{"muted"}.getBool, chats: newSeq[Chat](), members: newSeq[string](), communityColor: jsonCommunity{"color"}.getStr, diff --git a/ui/app/AppLayouts/Chat/CommunityColumn.qml b/ui/app/AppLayouts/Chat/CommunityColumn.qml index 6464003f0c..6b3a56ce07 100644 --- a/ui/app/AppLayouts/Chat/CommunityColumn.qml +++ b/ui/app/AppLayouts/Chat/CommunityColumn.qml @@ -246,7 +246,23 @@ Rectangle { anchors.top: emptyViewAndSuggestionsLoader.bottom anchors.topMargin: active ? Style.current.padding : 0 sourceComponent: Component { - BackUpCommuntyBanner {} + Item { + width: parent.width + height: backupBanner.height + + BackUpCommuntyBanner { + id: backupBanner + } + MouseArea { + anchors.fill: backupBanner + acceptedButtons: Qt.RightButton + onClicked: { + /* Prevents sending events to the component beneath + if Right Mouse Button is clicked. */ + mouse.accepted = false; + } + } + } } } } diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/BackUpCommuntyBanner.qml b/ui/app/AppLayouts/Chat/CommunityComponents/BackUpCommuntyBanner.qml index 739590cc6e..6cec3edfb1 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/BackUpCommuntyBanner.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/BackUpCommuntyBanner.qml @@ -15,16 +15,6 @@ Rectangle { radius: 16 color: Style.current.transparent - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.RightButton - onClicked: { - /* Prevents sending events to the component beneath - if Right Mouse Button is clicked. */ - mouse.accepted = false; - } - } - Rectangle { width: 66 height: 4 diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml index 8db3b33d7d..f0934701d1 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityProfilePopupOverview.qml @@ -158,29 +158,28 @@ Item { // } // } - // TODO re-add when this is supported -// CommunityPopupButton { -// id: notificationsBtn -// //% "Notifications" -// label: qsTrId("notifications") -// iconName: "notifications" -// width: parent.width -// txtColor: Style.current.textColor -// type: globalSettings.theme === Universal.Dark ? "secondary" : "primary" -// onClicked: function(){ -// notificationSwitch.checked = !notificationSwitch.checked -// } -// StatusSwitch { -// id: notificationSwitch -// anchors.right: parent.right -// anchors.rightMargin: Style.current.padding -// anchors.verticalCenter: parent.verticalCenter -// onCheckedChanged: function(value) { -// // TODO: enable/disable notifications -// console.log("TODO: toggle") -// } -// } -// } + CommunityPopupButton { + id: notificationsBtn + //% "Notifications" + label: qsTrId("notifications") + iconName: "notifications" + width: parent.width + txtColor: Style.current.textColor + type: globalSettings.theme === Universal.Dark ? "secondary" : "primary" + onClicked: function(){ + notificationSwitch.clicked() + } + StatusSwitch { + id: notificationSwitch + checked: !chatsModel.communities.activeCommunity.muted + anchors.right: parent.right + anchors.rightMargin: Style.current.padding + anchors.verticalCenter: parent.verticalCenter + onClicked: function () { + chatsModel.communities.setCommunityMuted(chatsModel.communities.activeCommunity.id, notificationSwitch.checked) + } + } + } Item { id: spacer1 diff --git a/vendor/status-go b/vendor/status-go index 7c1765786a..11c46edd8b 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 7c1765786a96f5683e7e34323216f9098eec596b +Subproject commit 11c46edd8b25bb6b313b71378f1b3ac842ad1908