feat: use last know channelPermissionResponse data in UI

This commit makes use of the newly introduced APIs added in

https://github.com/status-im/status-go/pull/3657

The idea is that clients can retrieve the last known channel permission
state from the database make use of the in the UI, before waiting for an
async onchain check to finish.

Closes #11156
This commit is contained in:
Pascal Precht 2023-06-22 09:05:05 +02:00 committed by r4bbit
parent 62fec738a1
commit d38ca1b71e
9 changed files with 172 additions and 154 deletions

View File

@ -114,10 +114,10 @@ proc asyncCheckPermissionsToJoin*(self: Controller) =
self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId()) self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId())
proc asyncCheckAllChannelsPermissions*(self: Controller) = proc asyncCheckAllChannelsPermissions*(self: Controller) =
self.communityService.asyncCheckAllChannelsPermissions(self.getMySectionId()) self.chatService.asyncCheckAllChannelsPermissions(self.getMySectionId())
proc asyncCheckChannelPermissions*(self: Controller, communityId: string, chatId: string) = proc asyncCheckChannelPermissions*(self: Controller, communityId: string, chatId: string) =
self.communityService.asyncCheckChannelPermissions(communityId, chatId) self.chatService.asyncCheckChannelPermissions(communityId, chatId)
proc asyncCheckPermissions*(self: Controller) = proc asyncCheckPermissions*(self: Controller) =
self.asyncCheckPermissionsToJoin() self.asyncCheckPermissionsToJoin()
@ -699,4 +699,3 @@ proc getContractAddressesForToken*(self: Controller, symbol: string): Table[int,
proc getCommunityTokenList*(self: Controller): seq[CommunityTokenDto] = proc getCommunityTokenList*(self: Controller): seq[CommunityTokenDto] =
return self.communityTokensService.getCommunityTokens(self.getMySectionId()) return self.communityTokensService.getCommunityTokens(self.getMySectionId())

View File

@ -403,6 +403,7 @@ method onChatsLoaded*(
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
self.view.setAmIMember(community.joined) self.view.setAmIMember(community.joined)
self.initCommunityTokenPermissionsModel(channelGroup) self.initCommunityTokenPermissionsModel(channelGroup)
self.onCommunityCheckAllChannelsPermissionsResponse(channelGroup.channelPermissions)
self.controller.asyncCheckPermissionsToJoin() self.controller.asyncCheckPermissionsToJoin()
let activeChatId = self.controller.getActiveChatId() let activeChatId = self.controller.getActiveChatId()
@ -895,8 +896,9 @@ proc updateChannelPermissionViewData*(self: Module, chatId: string, viewOnlyPerm
self.updateTokenPermissionModel(viewAndPostPermissions.permissions, community) self.updateTokenPermissionModel(viewAndPostPermissions.permissions, community)
self.updateChatRequiresPermissions(chatId) self.updateChatRequiresPermissions(chatId)
self.updateChatLocked(chatId) self.updateChatLocked(chatId)
self.chatContentModules[chatId].onUpdateViewOnlyPermissionsSatisfied(viewOnlyPermissions.satisfied) if self.chatContentModules.hasKey(chatId):
self.chatContentModules[chatId].onUpdateViewAndPostPermissionsSatisfied(viewAndPostPermissions.satisfied) self.chatContentModules[chatId].onUpdateViewOnlyPermissionsSatisfied(viewOnlyPermissions.satisfied)
self.chatContentModules[chatId].onUpdateViewAndPostPermissionsSatisfied(viewAndPostPermissions.satisfied)
method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) = method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) =
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
@ -921,10 +923,14 @@ method onCommunityTokenPermissionDeletionFailed*(self: Module, communityId: stri
method onCommunityCheckChannelPermissionsResponse*(self: Module, chatId: string, checkChannelPermissionsResponse: CheckChannelPermissionsResponseDto) = method onCommunityCheckChannelPermissionsResponse*(self: Module, chatId: string, checkChannelPermissionsResponse: CheckChannelPermissionsResponseDto) =
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
self.updateChannelPermissionViewData(chatId, checkChannelPermissionsResponse.viewOnlyPermissions, checkChannelPermissionsResponse.viewAndPostPermissions, community) if community.id != "":
self.updateChannelPermissionViewData(chatId, checkChannelPermissionsResponse.viewOnlyPermissions, checkChannelPermissionsResponse.viewAndPostPermissions, community)
method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, checkAllChannelsPermissionsResponse: CheckAllChannelsPermissionsResponseDto) = method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, checkAllChannelsPermissionsResponse: CheckAllChannelsPermissionsResponseDto) =
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
if community.id == "":
return
for chatId, permissionResult in checkAllChannelsPermissionsResponse.channels: for chatId, permissionResult in checkAllChannelsPermissionsResponse.channels:
self.updateChannelPermissionViewData(chatId, permissionResult.viewOnlyPermissions, permissionResult.viewAndPostPermissions, community) self.updateChannelPermissionViewData(chatId, permissionResult.viewOnlyPermissions, permissionResult.viewAndPostPermissions, community)

