feat(communities): Add muting category methods

Closes: #5975
This commit is contained in:
Boris Melnik 2022-06-29 17:30:40 +03:00
parent 1e7c648300
commit bb2c9e02c2
13 changed files with 126 additions and 2 deletions

View File

@ -123,7 +123,7 @@ method `notificationsCount=`*(self: var BaseItem, value: int) {.inline base.} =
method muted*(self: BaseItem): bool {.inline base.} =
self.muted
method `muted=`*(self: var BaseItem, value: bool) {.inline base.} =
method `muted=`*(self: BaseItem, value: bool) {.inline base.} =
self.muted = value
method blocked*(self: BaseItem): bool {.inline base.} =

View File

@ -171,6 +171,16 @@ proc init*(self: Controller) =
let args = ReloadMessagesArgs(e)
if (args.communityId == self.sectionId):
self.messageService.asyncLoadInitialMessagesForChat(self.getActiveChatId())
self.events.on(SIGNAL_CATEGORY_MUTED) do(e: Args):
let args = CategoryArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCategoryMuted(args.categoryId)
self.events.on(SIGNAL_CATEGORY_UNMUTED) do(e: Args):
let args = CategoryArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCategoryUnmuted(args.categoryId)
self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args):
var args = ContactArgs(e)
@ -422,6 +432,12 @@ proc editCommunity*(
proc exportCommunity*(self: Controller): string =
self.communityService.exportCommunity(self.sectionId)
method muteCategory*(self: Controller, categoryId: string) =
self.communityService.muteCategory(self.sectionId, categoryId)
method unmuteCategory*(self: Controller, categoryId: string) =
self.communityService.unmuteCategory(self.sectionId, categoryId)
proc setCommunityMuted*(self: Controller, muted: bool) =
self.communityService.setCommunityMuted(self.sectionId, muted)

View File

@ -175,6 +175,18 @@ method muteChat*(self: AccessInterface, chatId: string) {.base.} =
method unmuteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method muteCategory*(self: AccessInterface, categoryId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method unmuteCategory*(self: AccessInterface, categoryId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onCategoryMuted*(self: AccessInterface, categoryId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onCategoryUnmuted*(self: AccessInterface, categoryId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method markAllMessagesRead*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -67,15 +67,19 @@ proc toJsonNode*(self: Item): JsonNode =
proc appendSubItems*(self: Item, items: seq[SubItem]) =
self.subItems.appendItems(items)
self.BaseItem.muted = self.subItems.isAllMuted()
proc appendSubItem*(self: Item, item: SubItem) =
self.subItems.appendItem(item)
self.BaseItem.muted = self.subItems.isAllMuted()
proc prependSubItems*(self: Item, items: seq[SubItem]) =
self.subItems.prependItems(items)
self.BaseItem.muted = self.subItems.isAllMuted()
proc prependSubItem*(self: Item, item: SubItem) =
self.subItems.prependItem(item)
self.BaseItem.muted = self.subItems.isAllMuted()
proc setActiveSubItem*(self: Item, subItemId: string) =
self.subItems.setActiveItem(subItemId)

View File

@ -249,7 +249,16 @@ QtObject:
return
if self.items[i].subItems.muteUnmuteItemById(id, mute):
self.items[i].BaseItem.muted = self.items[i].subItems.isAllMuted()
return
proc muteUnmuteItemsOrSubItemsByCategoryId*(self: Model, categoryId: string, mute: bool) =
for i in 0 ..< self.items.len:
if(self.items[i].categoryId == categoryId):
let index = self.createIndex(i, 0, nil)
self.items[i].subItems.muteUnmuteAll(mute)
self.items[i].BaseItem.muted = mute
self.dataChanged(index, index, @[ModelRole.Muted.int])
proc blockUnblockItemOrSubItemById*(self: Model, id: string, blocked: bool) =
for i in 0 ..< self.items.len:

View File

@ -577,6 +577,18 @@ method muteChat*(self: Module, chatId: string) =
method unmuteChat*(self: Module, chatId: string) =
self.controller.unmuteChat(chatId)
method muteCategory*(self: Module, categoryId: string) =
self.controller.muteCategory(categoryId)
method unmuteCategory*(self: Module, categoryId: string) =
self.controller.unmuteCategory(categoryId)
method onCategoryMuted*(self: Module, categoryId: string) =
self.view.chatsModel().muteUnmuteItemsOrSubItemsByCategoryId(categoryId, true)
method onCategoryUnmuted*(self: Module, categoryId: string) =
self.view.chatsModel().muteUnmuteItemsOrSubItemsByCategoryId(categoryId, false)
method onChatMuted*(self: Module, chatId: string) =
self.view.chatsModel().muteUnmuteItemOrSubItemById(chatId, mute=true)

View File

@ -204,6 +204,18 @@ QtObject:
return true
return false
proc muteUnmuteAll*(self: SubModel, mute: bool) =
for i in 0 ..< self.items.len:
let index = self.createIndex(i, 0, nil)
self.items[i].BaseItem.muted = mute
self.dataChanged(index, index, @[ModelRole.Muted.int])
proc isAllMuted*(self: SubModel): bool =
for i in 0 ..< self.items.len:
if not self.items[i].BaseItem.muted:
return false
return self.items.len > 0
proc blockUnblockItemById*(self: SubModel, id: string, blocked: bool): bool =
## even we're not able to block specific channel of community now, this is here more as a predisposition
## for that feature, which may be added easy later.

View File

@ -154,6 +154,12 @@ QtObject:
proc unmuteChat*(self: View, chatId: string) {.slot.} =
self.delegate.unmuteChat(chatId)
proc muteCategory*(self: View, categoryId: string) {.slot.} =
self.delegate.muteCategory(categoryId)
proc unmuteCategory*(self: View, categoryId: string) {.slot.} =
self.delegate.unmuteCategory(categoryId)
proc markAllMessagesRead*(self: View, chatId: string) {.slot.} =
self.delegate.markAllMessagesRead(chatId)

View File

@ -38,6 +38,7 @@ type CommunityMembershipRequestDto* = object
type CommunitySettingsDto* = object
id*: string
historyArchiveSupportEnabled*: bool
categoriesMuted*: seq[string]
type CommunityAdminSettingsDto* = object
pinMessageAllMembersEnabled*: bool

View File

@ -69,6 +69,10 @@ type
communityId*: string
muted*: bool
CategoryArgs* = ref object of Args
communityId*: string
categoryId*: string
# Signals which may be emitted by this service:
const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
@ -93,6 +97,8 @@ const SIGNAL_COMMUNITY_MEMBER_REMOVED* = "communityMemberRemoved"
const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity"
const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound"
const SIGNAL_COMMUNITY_MUTED* = "communityMuted"
const SIGNAL_CATEGORY_MUTED* = "categoryMuted"
const SIGNAL_CATEGORY_UNMUTED* = "categoryUnmuted"
QtObject:
type
@ -1072,6 +1078,32 @@ QtObject:
error "Error inviting to community", msg = e.msg
result = "Error exporting community: " & e.msg
proc muteCategory*(self: Service, communityId: string, categoryId: string) =
try:
let response = status_go.muteCategory(communityId, categoryId)
if (not response.error.isNil):
let msg = response.error.message & " categoryId=" & categoryId
error "error while mute category ", msg
return
self.events.emit(SIGNAL_CATEGORY_MUTED, CategoryArgs(communityId: communityId, categoryId: categoryId))
except Exception as e:
error "Error muting category", msg = e.msg
proc unmuteCategory*(self: Service, communityId: string, categoryId: string) =
try:
let response = status_go.unmuteCategory(communityId, categoryId)
if (not response.error.isNil):
let msg = response.error.message & " categoryId=" & categoryId
error "error while unmute category ", msg
return
self.events.emit(SIGNAL_CATEGORY_UNMUTED, CategoryArgs(communityId: communityId, categoryId: categoryId))
except Exception as e:
error "Error unmuting category", msg = e.msg
proc removeUserFromCommunity*(self: Service, communityId: string, pubKey: string) =
try:
discard status_go.removeUserFromCommunity(communityId, pubKey)

View File

@ -8,6 +8,14 @@ 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 unmuteCategory*(communityId: string, categoryId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [communityId, categoryId]
result = callPrivateRPC("unmuteCommunityCategory".prefix, payload)
proc getJoinedComunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []

View File

@ -234,6 +234,18 @@ Item {
categoryItem = obj
}
StatusMenuItem {
text: categoryItem.muted ? qsTr("Unmute category") : qsTr("Mute category")
icon.name: "notification"
onTriggered: {
if (categoryItem.muted) {
root.communitySectionModule.unmuteCategory(categoryItem.itemId)
} else {
root.communitySectionModule.muteCategory(categoryItem.itemId)
}
}
}
StatusMenuItem {
enabled: communityData.amISectionAdmin
//% "Edit Category"

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 0322ac497bf9e4852b99780f4ff08377a8c3f267
Subproject commit 3e65e36fa6312e8c9ccd7e41dc0f8bfc84b37e2e