diff --git a/src/app_service/service/chat/dto/chat.nim b/src/app_service/service/chat/dto/chat.nim index 5aaca0473a..ed3cbe1048 100644 --- a/src/app_service/service/chat/dto/chat.nim +++ b/src/app_service/service/chat/dto/chat.nim @@ -94,6 +94,7 @@ type ChatDto* = object highlight*: bool permissions*: Permission hideIfPermissionsNotMet*: bool + tokenGated*: bool type ClearedHistoryDto* = object chatId*: string @@ -262,6 +263,7 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto = # This should be fixed in status-go, but would be a breaking change discard jsonObj.getProp("categoryID", result.categoryId) discard jsonObj.getProp("hideIfPermissionsNotMet", result.hideIfPermissionsNotMet) + discard jsonObj.getProp("tokenGated", result.tokenGated) discard jsonObj.getProp("position", result.position) discard jsonObj.getProp("communityId", result.communityId) discard jsonObj.getProp("profile", result.profile) @@ -301,13 +303,16 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto = result.id = result.communityId & result.id # 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.chatType = ChatType.CommunityChat result.communityId = communityId if communityId != "": 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 = return chatDto.chatType == ChatType.OneToOne diff --git a/src/app_service/service/community/dto/community.nim b/src/app_service/service/community/dto/community.nim index 78483c53f3..16ad0a0032 100644 --- a/src/app_service/service/community/dto/community.nim +++ b/src/app_service/service/community/dto/community.nim @@ -415,11 +415,6 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto = discard jsonObj.getProp("encrypted", result.encrypted) 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 if(jsonObj.getProp("categories", categoriesObj)): for _, categoryObj in categoriesObj: @@ -448,6 +443,11 @@ proc toCommunityDto*(jsonObj: JsonNode): CommunityDto = for memberId, memberObj in membersObj: 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 if(jsonObj.getProp("tags", tagsObj)): toUgly(result.tags, tagsObj) @@ -610,6 +610,14 @@ proc getCommunityChat*(self: CommunityDto, chatId: string): ChatDto = if chats.len > 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 = for communityChat in self.chats: if chatId == communityChat.id: diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index eb167cbe98..2cd0eb590b 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1306,7 +1306,8 @@ QtObject: let maxPosition = if chatsForCategory.len > 0: chatsForCategory[^1].position else: -1 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 self.chatService.updateOrAddChat(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}") 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. let data = CommunityChatArgs(chat: chatDto) diff --git a/vendor/status-go b/vendor/status-go index 49eaabaca5..2bc2099d55 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 49eaabaca5100368c5b39fb8c107aad2535371e5 +Subproject commit 2bc2099d55407af2c56bebe849ffed12929761ca