perf: use community members for unpermissioned channels (#15156)
Fixes #15149
This commit is contained in:
parent
775df8097c
commit
7a7dbb631c
|
@ -94,6 +94,7 @@ type ChatDto* = object
|
||||||
highlight*: bool
|
highlight*: bool
|
||||||
permissions*: Permission
|
permissions*: Permission
|
||||||
hideIfPermissionsNotMet*: bool
|
hideIfPermissionsNotMet*: bool
|
||||||
|
tokenGated*: bool
|
||||||
|
|
||||||
type ClearedHistoryDto* = object
|
type ClearedHistoryDto* = object
|
||||||
chatId*: string
|
chatId*: string
|
||||||
|
@ -262,6 +263,7 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto =
|
||||||
# This should be fixed in status-go, but would be a breaking change
|
# This should be fixed in status-go, but would be a breaking change
|
||||||
discard jsonObj.getProp("categoryID", result.categoryId)
|
discard jsonObj.getProp("categoryID", result.categoryId)
|
||||||
discard jsonObj.getProp("hideIfPermissionsNotMet", result.hideIfPermissionsNotMet)
|
discard jsonObj.getProp("hideIfPermissionsNotMet", result.hideIfPermissionsNotMet)
|
||||||
|
discard jsonObj.getProp("tokenGated", result.tokenGated)
|
||||||
discard jsonObj.getProp("position", result.position)
|
discard jsonObj.getProp("position", result.position)
|
||||||
discard jsonObj.getProp("communityId", result.communityId)
|
discard jsonObj.getProp("communityId", result.communityId)
|
||||||
discard jsonObj.getProp("profile", result.profile)
|
discard jsonObj.getProp("profile", result.profile)
|
||||||
|
@ -301,13 +303,16 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto =
|
||||||
result.id = result.communityId & result.id
|
result.id = result.communityId & result.id
|
||||||
|
|
||||||
# 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, communityMembers: seq[ChatMember]): ChatDto =
|
||||||
result = jsonObj.toChatDto()
|
result = jsonObj.toChatDto()
|
||||||
result.chatType = ChatType.CommunityChat
|
result.chatType = ChatType.CommunityChat
|
||||||
result.communityId = communityId
|
result.communityId = communityId
|
||||||
if communityId != "":
|
if communityId != "":
|
||||||
result.id = communityId & result.id.replace(communityId, "") # Adding communityID prefix in case it's not available
|
result.id = communityId & result.id.replace(communityId, "") # Adding communityID prefix in case it's not available
|
||||||
|
|
||||||
|
if not result.tokenGated:
|
||||||
|
result.members = communityMembers
|
||||||
|
|
||||||
proc isOneToOneChat*(chatDto: ChatDto): bool =
|
proc isOneToOneChat*(chatDto: ChatDto): bool =
|
||||||
return chatDto.chatType == ChatType.OneToOne
|
return chatDto.chatType == ChatType.OneToOne
|
||||||
|
|
||||||
|
|
|
@ -415,11 +415,6 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
|
||||||
discard jsonObj.getProp("encrypted", result.encrypted)
|
discard jsonObj.getProp("encrypted", result.encrypted)
|
||||||
discard jsonObj.getProp("isMember", result.isMember)
|
discard jsonObj.getProp("isMember", result.isMember)
|
||||||
|
|
||||||
var chatsObj: JsonNode
|
|
||||||
if(jsonObj.getProp("chats", chatsObj)):
|
|
||||||
for _, chatObj in chatsObj:
|
|
||||||
result.chats.add(chatObj.toChatDto(result.id))
|
|
||||||
|
|
||||||
var categoriesObj: JsonNode
|
var categoriesObj: JsonNode
|
||||||
if(jsonObj.getProp("categories", categoriesObj)):
|
if(jsonObj.getProp("categories", categoriesObj)):
|
||||||
for _, categoryObj in categoriesObj:
|
for _, categoryObj in categoriesObj:
|
||||||
|
@ -448,6 +443,11 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
|
||||||
for memberId, memberObj in membersObj:
|
for memberId, memberObj in membersObj:
|
||||||
result.members.add(toChannelMember(memberObj, memberId))
|
result.members.add(toChannelMember(memberObj, memberId))
|
||||||
|
|
||||||
|
var chatsObj: JsonNode
|
||||||
|
if(jsonObj.getProp("chats", chatsObj)):
|
||||||
|
for _, chatObj in chatsObj:
|
||||||
|
result.chats.add(chatObj.toChatDto(result.id, result.members))
|
||||||
|
|
||||||
var tagsObj: JsonNode
|
var tagsObj: JsonNode
|
||||||
if(jsonObj.getProp("tags", tagsObj)):
|
if(jsonObj.getProp("tags", tagsObj)):
|
||||||
toUgly(result.tags, tagsObj)
|
toUgly(result.tags, tagsObj)
|
||||||
|
@ -610,6 +610,14 @@ proc getCommunityChat*(self: CommunityDto, chatId: string): ChatDto =
|
||||||
if chats.len > 0:
|
if chats.len > 0:
|
||||||
return chats[0]
|
return chats[0]
|
||||||
|
|
||||||
|
proc getCommunityChatIndex*(self: CommunityDto, chatId: string): int =
|
||||||
|
var idx = 0
|
||||||
|
for communityChat in self.chats:
|
||||||
|
if chatId == communityChat.id:
|
||||||
|
return idx
|
||||||
|
idx.inc()
|
||||||
|
return -1
|
||||||
|
|
||||||
proc hasCommunityChat*(self: CommunityDto, chatId: string): bool =
|
proc hasCommunityChat*(self: CommunityDto, chatId: string): bool =
|
||||||
for communityChat in self.chats:
|
for communityChat in self.chats:
|
||||||
if chatId == communityChat.id:
|
if chatId == communityChat.id:
|
||||||
|
|
|
@ -1306,7 +1306,8 @@ QtObject:
|
||||||
let maxPosition = if chatsForCategory.len > 0: chatsForCategory[^1].position else: -1
|
let maxPosition = if chatsForCategory.len > 0: chatsForCategory[^1].position else: -1
|
||||||
|
|
||||||
for chatObj in chatsJArr:
|
for chatObj in chatsJArr:
|
||||||
var chatDto = chatObj.toChatDto(communityId)
|
let community = self.communities[communityId]
|
||||||
|
var chatDto = chatObj.toChatDto(communityId, community.members)
|
||||||
chatDto.position = maxPosition + 1
|
chatDto.position = maxPosition + 1
|
||||||
self.chatService.updateOrAddChat(chatDto)
|
self.chatService.updateOrAddChat(chatDto)
|
||||||
self.communities[communityId].chats.add(chatDto)
|
self.communities[communityId].chats.add(chatDto)
|
||||||
|
@ -1355,8 +1356,11 @@ QtObject:
|
||||||
raise newException(RpcException, fmt"editCommunityChannel; there is no `chats` key in the response for community id: {communityId}")
|
raise newException(RpcException, fmt"editCommunityChannel; there is no `chats` key in the response for community id: {communityId}")
|
||||||
|
|
||||||
for chatObj in chatsJArr:
|
for chatObj in chatsJArr:
|
||||||
var chatDto = chatObj.toChatDto(communityId)
|
let community = self.communities[communityId]
|
||||||
|
var chatDto = chatObj.toChatDto(communityId, community.members)
|
||||||
|
let chatIndex = community.getCommunityChatIndex(chatDto.id)
|
||||||
|
if chatIndex > -1:
|
||||||
|
self.communities[communityId].chats[chatIndex] = chatDto
|
||||||
self.chatService.updateOrAddChat(chatDto) # we have to update chats stored in the chat service.
|
self.chatService.updateOrAddChat(chatDto) # we have to update chats stored in the chat service.
|
||||||
|
|
||||||
let data = CommunityChatArgs(chat: chatDto)
|
let data = CommunityChatArgs(chat: chatDto)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 49eaabaca5100368c5b39fb8c107aad2535371e5
|
Subproject commit 2bc2099d55407af2c56bebe849ffed12929761ca
|
Loading…
Reference in New Issue