View File

@ -13,3 +13,44 @@ const asyncGetChannelGroupsTask: Task = proc(argEncoded: string) {.gcsafe, nimca
"channelGroups": response.result "channelGroups": response.result
} }
arg.finish(responseJson) arg.finish(responseJson)
type
AsyncCheckChannelPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string
chatId: string
const asyncCheckChannelPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckChannelPermissionsTaskArg](argEncoded)
try:
let response = status_communities.checkCommunityChannelPermissions(arg.communityId, arg.chatId)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,
"chatId": arg.chatId,
"error": "",
})
except Exception as e:
arg.finish(%* {
"communityId": arg.communityId,
"chatId": arg.chatId,
"error": e.msg,
})
type
AsyncCheckAllChannelsPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string
const asyncCheckAllChannelsPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckAllChannelsPermissionsTaskArg](argEncoded)
try:
let response = status_communities.checkAllCommunityChannelsPermissions(arg.communityId)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,
"error": "",
})
except Exception as e:
arg.finish(%* {
"communityId": arg.communityId,
"error": e.msg,
})

View File

@ -1,6 +1,6 @@
{.used.} {.used.}
import json, strformat, strutils import json, strformat, strutils, tables
import ../../community/dto/community import ../../community/dto/community
include ../../../common/json_utils include ../../../common/json_utils
@ -40,6 +40,20 @@ type ChatMember* = object
joined*: bool joined*: bool
role*: MemberRole role*: MemberRole
type CheckPermissionsResultDto* = object
criteria*: seq[bool]
type ViewOnlyOrViewAndPostPermissionsResponseDto* = object
satisfied*: bool
permissions*: Table[string, CheckPermissionsResultDto]
type CheckChannelPermissionsResponseDto* = object
viewOnlyPermissions*: ViewOnlyOrViewAndPostPermissionsResponseDto
viewAndPostPermissions*: ViewOnlyOrViewAndPostPermissionsResponseDto
type CheckAllChannelsPermissionsResponseDto* = object
channels*: Table[string, CheckChannelPermissionsResponseDto]
type ChatDto* = object type ChatDto* = object
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, id*: string # ID is the id of the chat, for public chats it is the name e.g. status,
# for one-to-one is the hex encoded public key and for group chats is a random # for one-to-one is the hex encoded public key and for group chats is a random
@ -98,6 +112,7 @@ type ChannelGroupDto* = object
encrypted*: bool encrypted*: bool
unviewedMessagesCount*: int unviewedMessagesCount*: int
unviewedMentionsCount*: int unviewedMentionsCount*: int
channelPermissions*: CheckAllChannelsPermissionsResponseDto
type ClearedHistoryDto* = object type ClearedHistoryDto* = object
chatId*: string chatId*: string
@ -134,6 +149,34 @@ proc `$`*(self: ChatDto): string =
highlight: {self.highlight} highlight: {self.highlight}
)""" )"""
proc toCheckPermissionsResultDto*(jsonObj: JsonNode): CheckPermissionsResultDto =
result = CheckPermissionsResultDto()
var criteriaObj: JsonNode
if(jsonObj.getProp("criteria", criteriaObj) and criteriaObj.kind == JArray):
for c in criteriaObj:
result.criteria.add(c.getBool)
proc toViewOnlyOrViewAndPostPermissionsResponseDto*(jsonObj: JsonNode): ViewOnlyOrViewAndPostPermissionsResponseDto =
result = ViewOnlyOrViewAndPostPermissionsResponseDto()
discard jsonObj.getProp("satisfied", result.satisfied)
var permissionsObj: JsonNode
if(jsonObj.getProp("permissions", permissionsObj) and permissionsObj.kind == JObject):
result.permissions = initTable[string, CheckPermissionsResultDto]()
for permissionId, permission in permissionsObj:
result.permissions[permissionId] = permission.toCheckPermissionsResultDto
proc toCheckChannelPermissionsResponseDto*(jsonObj: JsonNode): CheckChannelPermissionsResponseDto =
result = CheckChannelPermissionsResponseDto()
var viewOnlyPermissionsObj: JsonNode
if(jsonObj.getProp("viewOnlyPermissions", viewOnlyPermissionsObj) and viewOnlyPermissionsObj.kind == JObject):
result.viewOnlyPermissions = viewOnlyPermissionsObj.toViewOnlyOrViewAndPostPermissionsResponseDto()
var viewAndPostPermissionsObj: JsonNode
if(jsonObj.getProp("viewAndPostPermissions", viewAndPostPermissionsObj) and viewAndPostPermissionsObj.kind == JObject):
result.viewAndPostPermissions = viewAndPostPermissionsObj.toViewOnlyOrViewAndPostPermissionsResponseDto()
proc toClearedHistoryDto*(jsonObj: JsonNode): ClearedHistoryDto = proc toClearedHistoryDto*(jsonObj: JsonNode): ClearedHistoryDto =
result = ClearedHistoryDto() result = ClearedHistoryDto()
discard jsonObj.getProp("chatId", result.chatId) discard jsonObj.getProp("chatId", result.chatId)
@ -320,6 +363,15 @@ proc toChannelGroupDto*(jsonObj: JsonNode): ChannelGroupDto =
discard jsonObj.getProp("color", result.color) discard jsonObj.getProp("color", result.color)
discard jsonObj.getProp("muted", result.muted) discard jsonObj.getProp("muted", result.muted)
var responseDto = CheckAllChannelsPermissionsResponseDto()
responseDto.channels = initTable[string, CheckChannelPermissionsResponseDto]()
result.channelPermissions = responseDto
var checkChannelPermissionResponsesObj: JsonNode
if(jsonObj.getProp("checkChannelPermissionResponses", checkChannelPermissionResponsesObj) and checkChannelPermissionResponsesObj.kind == JObject):
for channelId, permissionResponse in checkChannelPermissionResponsesObj:
result.channelPermissions.channels[channelId] = permissionResponse.toCheckChannelPermissionsResponseDto()
# To parse Community chats to ChatDto, we need to add the commuity ID and type # To parse Community chats to ChatDto, we need to add the commuity ID and type
proc toChatDto*(jsonObj: JsonNode, communityId: string): ChatDto = proc toChatDto*(jsonObj: JsonNode, communityId: string): ChatDto =
result = jsonObj.toChatDto() result = jsonObj.toChatDto()

