feat(community): add notification setting to community

Fixes #2421
This commit is contained in:
Jonathan Rainville 2021-06-29 13:42:13 -04:00 committed by Iuri Matias
parent 5001f36e86
commit 2e98724641
11 changed files with 74 additions and 38 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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",

View File

@ -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()

View File

@ -125,6 +125,7 @@ type Community* = object
canManageUsers*: bool
canJoin*: bool
isMember*: bool
muted*: bool
communityImage*: IdentityImage
membershipRequests*: seq[CommunityMembershipRequest]
communityColor*: string

View File

@ -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] = @[]

View File

@ -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,

View File

@ -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;
}
}
}
}
}
}

View File

@ -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

View File

@ -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

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 7c1765786a96f5683e7e34323216f9098eec596b
Subproject commit 11c46edd8b25bb6b313b71378f1b3ac842ad1908