From 55ae227c4da0f7040b692321e22616da6905d5b1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 29 May 2024 14:25:29 -0400 Subject: [PATCH] Fix missing reaction and edit buttons on permissioned channels (#14933) * fix poster actions (edit, delete) * use canPost instead * fix chat getting updated without community --- .../chat_content/chat_details.nim | 30 ++++- .../chat_section/chat_content/controller.nim | 8 +- .../chat_content/io_interface.nim | 5 +- .../main/chat_section/chat_content/module.nim | 38 +++++- .../main/chat_section/chat_content/view.nim | 24 +--- src/app/modules/main/chat_section/item.nim | 26 +++- src/app/modules/main/chat_section/module.nim | 111 ++++++++---------- src/app_service/service/chat/dto/chat.nim | 8 +- src/app_service/service/chat/service.nim | 8 +- src/app_service/service/community/service.nim | 9 +- ui/imports/shared/views/chat/MessageView.qml | 20 +++- 11 files changed, 178 insertions(+), 109 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/chat_details.nim b/src/app/modules/main/chat_section/chat_content/chat_details.nim index c4a695e1b2..2cd26ce380 100644 --- a/src/app/modules/main/chat_section/chat_content/chat_details.nim +++ b/src/app/modules/main/chat_section/chat_content/chat_details.nim @@ -23,6 +23,8 @@ QtObject: isContact: bool active: bool blocked: bool + canPost: bool + canView: bool canPostReactions: bool hideIfPermissionsNotMet: bool @@ -50,8 +52,10 @@ QtObject: isUntrustworthy: bool, isContact: bool = false, blocked: bool = false, + canPost: bool = true, + canView: bool = true, canPostReactions: bool = true, - hideIfPermissionsNotMet: bool + hideIfPermissionsNotMet: bool, ) = self.id = id self.`type` = `type` @@ -71,6 +75,8 @@ QtObject: self.isContact = isContact self.active = false self.blocked = blocked + self.canPost = canPost + self.canView = canView self.canPostReactions = canPostReactions self.hideIfPermissionsNotMet = hideIfPermissionsNotMet @@ -248,6 +254,28 @@ QtObject: self.blocked = value self.blockedChanged() + proc canPostChanged(self: ChatDetails) {.signal.} + proc getCanPost(self: ChatDetails): bool {.slot.} = + return self.canPost + QtProperty[bool] canPost: + read = getCanPost + notify = canPostChanged + + proc setCanPost*(self: ChatDetails, value: bool) = + self.canPost = value + self.canPostChanged() + + proc canViewChanged(self: ChatDetails) {.signal.} + proc getCanView(self: ChatDetails): bool {.slot.} = + return self.canView + QtProperty[bool] canView: + read = getCanView + notify = canViewChanged + + proc setCanView*(self: ChatDetails, value: bool) = + self.canView = value + self.canViewChanged() + proc canPostReactionsChanged(self: ChatDetails) {.signal.} proc getCanPostReactions(self: ChatDetails): bool {.slot.} = return self.canPostReactions diff --git a/src/app/modules/main/chat_section/chat_content/controller.nim b/src/app/modules/main/chat_section/chat_content/controller.nim index 2f91617fc2..f8d08aae9e 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -170,7 +170,7 @@ proc init*(self: Controller) = let args = CommunityChatArgs(e) if(args.chat.communityId != self.sectionId or args.chat.id != self.chatId): return - self.delegate.onChatEdited(args.chat) + self.delegate.onCommunityChannelEdited(args.chat) self.events.on(SIGNAL_CHAT_RENAMED) do(e: Args): var args = ChatRenameArgs(e) @@ -184,12 +184,6 @@ proc init*(self: Controller) = return self.delegate.onGroupChatDetailsUpdated(args.newName, args.newColor, args.newImage) - self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args): - var args = ChatUpdateArgs(e) - for chat in args.chats: - if self.chatId == chat.id: - self.delegate.onChatEdited(chat) - proc getMyChatId*(self: Controller): string = return self.chatId diff --git a/src/app/modules/main/chat_section/chat_content/io_interface.nim b/src/app/modules/main/chat_section/chat_content/io_interface.nim index a8e0d5986e..abd99f4c90 100644 --- a/src/app/modules/main/chat_section/chat_content/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/io_interface.nim @@ -16,6 +16,9 @@ method load*(self: AccessInterface, chatItem: chat_item.Item) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") +method onChatUpdated*(self: AccessInterface, chatItem: chat_item.Item) {.base.} = + raise newException(ValueError, "No implementation available") + method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} = raise newException(ValueError, "No implementation available") @@ -50,7 +53,7 @@ method toggleReactionFromOthers*(self: AccessInterface, messageId: string, emoji method onContactDetailsUpdated*(self: AccessInterface, contactId: string) {.base.} = raise newException(ValueError, "No implementation available") -method onChatEdited*(self: AccessInterface, chatDto: ChatDto) {.base.} = +method onCommunityChannelEdited*(self: AccessInterface, chatDto: ChatDto) {.base.} = raise newException(ValueError, "No implementation available") method onChatRenamed*(self: AccessInterface, newName: string) {.base.} = diff --git a/src/app/modules/main/chat_section/chat_content/module.nim b/src/app/modules/main/chat_section/chat_content/module.nim index 512c05848e..8e2687f0ec 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -4,6 +4,7 @@ import ../io_interface as delegate_interface import view, controller import ../item as chat_item +import ./chat_details import ../../../shared_models/message_model as pinned_msg_model import ../../../shared_models/message_item as pinned_msg_item import ../../../shared_models/message_transaction_parameters_item @@ -90,11 +91,15 @@ method load*(self: Module, chatItem: chat_item.Item) = self.usersModule.load() - self.view.load(chatItem.id, chatItem.`type`, self.controller.belongsToCommunity(), + self.view.load() + self.view.chatDetails.setChatDetails(chatItem.id, chatItem.`type`, self.controller.belongsToCommunity(), self.controller.isUsersListAvailable(), chatName, chatImage, chatItem.color, chatItem.description, chatItem.emoji, chatItem.hasUnreadMessages, chatItem.notificationsCount, chatItem.highlight, chatItem.muted, chatItem.position, isUntrustworthy = trustStatus == TrustStatus.Untrustworthy, - isContact, chatItem.blocked, chatItem.canPostReactions, chatItem.hideIfPermissionsNotMet) + isContact, chatItem.blocked, chatItem.canPost, chatItem.canView, chatItem.canPostReactions, + chatItem.hideIfPermissionsNotMet) + + self.view.chatDetailsChanged() self.inputAreaModule.load() self.messagesModule.load() @@ -365,8 +370,33 @@ method onContactDetailsUpdated*(self: Module, contactId: string) = method onNotificationsUpdated*(self: Module, hasUnreadMessages: bool, notificationCount: int) = self.view.updateChatDetailsNotifications(hasUnreadMessages, notificationCount) -method onChatEdited*(self: Module, chatDto: ChatDto) = - self.view.updateChatDetails(chatDto) +method onChatUpdated*(self: Module, chatItem: chat_item.Item) = + if chatItem.`type` != ChatType.OneToOne.int: + self.view.chatDetails.setName(chatItem.name) + self.view.chatDetails.setIcon(chatItem.icon) + self.view.chatDetails.setDescription(chatItem.description) + self.view.chatDetails.setEmoji(chatItem.emoji) + self.view.chatDetails.setColor(chatItem.color) + self.view.chatDetails.setMuted(chatItem.muted) + self.view.chatDetails.setCanPost(chatItem.canPost) + self.view.chatDetails.setCanView(chatItem.canView) + self.view.chatDetails.setCanPostReactions(chatItem.canPostReactions) + self.view.chatDetails.setHideIfPermissionsNotMet(chat_item.hideIfPermissionsNotMet) + + self.messagesModule.updateChatFetchMoreMessages() + self.messagesModule.updateChatIdentifier() + +method onCommunityChannelEdited*(self: Module, chatDto: ChatDto) = + # This is CommunityChat ChatDto + self.view.chatDetails.setDescription(chatDto.description) + self.view.chatDetails.setEmoji(chatDto.emoji) + self.view.chatDetails.setColor(chatDto.color) + self.view.chatDetails.setMuted(chatDto.muted) + self.view.chatDetails.setCanPost(chatDto.canPost) + self.view.chatDetails.setCanView(chatDto.canView) + self.view.chatDetails.setCanPostReactions(chatDto.canPostReactions) + self.view.chatDetails.setHideIfPermissionsNotMet(chatDto.hideIfPermissionsNotMet) + self.messagesModule.updateChatFetchMoreMessages() self.messagesModule.updateChatIdentifier() diff --git a/src/app/modules/main/chat_section/chat_content/view.nim b/src/app/modules/main/chat_section/chat_content/view.nim index 6d61e94bd2..7ed7c1fed0 100644 --- a/src/app/modules/main/chat_section/chat_content/view.nim +++ b/src/app/modules/main/chat_section/chat_content/view.nim @@ -1,6 +1,6 @@ import NimQml import ../../../shared_models/message_model as pinned_msg_model -import ../../../../../app_service/service/chat/dto/chat as chat_dto +import ../item as chat_item import io_interface import chat_details @@ -37,15 +37,8 @@ QtObject: result.viewOnlyPermissionsSatisfied = false result.viewAndPostPermissionsSatisfied = false - proc load*(self: View, id: string, `type`: int, belongsToCommunity, isUsersListAvailable: bool, - name, icon: string, color, description, emoji: string, hasUnreadMessages: bool, - notificationsCount: int, highlight, muted: bool, position: int, isUntrustworthy: bool, - isContact: bool, blocked: bool, canPostReactions: bool, hideIfPermissionsNotMet: bool) = - self.chatDetails.setChatDetails(id, `type`, belongsToCommunity, isUsersListAvailable, name, - icon, color, description, emoji, hasUnreadMessages, notificationsCount, highlight, muted, position, - isUntrustworthy, isContact, blocked, canPostReactions, hideIfPermissionsNotMet) + proc load*(self: View) = self.delegate.viewDidLoad() - self.chatDetailsChanged() proc pinnedModel*(self: View): pinned_msg_model.Model = return self.pinnedMessagesModel @@ -103,6 +96,9 @@ QtObject: proc leaveChat*(self: View) {.slot.} = self.delegate.leaveChat() + proc chatDetails*(self: View): ChatDetails = + return self.chatDetails + proc setMuted*(self: View, muted: bool) = self.chatDetails.setMuted(muted) @@ -141,16 +137,6 @@ QtObject: proc amIChatAdmin*(self: View): bool {.slot.} = return self.delegate.amIChatAdmin() - proc updateChatDetails*(self: View, chatDto: ChatDto) = - if chatDto.chatType != ChatType.OneToOne: - self.chatDetails.setName(chatDto.name) - self.chatDetails.setIcon(chatDto.icon) - self.chatDetails.setDescription(chatDto.description) - self.chatDetails.setEmoji(chatDto.emoji) - self.chatDetails.setColor(chatDto.color) - self.chatDetails.setMuted(chatDto.muted) - self.chatDetails.setCanPostReactions(chatDto.canPostReactions) - proc updateChatDetailsName*(self: View, name: string) = self.chatDetails.setName(name) diff --git a/src/app/modules/main/chat_section/item.nim b/src/app/modules/main/chat_section/item.nim index f8affeb7a0..8777d22a0c 100644 --- a/src/app/modules/main/chat_section/item.nim +++ b/src/app/modules/main/chat_section/item.nim @@ -36,6 +36,8 @@ type locked: bool requiresPermissions: bool canPostReactions: bool + canPost: bool + canView: bool viewersCanPostReactions: bool hideIfPermissionsNotMet: bool viewOnlyPermissionsSatisfied: bool @@ -68,11 +70,13 @@ proc initItem*( loaderActive = false, locked = false, requiresPermissions = false, + canPost = true, + canView = true, canPostReactions = true, viewersCanPostReactions = true, hideIfPermissionsNotMet: bool, viewOnlyPermissionsSatisfied: bool, - viewAndPostPermissionsSatisfied: bool + viewAndPostPermissionsSatisfied: bool, ): Item = result = Item() result.id = id @@ -102,6 +106,8 @@ proc initItem*( result.loaderActive = loaderActive result.locked = locked result.requiresPermissions = requiresPermissions + result.canPost = canPost + result.canView = canView result.canPostReactions = canPostReactions result.viewersCanPostReactions = viewersCanPostReactions result.hideIfPermissionsNotMet = hideIfPermissionsNotMet @@ -135,11 +141,13 @@ proc `$`*(self: Item): string = loaderActive: {$self.loaderActive}, locked: {$self.locked}, requiresPermissions: {$self.requiresPermissions}, + canPost: {$self.canPost}, + canView: {$self.canView}, canPostReactions: {$self.canPostReactions}, viewersCanPostReactions: {$self.viewersCanPostReactions}, hideIfPermissionsNotMet: {$self.hideIfPermissionsNotMet}, viewOnlyPermissionsSatisfied: {$self.viewOnlyPermissionsSatisfied}, - viewAndPostPermissionsSatisfied: {$self.viewAndPostPermissionsSatisfied} + viewAndPostPermissionsSatisfied: {$self.viewAndPostPermissionsSatisfied}, ]""" proc toJsonNode*(self: Item): JsonNode = @@ -169,6 +177,8 @@ proc toJsonNode*(self: Item): JsonNode = "loaderActive": self.loaderActive, "locked": self.locked, "requiresPermissions": self.requiresPermissions, + "canPost": self.canPost, + "canView": self.canView, "canPostReactions": self.canPostReactions, "viewersCanPostReactions": self.viewersCanPostReactions, "hideIfPermissionsNotMet": self.hideIfPermissionsNotMet, @@ -344,6 +354,18 @@ proc requiresPermissions*(self: Item): bool = proc `requiresPermissions=`*(self: Item, value: bool) = self.requiresPermissions = value +proc canPost*(self: Item): bool = + self.canPost + +proc `canPost=`*(self: Item, value: bool) = + self.canPost = value + +proc canView*(self: Item): bool = + self.canView + +proc `canView=`*(self: Item, value: bool) = + self.canView = value + proc canPostReactions*(self: Item): bool = self.canPostReactions diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index b107a3aa02..1960bd19e3 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -74,9 +74,8 @@ proc reevaluateRequiresTokenPermissionToJoin(self: Module) proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) -proc addOrUpdateChat(self: Module, +method addOrUpdateChat(self: Module, chat: ChatDto, - community: CommunityDto, belongsToCommunity: bool, events: UniqueUUIDEventEmitter, settingsService: settings_service.Service, @@ -277,7 +276,7 @@ proc addCategoryItem(self: Module, category: Category, memberRole: MemberRole, c category.position, hideIfPermissionsNotMet = false, viewOnlyPermissionsSatisfied = true, - viewAndPostPermissionsSatisfied = true + viewAndPostPermissionsSatisfied = true, ) if insertIntoModel: @@ -324,7 +323,6 @@ proc buildChatSectionUI( items.add(self.addOrUpdateChat( chatDto, - community, belongsToCommunity = chatDto.communityId.len > 0, events, settingsService, @@ -639,23 +637,13 @@ method onActiveSectionChange*(self: Module, sectionId: string) = method chatsModel*(self: Module): chats_model.Model = return self.view.chatsModel() -proc addNewChat( +proc getChatItemFromChatDto( self: Module, chatDto: ChatDto, community: CommunityDto, - belongsToCommunity: bool, - events: EventEmitter, - settingsService: settings_service.Service, - nodeConfigurationService: node_configuration_service.Service, - contactService: contact_service.Service, - chatService: chat_service.Service, - communityService: community_service.Service, - messageService: message_service.Service, - mailserversService: mailservers_service.Service, - sharedUrlsService: shared_urls_service.Service, setChatAsActive: bool = true, - insertIntoModel: bool = true, - ): chat_item.Item = + ): chat_item.Item = + let hasNotification = chatDto.unviewedMessagesCount > 0 let notificationsCount = chatDto.unviewedMentionsCount @@ -667,13 +655,11 @@ proc addNewChat( var onlineStatus = OnlineStatus.Inactive var categoryPosition = -1 - var isUsersListAvailable = true if chatDto.chatType == ChatType.OneToOne: let contactDetails = self.controller.getContactDetails(chatDto.id) chatName = contactDetails.defaultDisplayName chatImage = contactDetails.icon blocked = contactDetails.dto.isBlocked() - isUsersListAvailable = false if not contactDetails.dto.ensVerified: colorHash = self.controller.getColorHash(chatDto.id) colorId = self.controller.getColorId(chatDto.id) @@ -706,12 +692,17 @@ proc addNewChat( # preferable. Please fix-me in https://github.com/status-im/status-desktop/issues/14431 self.view.chatsModel().changeCategoryOpened(category.id, categoryOpened) + + var canPost = true + var canView = true var canPostReactions = true var hideIfPermissionsNotMet = false 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 @@ -748,13 +739,35 @@ proc addNewChat( self.controller.checkChatHasPermissions(self.controller.getMySectionId(), chatDto.id) else: false, + canPost = canPost, + canView = canView, canPostReactions = canPostReactions, viewersCanPostReactions = viewersCanPostReactions, hideIfPermissionsNotMet = hideIfPermissionsNotMet, viewOnlyPermissionsSatisfied = true, # will be updated in async call - viewAndPostPermissionsSatisfied = true # will be updated in async call + viewAndPostPermissionsSatisfied = true, # will be updated in async call ) +proc addNewChat( + self: Module, + chatItem: chat_item.Item, + chatDto: ChatDto, + belongsToCommunity: bool, + events: EventEmitter, + settingsService: settings_service.Service, + nodeConfigurationService: node_configuration_service.Service, + contactService: contact_service.Service, + chatService: chat_service.Service, + communityService: community_service.Service, + messageService: message_service.Service, + mailserversService: mailservers_service.Service, + sharedUrlsService: shared_urls_service.Service, + setChatAsActive: bool = true, + insertIntoModel: bool = true, + ) = + + let isUsersListAvailable = chatDto.chatType != ChatType.OneToOne + self.addSubmodule( chatDto.id, belongsToCommunity, @@ -770,11 +783,11 @@ proc addNewChat( sharedUrlsService, ) - self.chatContentModules[chatDto.id].load(result) + self.chatContentModules[chatDto.id].load(chatItem) if insertIntoModel: - self.view.chatsModel().appendItem(result) + self.view.chatsModel().appendItem(chatItem) if setChatAsActive: - self.setActiveItem(result.id) + self.setActiveItem(chatItem.id) method switchToChannel*(self: Module, channelName: string) = if(not self.controller.isCommunity()): @@ -1358,7 +1371,7 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) = categoryId="", hideIfPermissionsNotMet=false, viewOnlyPermissionsSatisfied = true, - viewAndPostPermissionsSatisfied = true + viewAndPostPermissionsSatisfied = true, ) self.view.editCategoryChannelsModel().appendItem(chatItem) let catChats = self.controller.getChats(communityId, categoryId) @@ -1383,7 +1396,7 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) = categoryId, hideIfPermissionsNotMet=false, viewOnlyPermissionsSatisfied = true, - viewAndPostPermissionsSatisfied = true + viewAndPostPermissionsSatisfied = true, ) self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true) @@ -1406,9 +1419,8 @@ method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, t method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) = self.view.setLoadingHistoryMessagesInProgress(isLoading) -proc addOrUpdateChat(self: Module, +method addOrUpdateChat(self: Module, chat: ChatDto, - community: CommunityDto, belongsToCommunity: bool, events: UniqueUUIDEventEmitter, settingsService: settings_service.Service, @@ -1422,7 +1434,6 @@ proc addOrUpdateChat(self: Module, setChatAsActive: bool = true, insertIntoModel: bool = true, ): chat_item.Item = - let sectionId = self.controller.getMySectionId() if belongsToCommunity and sectionId != chat.communityId or not belongsToCommunity and sectionId != singletonInstance.userProfile.getPubKey(): @@ -1437,7 +1448,15 @@ proc addOrUpdateChat(self: Module, if chat.id == activeChatId: self.updateActiveChatMembership() + var community = CommunityDto() + if belongsToCommunity: + community = self.controller.getMyCommunity() + result = self.getChatItemFromChatDto(chat, community, setChatAsActive) + if self.doesCatOrChatExist(chat.id): + if (self.chatContentModules.contains(chat.id)): + self.chatContentModules[chat.id].onChatUpdated(result) + self.changeMutedOnChat(chat.id, chat.muted) self.changeCanPostValues(chat.id, chat.canPostReactions, chat.viewersCanPostReactions) self.updateChatRequiresPermissions(chat.id) @@ -1448,9 +1467,9 @@ proc addOrUpdateChat(self: Module, self.onChatRenamed(chat.id, chat.name) return - result = self.addNewChat( + self.addNewChat( + result, chat, - community, belongsToCommunity, events.eventsEmitter(), settingsService, @@ -1465,38 +1484,6 @@ proc addOrUpdateChat(self: Module, insertIntoModel, ) -method addOrUpdateChat*(self: Module, - chat: ChatDto, - belongsToCommunity: bool, - events: UniqueUUIDEventEmitter, - settingsService: settings_service.Service, - nodeConfigurationService: node_configuration_service.Service, - contactService: contact_service.Service, - chatService: chat_service.Service, - communityService: community_service.Service, - messageService: message_service.Service, - mailserversService: mailservers_service.Service, - sharedUrlsService: shared_urls_service.Service, - setChatAsActive: bool = true, - insertIntoModel: bool = true, - ): chat_item.Item = - result = self.addOrUpdateChat( - chat, - CommunityDto(), - belongsToCommunity, - events, - settingsService, - nodeConfigurationService, - contactService, - chatService, - communityService, - messageService, - mailserversService, - sharedUrlsService, - setChatAsActive, - insertIntoModel, - ) - method downloadMessages*(self: Module, chatId: string, filePath: string) = if(not self.chatContentModules.contains(chatId)): error "unexisting chat key: ", chatId, methodName="downloadMessages" diff --git a/src/app_service/service/chat/dto/chat.nim b/src/app_service/service/chat/dto/chat.nim index 112f0a52e2..622da11e77 100644 --- a/src/app_service/service/chat/dto/chat.nim +++ b/src/app_service/service/chat/dto/chat.nim @@ -85,6 +85,8 @@ type ChatDto* = object syncedTo*: int64 syncedFrom*: int64 firstMessageTimestamp: int64 # valid only for community chats, 0 - undefined, 1 - no messages, >1 valid timestamps + canPost*: bool + canView*: bool canPostReactions*: bool viewersCanPostReactions*: bool position*: int @@ -209,7 +211,7 @@ proc toGroupChatMember*(jsonObj: JsonNode): ChatMember = proc toChannelMember*(jsonObj: JsonNode, memberId: string, joined: bool): ChatMember = # Parse status-go "CommunityMember" type - # Mapping this DTO is not strightforward since only keys are used for id. We + # Mapping this DTO is not straightforward since only keys are used for id. We # handle it a bit different. result = ChatMember() result.id = memberId @@ -231,8 +233,6 @@ proc toChannelMember*(jsonObj: JsonNode, memberId: string, joined: bool): ChatMe elif roles.contains(MemberRole.TokenMaster.int): result.role = MemberRole.TokenMaster - result.joined = joined - proc toChatDto*(jsonObj: JsonNode): ChatDto = result = ChatDto() discard jsonObj.getProp("id", result.id) @@ -248,6 +248,8 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto = discard jsonObj.getProp("unviewedMessagesCount", result.unviewedMessagesCount) discard jsonObj.getProp("unviewedMentionsCount", result.unviewedMentionsCount) discard jsonObj.getProp("canPostReactions", result.canPostReactions) + discard jsonObj.getProp("canPost", result.canPost) + discard jsonObj.getProp("canView", result.canView) discard jsonObj.getProp("viewersCanPostReactions", result.viewersCanPostReactions) discard jsonObj.getProp("alias", result.alias) discard jsonObj.getProp("muted", result.muted) diff --git a/src/app_service/service/chat/service.nim b/src/app_service/service/chat/service.nim index 0e5ceae9b6..a3f69d4296 100644 --- a/src/app_service/service/chat/service.nim +++ b/src/app_service/service/chat/service.nim @@ -145,6 +145,7 @@ QtObject: # Forward declarations proc updateOrAddChat*(self: Service, chat: ChatDto) proc processMessengerResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) + proc getChatById*(self: Service, chatId: string, showWarning: bool = true): ChatDto proc doConnect(self: Service) = self.events.on(SignalType.Message.event) do(e: Args): @@ -287,8 +288,11 @@ QtObject: error "no chats or messages in the parsed response" return for chat in chats: - if (chat.active): - self.events.emit(SIGNAL_CHAT_CREATED, CreatedChatArgs(chat: chat)) + if chat.active: + var existingChat = self.getChatById(chat.id) + if existingChat.id == "" or not existingChat.active: + # Chat is now created + self.events.emit(SIGNAL_CHAT_CREATED, CreatedChatArgs(chat: chat)) var chatMap: Table[string, ChatDto] = initTable[string, ChatDto]() for chat in chats: chatMap[chat.id] = chat diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 9c10e4d797..b3b8c82975 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -642,8 +642,13 @@ QtObject: ) ) - if chat.name != prevChat.name or chat.description != prevChat.description or chat.color != prevChat.color or - chat.emoji != prevChat.emoji or chat.viewersCanPostReactions != prevChat.viewersCanPostReactions or + if chat.name != prevChat.name or + chat.description != prevChat.description or + chat.color != prevChat.color or + chat.emoji != prevChat.emoji or + chat.viewersCanPostReactions != prevChat.viewersCanPostReactions or + chat.canPost != prevChat.canPost or + chat.canView != prevChat.canView or chat.hideIfPermissionsNotMet != prevChat.hideIfPermissionsNotMet: var updatedChat = chat self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service. diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 5d30635d92..b2af940a77 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -271,6 +271,9 @@ Loader { root.chatContentModule.chatDetails.canPostReactions && !root.isViewMemberMessagesePopup + readonly property bool canPost: root.chatContentModule.chatDetails.canPost + readonly property bool canView: canPost || root.chatContentModule.chatDetails.canView + function nextMessageHasHeader() { if(!root.nextMessageAsJsonObj) { return false @@ -587,11 +590,13 @@ Loader { readonly property int contentType: d.convertContentType(root.messageContentType) property string originalMessageText: "" - readonly property bool hideQuickActions: root.isChatBlocked || + readonly property bool hideQuickActions: { + return root.isChatBlocked || root.placeholderMessage || root.isInPinnedPopup || root.editModeOn || !root.rootStore.mainModuleInst.activeSection.joined + } function editCancelledHandler() { root.messageStore.setEditModeOff(root.messageId) @@ -939,7 +944,7 @@ Loader { }, Loader { active: !root.isInPinnedPopup && delegate.hovered && !delegate.hideQuickActions - && !root.isViewMemberMessagesePopup && root.rootStore.permissionsStore.viewAndPostCriteriaMet + && !root.isViewMemberMessagesePopup && d.canPost visible: active sourceComponent: StatusFlatRoundButton { objectName: "replyToMessageButton" @@ -954,8 +959,11 @@ Loader { } }, Loader { - active: !root.isInPinnedPopup && !root.editRestricted && !root.editModeOn && root.amISender && delegate.hovered && !delegate.hideQuickActions - && !root.isViewMemberMessagesePopup && root.rootStore.permissionsStore.viewAndPostCriteriaMet + active: { + + return !root.isInPinnedPopup && !root.editRestricted && !root.editModeOn && root.amISender && delegate.hovered && !delegate.hideQuickActions + && !root.isViewMemberMessagesePopup && d.canPost + } visible: active sourceComponent: StatusFlatRoundButton { objectName: "editMessageButton" @@ -980,7 +988,7 @@ Loader { if(delegate.hideQuickActions) return false; - if (!root.rootStore.permissionsStore.viewAndPostCriteriaMet) + if (!d.canPost) return false; if (root.isViewMemberMessagesePopup) { @@ -1049,7 +1057,7 @@ Loader { return false; if (delegate.hideQuickActions) return false; - if (!root.rootStore.permissionsStore.viewAndPostCriteriaMet) + if (!d.canPost) return false; return (root.amISender || root.amIChatAdmin) && (messageContentType === Constants.messageContentType.messageType ||