View File

@ -8,6 +8,7 @@ import ../activity_center/dto/notification as notification_dto
import ../community/dto/community as community_dto import ../community/dto/community as community_dto
import ../contacts/service as contact_service import ../contacts/service as contact_service
import ../../../backend/chat as status_chat import ../../../backend/chat as status_chat
import ../../../backend/communities as status_communities
import ../../../backend/group_chat as status_group_chat import ../../../backend/group_chat as status_group_chat
import ../../../backend/chatCommands as status_chat_commands import ../../../backend/chatCommands as status_chat_commands
import ../../../app/global/global_singleton import ../../../app/global/global_singleton
@ -86,6 +87,15 @@ type
RpcResponseArgs* = ref object of Args RpcResponseArgs* = ref object of Args
response*: RpcResponse[JsonNode] response*: RpcResponse[JsonNode]
CheckChannelPermissionsResponseArgs* = ref object of Args
communityId*: string
chatId*: string
checkChannelPermissionsResponse*: CheckChannelPermissionsResponseDto
CheckAllChannelsPermissionsResponseArgs* = ref object of Args
communityId*: string
checkAllChannelsPermissionsResponse*: CheckAllChannelsPermissionsResponseDto
# Signals which may be emitted by this service: # Signals which may be emitted by this service:
const SIGNAL_CHANNEL_GROUPS_LOADED* = "channelGroupsLoaded" const SIGNAL_CHANNEL_GROUPS_LOADED* = "channelGroupsLoaded"
@ -108,6 +118,8 @@ const SIGNAL_CHAT_SWITCH_TO_OR_CREATE_1_1_CHAT* = "switchToOrCreateOneToOneChat"
const SIGNAL_CHAT_ADDED_OR_UPDATED* = "chatAddedOrUpdated" const SIGNAL_CHAT_ADDED_OR_UPDATED* = "chatAddedOrUpdated"
const SIGNAL_CHAT_CREATED* = "chatCreated" const SIGNAL_CHAT_CREATED* = "chatCreated"
const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend" const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend"
const SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE* = "checkChannelPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE* = "checkAllChannelsPermissionsResponse"
QtObject: QtObject:
type Service* = ref object of QObject type Service* = ref object of QObject
@ -730,3 +742,56 @@ QtObject:
chat.unviewedMessagesCount = max(0, chat.unviewedMessagesCount - markAsReadCount) chat.unviewedMessagesCount = max(0, chat.unviewedMessagesCount - markAsReadCount)
chat.unviewedMentionsCount = max(0, chat.unviewedMentionsCount - markAsReadMentionsCount) chat.unviewedMentionsCount = max(0, chat.unviewedMentionsCount - markAsReadMentionsCount)
self.updateOrAddChat(chat) self.updateOrAddChat(chat)
proc asyncCheckChannelPermissions*(self: Service, communityId: string, chatId: string) =
let arg = AsyncCheckChannelPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckChannelPermissionsTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckChannelPermissionsDone",
communityId: communityId,
chatId: chatId
)
self.threadpool.start(arg)
proc onAsyncCheckChannelPermissionsDone*(self: Service, rpcResponse: string) {.slot.} =
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking community channel permissions", msg = error.message
return
let communityId = rpcResponseObj{"communityId"}.getStr()
let chatId = rpcResponseObj{"chatId"}.getStr()
let checkChannelPermissionsResponse = rpcResponseObj["response"]["result"].toCheckChannelPermissionsResponseDto()
self.channelGroups[communityId].channelPermissions.channels[chatId] = checkChannelPermissionsResponse
self.events.emit(SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE, CheckChannelPermissionsResponseArgs(communityId: communityId, chatId: chatId, checkChannelPermissionsResponse: checkChannelPermissionsResponse))
except Exception as e:
let errMsg = e.msg
error "error checking all channel permissions: ", errMsg
proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string) =
let arg = AsyncCheckAllChannelsPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckAllChannelsPermissionsTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckAllChannelsPermissionsDone",
communityId: communityId
)
self.threadpool.start(arg)
proc onAsyncCheckAllChannelsPermissionsDone*(self: Service, rpcResponse: string) {.slot.} =
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking all community channel permissions", msg = error.message
return
let communityId = rpcResponseObj{"communityId"}.getStr()
let checkAllChannelsPermissionsResponse = rpcResponseObj["response"]["result"].toCheckAllChannelsPermissionsResponseDto()
self.channelGroups[communityId].channelPermissions = checkAllChannelsPermissionsResponse
self.events.emit(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE, CheckAllChannelsPermissionsResponseArgs(communityId: communityId, checkAllChannelsPermissionsResponse: checkAllChannelsPermissionsResponse))
except Exception as e:
let errMsg = e.msg
error "error checking all channels permissions: ", errMsg

