From 73eb12c914b674f9b543fc2bc070e5721824973e Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Tue, 30 May 2023 20:51:57 +0300 Subject: [PATCH] feat(communities): Adds mute category interval Part of: #9369 --- .../modules/main/chat_section/controller.nim | 8 +++---- .../main/chat_section/io_interface.nim | 7 ++---- src/app/modules/main/chat_section/module.nim | 12 +++++----- src/app/modules/main/chat_section/view.nim | 4 ++-- src/app_service/service/community/service.nim | 4 ++-- src/backend/communities.nim | 14 +++++++----- .../Chat/views/CommunityColumnView.qml | 22 +++++++++++++------ vendor/status-go | 2 +- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 4c0b1a70da..6601e1718e 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -122,11 +122,11 @@ proc init*(self: Controller) = self.events.on(chat_service.SIGNAL_CHAT_MUTED) do(e:Args): let args = chat_service.ChatArgs(e) - self.delegate.onChatMuted(args.chatId) + self.delegate.changeMutedOnChat(args.chatId, true) self.events.on(chat_service.SIGNAL_CHAT_UNMUTED) do(e:Args): let args = chat_service.ChatArgs(e) - self.delegate.onChatUnmuted(args.chatId) + self.delegate.changeMutedOnChat(args.chatId, false) self.events.on(message_service.SIGNAL_MESSAGES_MARKED_AS_READ) do(e: Args): let args = message_service.MessagesMarkedAsReadArgs(e) @@ -597,8 +597,8 @@ proc editCommunity*( proc exportCommunity*(self: Controller): string = self.communityService.exportCommunity(self.sectionId) -proc muteCategory*(self: Controller, categoryId: string) = - self.communityService.muteCategory(self.sectionId, categoryId) +proc muteCategory*(self: Controller, categoryId: string, interval: int) = + self.communityService.muteCategory(self.sectionId, categoryId, interval) proc unmuteCategory*(self: Controller, categoryId: string) = self.communityService.unmuteCategory(self.sectionId, categoryId) diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index 71a2b0f637..2465adb458 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -105,10 +105,7 @@ method onNewMessagesReceived*(self: AccessInterface, sectionIdMsgBelongsTo: stri chatTypeMsgBelongsTo: ChatType, lastMessageTimestamp: int, unviewedMessagesCount: int, unviewedMentionsCount: int, message: MessageDto) {.base.} = raise newException(ValueError, "No implementation available") -method onChatMuted*(self: AccessInterface, chatId: string) {.base.} = - raise newException(ValueError, "No implementation available") - -method onChatUnmuted*(self: AccessInterface, chatId: string) {.base.} = +method changeMutedOnChat*(self: AccessInterface, chatId: string, muted: bool) {.base.} = raise newException(ValueError, "No implementation available") method onMarkAllMessagesRead*(self: AccessInterface, chat: ChatDto) {.base.} = @@ -204,7 +201,7 @@ method muteChat*(self: AccessInterface, chatId: string, interval: int) {.base.} method unmuteChat*(self: AccessInterface, chatId: string) {.base.} = raise newException(ValueError, "No implementation available") -method muteCategory*(self: AccessInterface, categoryId: string) {.base.} = +method muteCategory*(self: AccessInterface, categoryId: string, interval: int) {.base.} = raise newException(ValueError, "No implementation available") method unmuteCategory*(self: AccessInterface, categoryId: string) {.base.} = diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index d8fc161074..a14e1696d9 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -769,8 +769,8 @@ method muteChat*(self: Module, chatId: string, interval: int) = method unmuteChat*(self: Module, chatId: string) = self.controller.unmuteChat(chatId) -method muteCategory*(self: Module, categoryId: string) = - self.controller.muteCategory(categoryId) +method muteCategory*(self: Module, categoryId: string, interval: int) = + self.controller.muteCategory(categoryId, interval) method unmuteCategory*(self: Module, categoryId: string) = self.controller.unmuteCategory(categoryId) @@ -781,11 +781,8 @@ method onCategoryMuted*(self: Module, categoryId: string) = method onCategoryUnmuted*(self: Module, categoryId: string) = self.view.chatsModel().changeMutedOnItemByCategoryId(categoryId, false) -method onChatMuted*(self: Module, chatId: string) = - self.view.chatsModel().changeMutedOnItemById(chatId, muted=true) - -method onChatUnmuted*(self: Module, chatId: string) = - self.view.chatsModel().changeMutedOnItemById(chatId, muted=false) +method changeMutedOnChat*(self: Module, chatId: string, muted: bool) = + self.view.chatsModel().changeMutedOnItemById(chatId, muted) method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, permissionId: string) = self.rebuildCommunityTokenPermissionsModel() @@ -1175,6 +1172,7 @@ proc addOrUpdateChat(self: Module, self.updateActiveChatMembership() if chatExists: + self.changeMutedOnChat(chat.id, chat.muted) if (chat.chatType == ChatType.PrivateGroupChat): self.onGroupChatDetailsUpdated(chat.id, chat.name, chat.color, chat.icon) elif (chat.chatType != ChatType.OneToOne): diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index 7e3905c300..65d2961f2d 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -200,8 +200,8 @@ QtObject: proc unmuteChat*(self: View, chatId: string) {.slot.} = self.delegate.unmuteChat(chatId) - proc muteCategory*(self: View, categoryId: string) {.slot.} = - self.delegate.muteCategory(categoryId) + proc muteCategory*(self: View, categoryId: string, interval: int) {.slot.} = + self.delegate.muteCategory(categoryId, interval) proc unmuteCategory*(self: View, categoryId: string) {.slot.} = self.delegate.unmuteCategory(categoryId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 979cfa31c1..7f049d7772 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1648,9 +1648,9 @@ QtObject: error "Error sharing community", msg = e.msg result = "Error sharing community: " & e.msg - proc muteCategory*(self: Service, communityId: string, categoryId: string) = + proc muteCategory*(self: Service, communityId: string, categoryId: string, interval: int) = try: - let response = status_go.muteCategory(communityId, categoryId) + let response = status_go.muteCategory(communityId, categoryId, interval) if (not response.error.isNil): let msg = response.error.message & " categoryId=" & categoryId error "error while mute category ", msg diff --git a/src/backend/communities.nim b/src/backend/communities.nim index f106b277c9..758e58dc36 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -9,13 +9,17 @@ export response_type proc getCommunityTags*(): RpcResponse[JsonNode] {.raises: [Exception].} = result = callPrivateRPC("communityTags".prefix) -proc muteCategory*(communityId: string, categoryId: string): RpcResponse[JsonNode] {.raises: [Exception].} = - let payload = %* [communityId, categoryId] - result = callPrivateRPC("muteCommunityCategory".prefix, payload) +proc muteCategory*(communityId: string, categoryId: string, interval: int): RpcResponse[JsonNode] {.raises: [Exception].} = + result = callPrivateRPC("muteCommunityCategory".prefix, %* [ + { + "communityId": communityId, + "categoryId": categoryId, + "mutedType": interval, + } + ]) proc unmuteCategory*(communityId: string, categoryId: string): RpcResponse[JsonNode] {.raises: [Exception].} = - let payload = %* [communityId, categoryId] - result = callPrivateRPC("unmuteCommunityCategory".prefix, payload) + result = callPrivateRPC("unmuteCommunityCategory".prefix, %* [communityId, categoryId]) proc getCuratedCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} = let payload = %* [] diff --git a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml index 111da8f299..9893e3961b 100644 --- a/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Chat/views/CommunityColumnView.qml @@ -14,6 +14,8 @@ import utils 1.0 import shared 1.0 import shared.popups 1.0 import shared.status 1.0 +import shared.controls.chat.menuItems 1.0 + import "../popups/community" import "../panels" import "../panels/communities" @@ -229,18 +231,24 @@ Item { } categoryPopupMenu: StatusMenu { - + id: contextMenuCategory property var categoryItem + MuteChatMenuItem { + enabled: !!categoryItem && !categoryItem.muted + title: qsTr("Mute category") + onMuteTriggered: { + root.communitySectionModule.muteCategory(categoryItem.itemId, interval) + contextMenuCategory.close() + } + } + StatusAction { - text: !!categoryItem ? categoryItem.muted ? qsTr("Unmute category") : qsTr("Mute category") : "" + enabled: !!categoryItem && categoryItem.muted + text: qsTr("Unmute category") icon.name: "notification" onTriggered: { - if (categoryItem.muted) { - root.communitySectionModule.unmuteCategory(categoryItem.itemId) - } else { - root.communitySectionModule.muteCategory(categoryItem.itemId) - } + root.communitySectionModule.unmuteCategory(categoryItem.itemId) } } diff --git a/vendor/status-go b/vendor/status-go index e8c4b7647f..d73c886d3b 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit e8c4b7647f67564c1d2b9534c8487202e91324d7 +Subproject commit d73c886d3b093c2018dcf82089dc1b11160ad736