From 2d4de5da6fd5ced04d425d2ab1fa85d8eb058489 Mon Sep 17 00:00:00 2001 From: MishkaRogachev Date: Fri, 31 May 2024 16:06:26 +0200 Subject: [PATCH] fix: cherry-pick https://github.com/status-im/status-desktop/pull/14977 --- src/app/modules/main/chat_section/module.nim | 21 +++++++++++++------ .../service/community/dto/community.nim | 6 ++++++ src/app_service/service/community/service.nim | 1 + .../Communities/views/CommunityColumnView.qml | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 1960bd19e3..254dd2e3a9 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -700,12 +700,21 @@ proc getChatItemFromChatDto( var viewersCanPostReactions = true if self.controller.isCommunity: let communityChat = community.getCommunityChat(chatDto.id) - # Some properties are only available on CommunityChat (they are useless for normal chats) - canPost = communityChat.canPost - canView = communityChat.canView - canPostReactions = communityChat.canPostReactions - hideIfPermissionsNotMet = communityChat.hideIfPermissionsNotMet - viewersCanPostReactions = communityChat.viewersCanPostReactions + # NOTE: workaround for new community chat, which is delivered in chatDto before the community will know about that + if community.hasCommunityChat(chatDto.id): + let communityChat = community.getCommunityChat(chatDto.id) + # Some properties are only available on CommunityChat (they are useless for normal chats) + canPost = communityChat.canPost + canView = communityChat.canView + canPostReactions = communityChat.canPostReactions + hideIfPermissionsNotMet = communityChat.hideIfPermissionsNotMet + viewersCanPostReactions = communityChat.viewersCanPostReactions + else: + canPost = chatDto.canPost + canView = chatDto.canView + canPostReactions = chatDto.canPostReactions + hideIfPermissionsNotMet = chatDto.hideIfPermissionsNotMet + viewersCanPostReactions = chatDto.viewersCanPostReactions result = chat_item.initItem( chatDto.id, diff --git a/src/app_service/service/community/dto/community.nim b/src/app_service/service/community/dto/community.nim index 39b81f390d..6ed0b16062 100644 --- a/src/app_service/service/community/dto/community.nim +++ b/src/app_service/service/community/dto/community.nim @@ -612,6 +612,12 @@ proc getCommunityChat*(self: CommunityDto, chatId: string): ChatDto = if chats.len > 0: return chats[0] +proc hasCommunityChat*(self: CommunityDto, chatId: string): bool = + for communityChat in self.chats: + if chatId == communityChat.id: + return true + return false + proc isOwner*(self: CommunityDto): bool = return self.memberRole == MemberRole.Owner diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index b3b8c82975..db86179f84 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1312,6 +1312,7 @@ QtObject: self.communities[communityId].chats.add(chatDto) let data = CommunityChatArgs(chat: chatDto) self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, data) + except Exception as e: error "Error creating community channel", msg = e.msg, communityId, name, description, procName="createCommunityChannel" diff --git a/ui/app/AppLayouts/Communities/views/CommunityColumnView.qml b/ui/app/AppLayouts/Communities/views/CommunityColumnView.qml index 443a37ebd4..69a5229d71 100644 --- a/ui/app/AppLayouts/Communities/views/CommunityColumnView.qml +++ b/ui/app/AppLayouts/Communities/views/CommunityColumnView.qml @@ -553,7 +553,7 @@ Item { property var deleteChatConfirmationDialog onCreateCommunityChannel: function (chName, chDescription, chEmoji, chColor, - chCategoryId, hideIfPermissionsNotMet) { + chCategoryId, viewOnlyCanAddReaction, hideIfPermissionsNotMet) { root.store.createCommunityChannel(chName, chDescription, chEmoji, chColor, chCategoryId, viewOnlyCanAddReaction, hideIfPermissionsNotMet) chatId = root.store.currentChatContentModule().chatDetails.id