View File

@ -121,44 +121,3 @@ const asyncCheckPermissionsToJoinTask: Task = proc(argEncoded: string) {.gcsafe,
"communityId": arg.communityId, "communityId": arg.communityId,
"error": e.msg, "error": e.msg,
}) })
type
AsyncCheckChannelPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string
chatId: string
const asyncCheckChannelPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckChannelPermissionsTaskArg](argEncoded)
try:
let response = status_go.checkCommunityChannelPermissions(arg.communityId, arg.chatId)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,
"chatId": arg.chatId,
"error": "",
})
except Exception as e:
arg.finish(%* {
"communityId": arg.communityId,
"chatId": arg.chatId,
"error": e.msg,
})
type
AsyncCheckAllChannelsPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string
const asyncCheckAllChannelsPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckAllChannelsPermissionsTaskArg](argEncoded)
try:
let response = status_go.checkAllCommunityChannelsPermissions(arg.communityId)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,
"error": "",
})
except Exception as e:
arg.finish(%* {
"communityId": arg.communityId,
"error": e.msg,
})

View File

@ -83,25 +83,11 @@ type AccountChainIDsCombinationDto* = object
address*: string address*: string
chainIds*: seq[int] chainIds*: seq[int]
type CheckPermissionsResultDto* = object
criteria*: seq[bool]
type CheckPermissionsToJoinResponseDto* = object type CheckPermissionsToJoinResponseDto* = object
satisfied*: bool satisfied*: bool
permissions*: Table[string, CheckPermissionsResultDto] permissions*: Table[string, CheckPermissionsResultDto]
validCombinations*: seq[AccountChainIDsCombinationDto] validCombinations*: seq[AccountChainIDsCombinationDto]
type ViewOnlyOrViewAndPostPermissionsResponseDto* = object
satisfied*: bool
permissions*: Table[string, CheckPermissionsResultDto]
type CheckChannelPermissionsResponseDto* = object
viewOnlyPermissions*: ViewOnlyOrViewAndPostPermissionsResponseDto
viewAndPostPermissions*: ViewOnlyOrViewAndPostPermissionsResponseDto
type CheckAllChannelsPermissionsResponseDto* = object
channels*: Table[string, CheckChannelPermissionsResponseDto]
type CommunityDto* = object type CommunityDto* = object
id*: string id*: string
memberRole*: MemberRole memberRole*: MemberRole
@ -282,13 +268,6 @@ proc toCommunityTokenPermissionDto*(jsonObj: JsonNode): CommunityTokenPermission
if jsonObj.hasKey("key"): if jsonObj.hasKey("key"):
discard jsonObj.getProp("key", result.id) discard jsonObj.getProp("key", result.id)
proc toCheckPermissionsResultDto*(jsonObj: JsonNode): CheckPermissionsResultDto =
result = CheckPermissionsResultDto()
var criteriaObj: JsonNode
if(jsonObj.getProp("criteria", criteriaObj) and criteriaObj.kind == JArray):
for c in criteriaObj:
result.criteria.add(c.getBool)
proc toAccountChainIDsCombinationDto*(jsonObj: JsonNode): AccountChainIDsCombinationDto = proc toAccountChainIDsCombinationDto*(jsonObj: JsonNode): AccountChainIDsCombinationDto =
result = AccountChainIDsCombinationDto() result = AccountChainIDsCombinationDto()
discard jsonObj.getProp("address", result.address) discard jsonObj.getProp("address", result.address)
@ -312,27 +291,6 @@ proc toCheckPermissionsToJoinResponseDto*(jsonObj: JsonNode): CheckPermissionsTo
for permissionId, permission in permissionsObj: for permissionId, permission in permissionsObj:
result.permissions[permissionId] = permission.toCheckPermissionsResultDto result.permissions[permissionId] = permission.toCheckPermissionsResultDto
proc toViewOnlyOrViewAndPostPermissionsResponseDto*(jsonObj: JsonNode): ViewOnlyOrViewAndPostPermissionsResponseDto =
result = ViewOnlyOrViewAndPostPermissionsResponseDto()
discard jsonObj.getProp("satisfied", result.satisfied)
var permissionsObj: JsonNode
if(jsonObj.getProp("permissions", permissionsObj) and permissionsObj.kind == JObject):
result.permissions = initTable[string, CheckPermissionsResultDto]()
for permissionId, permission in permissionsObj:
result.permissions[permissionId] = permission.toCheckPermissionsResultDto
proc toCheckChannelPermissionsResponseDto*(jsonObj: JsonNode): CheckChannelPermissionsResponseDto =
result = CheckChannelPermissionsResponseDto()
var viewOnlyPermissionsObj: JsonNode
if(jsonObj.getProp("viewOnlyPermissions", viewOnlyPermissionsObj) and viewOnlyPermissionsObj.kind == JObject):
result.viewOnlyPermissions = viewOnlyPermissionsObj.toViewOnlyOrViewAndPostPermissionsResponseDto()
var viewAndPostPermissionsObj: JsonNode
if(jsonObj.getProp("viewAndPostPermissions", viewAndPostPermissionsObj) and viewAndPostPermissionsObj.kind == JObject):
result.viewAndPostPermissions = viewAndPostPermissionsObj.toViewOnlyOrViewAndPostPermissionsResponseDto()
proc toCheckAllChannelsPermissionsResponseDto*(jsonObj: JsonNode): CheckAllChannelsPermissionsResponseDto = proc toCheckAllChannelsPermissionsResponseDto*(jsonObj: JsonNode): CheckAllChannelsPermissionsResponseDto =
result = CheckAllChannelsPermissionsResponseDto() result = CheckAllChannelsPermissionsResponseDto()
result.channels = initTable[string, CheckChannelPermissionsResponseDto]() result.channels = initTable[string, CheckChannelPermissionsResponseDto]()

View File

@ -117,15 +117,6 @@ type
communityId*: string communityId*: string
checkPermissionsToJoinResponse*: CheckPermissionsToJoinResponseDto checkPermissionsToJoinResponse*: CheckPermissionsToJoinResponseDto
CheckChannelPermissionsResponseArgs* = ref object of Args
communityId*: string
chatId*: string
checkChannelPermissionsResponse*: CheckChannelPermissionsResponseDto
CheckAllChannelsPermissionsResponseArgs* = ref object of Args
communityId*: string
checkAllChannelsPermissionsResponse*: CheckAllChannelsPermissionsResponseDto
# Signals which may be emitted by this service: # Signals which may be emitted by this service:
const SIGNAL_COMMUNITY_DATA_LOADED* = "communityDataLoaded" const SIGNAL_COMMUNITY_DATA_LOADED* = "communityDataLoaded"
const SIGNAL_COMMUNITY_JOINED* = "communityJoined" const SIGNAL_COMMUNITY_JOINED* = "communityJoined"
@ -188,8 +179,6 @@ const TOKEN_PERMISSIONS_ADDED = "tokenPermissionsAdded"
const TOKEN_PERMISSIONS_MODIFIED = "tokenPermissionsModified" const TOKEN_PERMISSIONS_MODIFIED = "tokenPermissionsModified"
const SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE* = "checkPermissionsToJoinResponse" const SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE* = "checkPermissionsToJoinResponse"
const SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE* = "checkChannelPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE* = "checkAllChannelsPermissionsResponse"
QtObject: QtObject:
type type
@ -1408,59 +1397,6 @@ QtObject:
let errMsg = e.msg let errMsg = e.msg
error "error checking permissions to join: ", errMsg error "error checking permissions to join: ", errMsg
proc asyncCheckChannelPermissions*(self: Service, communityId: string, chatId: string) =
let arg = AsyncCheckChannelPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckChannelPermissionsTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckChannelPermissionsDone",
communityId: communityId,
chatId: chatId
)
self.threadpool.start(arg)
proc onAsyncCheckChannelPermissionsDone*(self: Service, rpcResponse: string) {.slot.} =
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking community channel permissions", msg = error.message
return
let communityId = rpcResponseObj{"communityId"}.getStr()
let chatId = rpcResponseObj{"chatId"}.getStr()
let checkChannelPermissionsResponse = rpcResponseObj["response"]["result"].toCheckChannelPermissionsResponseDto()
self.communities[communityId].channelPermissions.channels[chatId] = checkChannelPermissionsResponse
self.events.emit(SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE, CheckChannelPermissionsResponseArgs(communityId: communityId, chatId: chatId, checkChannelPermissionsResponse: checkChannelPermissionsResponse))
except Exception as e:
let errMsg = e.msg
error "error checking all channel permissions: ", errMsg
proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string) =
let arg = AsyncCheckAllChannelsPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckAllChannelsPermissionsTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckAllChannelsPermissionsDone",
communityId: communityId
)
self.threadpool.start(arg)
proc onAsyncCheckAllChannelsPermissionsDone*(self: Service, rpcResponse: string) {.slot.} =
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking all community channel permissions", msg = error.message
return
let communityId = rpcResponseObj{"communityId"}.getStr()
let checkAllChannelsPermissionsResponse = rpcResponseObj["response"]["result"].toCheckAllChannelsPermissionsResponseDto()
self.communities[communityId].channelPermissions = checkAllChannelsPermissionsResponse
self.events.emit(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE, CheckAllChannelsPermissionsResponseArgs(communityId: communityId, checkAllChannelsPermissionsResponse: checkAllChannelsPermissionsResponse))
except Exception as e:
let errMsg = e.msg
error "error checking all channels permissions: ", errMsg
proc asyncRequestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string) = proc asyncRequestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string) =
try: try:
let arg = AsyncRequestToJoinCommunityTaskArg( let arg = AsyncRequestToJoinCommunityTaskArg(

View File

@ -395,3 +395,5 @@ proc getCommunitiesSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} =
proc requestExtractDiscordChannelsAndCategories*(filesToImport: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} = proc requestExtractDiscordChannelsAndCategories*(filesToImport: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("requestExtractDiscordChannelsAndCategories".prefix, %*[filesToImport]) return callPrivateRPC("requestExtractDiscordChannelsAndCategories".prefix, %*[filesToImport])
proc getCheckChannelPermissionResponses*(communityId: string,): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("getCheckChannelPermissionResponses".prefix, %*[communityId])