Fix missing reaction and edit buttons on permissioned channels (#14933)

* fix poster actions (edit, delete)

* use canPost instead

* fix chat getting updated without community
This commit is contained in:
Jonathan Rainville 2024-05-29 14:25:29 -04:00
parent 42b10783ef
commit 2830f01932
11 changed files with 178 additions and 109 deletions

View File

@ -23,6 +23,8 @@ QtObject:
isContact: bool isContact: bool
active: bool active: bool
blocked: bool blocked: bool
canPost: bool
canView: bool
canPostReactions: bool canPostReactions: bool
hideIfPermissionsNotMet: bool hideIfPermissionsNotMet: bool
@ -50,8 +52,10 @@ QtObject:
isUntrustworthy: bool, isUntrustworthy: bool,
isContact: bool = false, isContact: bool = false,
blocked: bool = false, blocked: bool = false,
canPost: bool = true,
canView: bool = true,
canPostReactions: bool = true, canPostReactions: bool = true,
hideIfPermissionsNotMet: bool hideIfPermissionsNotMet: bool,
) = ) =
self.id = id self.id = id
self.`type` = `type` self.`type` = `type`
@ -71,6 +75,8 @@ QtObject:
self.isContact = isContact self.isContact = isContact
self.active = false self.active = false
self.blocked = blocked self.blocked = blocked
self.canPost = canPost
self.canView = canView
self.canPostReactions = canPostReactions self.canPostReactions = canPostReactions
self.hideIfPermissionsNotMet = hideIfPermissionsNotMet self.hideIfPermissionsNotMet = hideIfPermissionsNotMet
@ -248,6 +254,28 @@ QtObject:
self.blocked = value self.blocked = value
self.blockedChanged() 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 canPostReactionsChanged(self: ChatDetails) {.signal.}
proc getCanPostReactions(self: ChatDetails): bool {.slot.} = proc getCanPostReactions(self: ChatDetails): bool {.slot.} =
return self.canPostReactions return self.canPostReactions

View File

@ -170,7 +170,7 @@ proc init*(self: Controller) =
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
if(args.chat.communityId != self.sectionId or args.chat.id != self.chatId): if(args.chat.communityId != self.sectionId or args.chat.id != self.chatId):
return return
self.delegate.onChatEdited(args.chat) self.delegate.onCommunityChannelEdited(args.chat)
self.events.on(SIGNAL_CHAT_RENAMED) do(e: Args): self.events.on(SIGNAL_CHAT_RENAMED) do(e: Args):
var args = ChatRenameArgs(e) var args = ChatRenameArgs(e)
@ -184,12 +184,6 @@ proc init*(self: Controller) =
return return
self.delegate.onGroupChatDetailsUpdated(args.newName, args.newColor, args.newImage) 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 = proc getMyChatId*(self: Controller): string =
return self.chatId return self.chatId

View File

@ -16,6 +16,9 @@ method load*(self: AccessInterface, chatItem: chat_item.Item) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") 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.} = method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -50,7 +53,7 @@ method toggleReactionFromOthers*(self: AccessInterface, messageId: string, emoji
method onContactDetailsUpdated*(self: AccessInterface, contactId: string) {.base.} = method onContactDetailsUpdated*(self: AccessInterface, contactId: string) {.base.} =
raise newException(ValueError, "No implementation available") 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") raise newException(ValueError, "No implementation available")
method onChatRenamed*(self: AccessInterface, newName: string) {.base.} = method onChatRenamed*(self: AccessInterface, newName: string) {.base.} =

View File

@ -4,6 +4,7 @@ import ../io_interface as delegate_interface
import view, controller import view, controller
import ../item as chat_item import ../item as chat_item
import ./chat_details
import ../../../shared_models/message_model as pinned_msg_model import ../../../shared_models/message_model as pinned_msg_model
import ../../../shared_models/message_item as pinned_msg_item import ../../../shared_models/message_item as pinned_msg_item
import ../../../shared_models/message_transaction_parameters_item import ../../../shared_models/message_transaction_parameters_item
@ -90,11 +91,15 @@ method load*(self: Module, chatItem: chat_item.Item) =
self.usersModule.load() 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, self.controller.isUsersListAvailable(), chatName, chatImage,
chatItem.color, chatItem.description, chatItem.emoji, chatItem.hasUnreadMessages, chatItem.notificationsCount, chatItem.color, chatItem.description, chatItem.emoji, chatItem.hasUnreadMessages, chatItem.notificationsCount,
chatItem.highlight, chatItem.muted, chatItem.position, isUntrustworthy = trustStatus == TrustStatus.Untrustworthy, 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.inputAreaModule.load()
self.messagesModule.load() self.messagesModule.load()
@ -365,8 +370,33 @@ method onContactDetailsUpdated*(self: Module, contactId: string) =
method onNotificationsUpdated*(self: Module, hasUnreadMessages: bool, notificationCount: int) = method onNotificationsUpdated*(self: Module, hasUnreadMessages: bool, notificationCount: int) =
self.view.updateChatDetailsNotifications(hasUnreadMessages, notificationCount) self.view.updateChatDetailsNotifications(hasUnreadMessages, notificationCount)
method onChatEdited*(self: Module, chatDto: ChatDto) = method onChatUpdated*(self: Module, chatItem: chat_item.Item) =
self.view.updateChatDetails(chatDto) 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.updateChatFetchMoreMessages()
self.messagesModule.updateChatIdentifier() self.messagesModule.updateChatIdentifier()

View File

@ -1,6 +1,6 @@
import NimQml import NimQml
import ../../../shared_models/message_model as pinned_msg_model 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 io_interface
import chat_details import chat_details
@ -37,15 +37,8 @@ QtObject:
result.viewOnlyPermissionsSatisfied = false result.viewOnlyPermissionsSatisfied = false
result.viewAndPostPermissionsSatisfied = false result.viewAndPostPermissionsSatisfied = false
proc load*(self: View, id: string, `type`: int, belongsToCommunity, isUsersListAvailable: bool, proc load*(self: View) =
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)
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
self.chatDetailsChanged()
proc pinnedModel*(self: View): pinned_msg_model.Model = proc pinnedModel*(self: View): pinned_msg_model.Model =
return self.pinnedMessagesModel return self.pinnedMessagesModel
@ -103,6 +96,9 @@ QtObject:
proc leaveChat*(self: View) {.slot.} = proc leaveChat*(self: View) {.slot.} =
self.delegate.leaveChat() self.delegate.leaveChat()
proc chatDetails*(self: View): ChatDetails =
return self.chatDetails
proc setMuted*(self: View, muted: bool) = proc setMuted*(self: View, muted: bool) =
self.chatDetails.setMuted(muted) self.chatDetails.setMuted(muted)
@ -141,16 +137,6 @@ QtObject:
proc amIChatAdmin*(self: View): bool {.slot.} = proc amIChatAdmin*(self: View): bool {.slot.} =
return self.delegate.amIChatAdmin() 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) = proc updateChatDetailsName*(self: View, name: string) =
self.chatDetails.setName(name) self.chatDetails.setName(name)

View File

@ -36,6 +36,8 @@ type
locked: bool locked: bool
requiresPermissions: bool requiresPermissions: bool
canPostReactions: bool canPostReactions: bool
canPost: bool
canView: bool
viewersCanPostReactions: bool viewersCanPostReactions: bool
hideIfPermissionsNotMet: bool hideIfPermissionsNotMet: bool
viewOnlyPermissionsSatisfied: bool viewOnlyPermissionsSatisfied: bool
@ -68,11 +70,13 @@ proc initItem*(
loaderActive = false, loaderActive = false,
locked = false, locked = false,
requiresPermissions = false, requiresPermissions = false,
canPost = true,
canView = true,
canPostReactions = true, canPostReactions = true,
viewersCanPostReactions = true, viewersCanPostReactions = true,
hideIfPermissionsNotMet: bool, hideIfPermissionsNotMet: bool,
viewOnlyPermissionsSatisfied: bool, viewOnlyPermissionsSatisfied: bool,
viewAndPostPermissionsSatisfied: bool viewAndPostPermissionsSatisfied: bool,
): Item = ): Item =
result = Item() result = Item()
result.id = id result.id = id
@ -102,6 +106,8 @@ proc initItem*(
result.loaderActive = loaderActive result.loaderActive = loaderActive
result.locked = locked result.locked = locked
result.requiresPermissions = requiresPermissions result.requiresPermissions = requiresPermissions
result.canPost = canPost
result.canView = canView
result.canPostReactions = canPostReactions result.canPostReactions = canPostReactions
result.viewersCanPostReactions = viewersCanPostReactions result.viewersCanPostReactions = viewersCanPostReactions
result.hideIfPermissionsNotMet = hideIfPermissionsNotMet result.hideIfPermissionsNotMet = hideIfPermissionsNotMet
@ -135,11 +141,13 @@ proc `$`*(self: Item): string =
loaderActive: {$self.loaderActive}, loaderActive: {$self.loaderActive},
locked: {$self.locked}, locked: {$self.locked},
requiresPermissions: {$self.requiresPermissions}, requiresPermissions: {$self.requiresPermissions},
canPost: {$self.canPost},
canView: {$self.canView},
canPostReactions: {$self.canPostReactions}, canPostReactions: {$self.canPostReactions},
viewersCanPostReactions: {$self.viewersCanPostReactions}, viewersCanPostReactions: {$self.viewersCanPostReactions},
hideIfPermissionsNotMet: {$self.hideIfPermissionsNotMet}, hideIfPermissionsNotMet: {$self.hideIfPermissionsNotMet},
viewOnlyPermissionsSatisfied: {$self.viewOnlyPermissionsSatisfied}, viewOnlyPermissionsSatisfied: {$self.viewOnlyPermissionsSatisfied},
viewAndPostPermissionsSatisfied: {$self.viewAndPostPermissionsSatisfied} viewAndPostPermissionsSatisfied: {$self.viewAndPostPermissionsSatisfied},
]""" ]"""
proc toJsonNode*(self: Item): JsonNode = proc toJsonNode*(self: Item): JsonNode =
@ -169,6 +177,8 @@ proc toJsonNode*(self: Item): JsonNode =
"loaderActive": self.loaderActive, "loaderActive": self.loaderActive,
"locked": self.locked, "locked": self.locked,
"requiresPermissions": self.requiresPermissions, "requiresPermissions": self.requiresPermissions,
"canPost": self.canPost,
"canView": self.canView,
"canPostReactions": self.canPostReactions, "canPostReactions": self.canPostReactions,
"viewersCanPostReactions": self.viewersCanPostReactions, "viewersCanPostReactions": self.viewersCanPostReactions,
"hideIfPermissionsNotMet": self.hideIfPermissionsNotMet, "hideIfPermissionsNotMet": self.hideIfPermissionsNotMet,
@ -344,6 +354,18 @@ proc requiresPermissions*(self: Item): bool =
proc `requiresPermissions=`*(self: Item, value: bool) = proc `requiresPermissions=`*(self: Item, value: bool) =
self.requiresPermissions = value 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 = proc canPostReactions*(self: Item): bool =
self.canPostReactions self.canPostReactions

View File

@ -74,9 +74,8 @@ proc reevaluateRequiresTokenPermissionToJoin(self: Module)
proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool)
proc addOrUpdateChat(self: Module, method addOrUpdateChat(self: Module,
chat: ChatDto, chat: ChatDto,
community: CommunityDto,
belongsToCommunity: bool, belongsToCommunity: bool,
events: UniqueUUIDEventEmitter, events: UniqueUUIDEventEmitter,
settingsService: settings_service.Service, settingsService: settings_service.Service,
@ -277,7 +276,7 @@ proc addCategoryItem(self: Module, category: Category, memberRole: MemberRole, c
category.position, category.position,
hideIfPermissionsNotMet = false, hideIfPermissionsNotMet = false,
viewOnlyPermissionsSatisfied = true, viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true viewAndPostPermissionsSatisfied = true,
) )
if insertIntoModel: if insertIntoModel:
@ -324,7 +323,6 @@ proc buildChatSectionUI(
items.add(self.addOrUpdateChat( items.add(self.addOrUpdateChat(
chatDto, chatDto,
community,
belongsToCommunity = chatDto.communityId.len > 0, belongsToCommunity = chatDto.communityId.len > 0,
events, events,
settingsService, settingsService,
@ -639,23 +637,13 @@ method onActiveSectionChange*(self: Module, sectionId: string) =
method chatsModel*(self: Module): chats_model.Model = method chatsModel*(self: Module): chats_model.Model =
return self.view.chatsModel() return self.view.chatsModel()
proc addNewChat( proc getChatItemFromChatDto(
self: Module, self: Module,
chatDto: ChatDto, chatDto: ChatDto,
community: CommunityDto, 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, setChatAsActive: bool = true,
insertIntoModel: bool = true,
): chat_item.Item = ): chat_item.Item =
let hasNotification = chatDto.unviewedMessagesCount > 0 let hasNotification = chatDto.unviewedMessagesCount > 0
let notificationsCount = chatDto.unviewedMentionsCount let notificationsCount = chatDto.unviewedMentionsCount
@ -667,13 +655,11 @@ proc addNewChat(
var onlineStatus = OnlineStatus.Inactive var onlineStatus = OnlineStatus.Inactive
var categoryPosition = -1 var categoryPosition = -1
var isUsersListAvailable = true
if chatDto.chatType == ChatType.OneToOne: if chatDto.chatType == ChatType.OneToOne:
let contactDetails = self.controller.getContactDetails(chatDto.id) let contactDetails = self.controller.getContactDetails(chatDto.id)
chatName = contactDetails.defaultDisplayName chatName = contactDetails.defaultDisplayName
chatImage = contactDetails.icon chatImage = contactDetails.icon
blocked = contactDetails.dto.isBlocked() blocked = contactDetails.dto.isBlocked()
isUsersListAvailable = false
if not contactDetails.dto.ensVerified: if not contactDetails.dto.ensVerified:
colorHash = self.controller.getColorHash(chatDto.id) colorHash = self.controller.getColorHash(chatDto.id)
colorId = self.controller.getColorId(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 # preferable. Please fix-me in https://github.com/status-im/status-desktop/issues/14431
self.view.chatsModel().changeCategoryOpened(category.id, categoryOpened) self.view.chatsModel().changeCategoryOpened(category.id, categoryOpened)
var canPost = true
var canView = true
var canPostReactions = true var canPostReactions = true
var hideIfPermissionsNotMet = false var hideIfPermissionsNotMet = false
var viewersCanPostReactions = true var viewersCanPostReactions = true
if self.controller.isCommunity: if self.controller.isCommunity:
let communityChat = community.getCommunityChat(chatDto.id) let communityChat = community.getCommunityChat(chatDto.id)
# Some properties are only available on CommunityChat (they are useless for normal chats) # Some properties are only available on CommunityChat (they are useless for normal chats)
canPost = communityChat.canPost
canView = communityChat.canView
canPostReactions = communityChat.canPostReactions canPostReactions = communityChat.canPostReactions
hideIfPermissionsNotMet = communityChat.hideIfPermissionsNotMet hideIfPermissionsNotMet = communityChat.hideIfPermissionsNotMet
viewersCanPostReactions = communityChat.viewersCanPostReactions viewersCanPostReactions = communityChat.viewersCanPostReactions
@ -748,13 +739,35 @@ proc addNewChat(
self.controller.checkChatHasPermissions(self.controller.getMySectionId(), chatDto.id) self.controller.checkChatHasPermissions(self.controller.getMySectionId(), chatDto.id)
else: else:
false, false,
canPost = canPost,
canView = canView,
canPostReactions = canPostReactions, canPostReactions = canPostReactions,
viewersCanPostReactions = viewersCanPostReactions, viewersCanPostReactions = viewersCanPostReactions,
hideIfPermissionsNotMet = hideIfPermissionsNotMet, hideIfPermissionsNotMet = hideIfPermissionsNotMet,
viewOnlyPermissionsSatisfied = true, # will be updated in async call 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( self.addSubmodule(
chatDto.id, chatDto.id,
belongsToCommunity, belongsToCommunity,
@ -770,11 +783,11 @@ proc addNewChat(
sharedUrlsService, sharedUrlsService,
) )
self.chatContentModules[chatDto.id].load(result) self.chatContentModules[chatDto.id].load(chatItem)
if insertIntoModel: if insertIntoModel:
self.view.chatsModel().appendItem(result) self.view.chatsModel().appendItem(chatItem)
if setChatAsActive: if setChatAsActive:
self.setActiveItem(result.id) self.setActiveItem(chatItem.id)
method switchToChannel*(self: Module, channelName: string) = method switchToChannel*(self: Module, channelName: string) =
if(not self.controller.isCommunity()): if(not self.controller.isCommunity()):
@ -1358,7 +1371,7 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
categoryId="", categoryId="",
hideIfPermissionsNotMet=false, hideIfPermissionsNotMet=false,
viewOnlyPermissionsSatisfied = true, viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true viewAndPostPermissionsSatisfied = true,
) )
self.view.editCategoryChannelsModel().appendItem(chatItem) self.view.editCategoryChannelsModel().appendItem(chatItem)
let catChats = self.controller.getChats(communityId, categoryId) let catChats = self.controller.getChats(communityId, categoryId)
@ -1383,7 +1396,7 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
categoryId, categoryId,
hideIfPermissionsNotMet=false, hideIfPermissionsNotMet=false,
viewOnlyPermissionsSatisfied = true, viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true viewAndPostPermissionsSatisfied = true,
) )
self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = 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) = method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
self.view.setLoadingHistoryMessagesInProgress(isLoading) self.view.setLoadingHistoryMessagesInProgress(isLoading)
proc addOrUpdateChat(self: Module, method addOrUpdateChat(self: Module,
chat: ChatDto, chat: ChatDto,
community: CommunityDto,
belongsToCommunity: bool, belongsToCommunity: bool,
events: UniqueUUIDEventEmitter, events: UniqueUUIDEventEmitter,
settingsService: settings_service.Service, settingsService: settings_service.Service,
@ -1422,7 +1434,6 @@ proc addOrUpdateChat(self: Module,
setChatAsActive: bool = true, setChatAsActive: bool = true,
insertIntoModel: bool = true, insertIntoModel: bool = true,
): chat_item.Item = ): chat_item.Item =
let sectionId = self.controller.getMySectionId() let sectionId = self.controller.getMySectionId()
if belongsToCommunity and sectionId != chat.communityId or if belongsToCommunity and sectionId != chat.communityId or
not belongsToCommunity and sectionId != singletonInstance.userProfile.getPubKey(): not belongsToCommunity and sectionId != singletonInstance.userProfile.getPubKey():
@ -1437,7 +1448,15 @@ proc addOrUpdateChat(self: Module,
if chat.id == activeChatId: if chat.id == activeChatId:
self.updateActiveChatMembership() self.updateActiveChatMembership()
var community = CommunityDto()
if belongsToCommunity:
community = self.controller.getMyCommunity()
result = self.getChatItemFromChatDto(chat, community, setChatAsActive)
if self.doesCatOrChatExist(chat.id): if self.doesCatOrChatExist(chat.id):
if (self.chatContentModules.contains(chat.id)):
self.chatContentModules[chat.id].onChatUpdated(result)
self.changeMutedOnChat(chat.id, chat.muted) self.changeMutedOnChat(chat.id, chat.muted)
self.changeCanPostValues(chat.id, chat.canPostReactions, chat.viewersCanPostReactions) self.changeCanPostValues(chat.id, chat.canPostReactions, chat.viewersCanPostReactions)
self.updateChatRequiresPermissions(chat.id) self.updateChatRequiresPermissions(chat.id)
@ -1448,9 +1467,9 @@ proc addOrUpdateChat(self: Module,
self.onChatRenamed(chat.id, chat.name) self.onChatRenamed(chat.id, chat.name)
return return
result = self.addNewChat( self.addNewChat(
result,
chat, chat,
community,
belongsToCommunity, belongsToCommunity,
events.eventsEmitter(), events.eventsEmitter(),
settingsService, settingsService,
@ -1465,38 +1484,6 @@ proc addOrUpdateChat(self: Module,
insertIntoModel, 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) = method downloadMessages*(self: Module, chatId: string, filePath: string) =
if(not self.chatContentModules.contains(chatId)): if(not self.chatContentModules.contains(chatId)):
error "unexisting chat key: ", chatId, methodName="downloadMessages" error "unexisting chat key: ", chatId, methodName="downloadMessages"

View File

@ -85,6 +85,8 @@ type ChatDto* = object
syncedTo*: int64 syncedTo*: int64
syncedFrom*: int64 syncedFrom*: int64
firstMessageTimestamp: int64 # valid only for community chats, 0 - undefined, 1 - no messages, >1 valid timestamps firstMessageTimestamp: int64 # valid only for community chats, 0 - undefined, 1 - no messages, >1 valid timestamps
canPost*: bool
canView*: bool
canPostReactions*: bool canPostReactions*: bool
viewersCanPostReactions*: bool viewersCanPostReactions*: bool
position*: int position*: int
@ -209,7 +211,7 @@ proc toGroupChatMember*(jsonObj: JsonNode): ChatMember =
proc toChannelMember*(jsonObj: JsonNode, memberId: string, joined: bool): ChatMember = proc toChannelMember*(jsonObj: JsonNode, memberId: string, joined: bool): ChatMember =
# Parse status-go "CommunityMember" type # 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. # handle it a bit different.
result = ChatMember() result = ChatMember()
result.id = memberId result.id = memberId
@ -231,8 +233,6 @@ proc toChannelMember*(jsonObj: JsonNode, memberId: string, joined: bool): ChatMe
elif roles.contains(MemberRole.TokenMaster.int): elif roles.contains(MemberRole.TokenMaster.int):
result.role = MemberRole.TokenMaster result.role = MemberRole.TokenMaster
result.joined = joined
proc toChatDto*(jsonObj: JsonNode): ChatDto = proc toChatDto*(jsonObj: JsonNode): ChatDto =
result = ChatDto() result = ChatDto()
discard jsonObj.getProp("id", result.id) discard jsonObj.getProp("id", result.id)
@ -248,6 +248,8 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto =
discard jsonObj.getProp("unviewedMessagesCount", result.unviewedMessagesCount) discard jsonObj.getProp("unviewedMessagesCount", result.unviewedMessagesCount)
discard jsonObj.getProp("unviewedMentionsCount", result.unviewedMentionsCount) discard jsonObj.getProp("unviewedMentionsCount", result.unviewedMentionsCount)
discard jsonObj.getProp("canPostReactions", result.canPostReactions) 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("viewersCanPostReactions", result.viewersCanPostReactions)
discard jsonObj.getProp("alias", result.alias) discard jsonObj.getProp("alias", result.alias)
discard jsonObj.getProp("muted", result.muted) discard jsonObj.getProp("muted", result.muted)

View File

@ -145,6 +145,7 @@ QtObject:
# Forward declarations # Forward declarations
proc updateOrAddChat*(self: Service, chat: ChatDto) proc updateOrAddChat*(self: Service, chat: ChatDto)
proc processMessengerResponse*(self: Service, response: RpcResponse[JsonNode]): (seq[ChatDto], seq[MessageDto]) 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) = proc doConnect(self: Service) =
self.events.on(SignalType.Message.event) do(e: Args): self.events.on(SignalType.Message.event) do(e: Args):
@ -286,7 +287,10 @@ QtObject:
error "no chats or messages in the parsed response" error "no chats or messages in the parsed response"
return return
for chat in chats: for chat in chats:
if (chat.active): 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)) self.events.emit(SIGNAL_CHAT_CREATED, CreatedChatArgs(chat: chat))
var chatMap: Table[string, ChatDto] = initTable[string, ChatDto]() var chatMap: Table[string, ChatDto] = initTable[string, ChatDto]()
for chat in chats: for chat in chats:

View File

@ -642,8 +642,13 @@ QtObject:
) )
) )
if chat.name != prevChat.name or chat.description != prevChat.description or chat.color != prevChat.color or if chat.name != prevChat.name or
chat.emoji != prevChat.emoji or chat.viewersCanPostReactions != prevChat.viewersCanPostReactions 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: chat.hideIfPermissionsNotMet != prevChat.hideIfPermissionsNotMet:
var updatedChat = chat var updatedChat = chat
self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service. self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service.

View File

@ -271,6 +271,9 @@ Loader {
root.chatContentModule.chatDetails.canPostReactions && root.chatContentModule.chatDetails.canPostReactions &&
!root.isViewMemberMessagesePopup !root.isViewMemberMessagesePopup
readonly property bool canPost: root.chatContentModule.chatDetails.canPost
readonly property bool canView: canPost || root.chatContentModule.chatDetails.canView
function nextMessageHasHeader() { function nextMessageHasHeader() {
if(!root.nextMessageAsJsonObj) { if(!root.nextMessageAsJsonObj) {
return false return false
@ -587,11 +590,13 @@ Loader {
readonly property int contentType: d.convertContentType(root.messageContentType) readonly property int contentType: d.convertContentType(root.messageContentType)
property string originalMessageText: "" property string originalMessageText: ""
readonly property bool hideQuickActions: root.isChatBlocked || readonly property bool hideQuickActions: {
return root.isChatBlocked ||
root.placeholderMessage || root.placeholderMessage ||
root.isInPinnedPopup || root.isInPinnedPopup ||
root.editModeOn || root.editModeOn ||
!root.rootStore.mainModuleInst.activeSection.joined !root.rootStore.mainModuleInst.activeSection.joined
}
function editCancelledHandler() { function editCancelledHandler() {
root.messageStore.setEditModeOff(root.messageId) root.messageStore.setEditModeOff(root.messageId)
@ -939,7 +944,7 @@ Loader {
}, },
Loader { Loader {
active: !root.isInPinnedPopup && delegate.hovered && !delegate.hideQuickActions active: !root.isInPinnedPopup && delegate.hovered && !delegate.hideQuickActions
&& !root.isViewMemberMessagesePopup && root.rootStore.permissionsStore.viewAndPostCriteriaMet && !root.isViewMemberMessagesePopup && d.canPost
visible: active visible: active
sourceComponent: StatusFlatRoundButton { sourceComponent: StatusFlatRoundButton {
objectName: "replyToMessageButton" objectName: "replyToMessageButton"
@ -954,8 +959,11 @@ Loader {
} }
}, },
Loader { Loader {
active: !root.isInPinnedPopup && !root.editRestricted && !root.editModeOn && root.amISender && delegate.hovered && !delegate.hideQuickActions active: {
&& !root.isViewMemberMessagesePopup && root.rootStore.permissionsStore.viewAndPostCriteriaMet
return !root.isInPinnedPopup && !root.editRestricted && !root.editModeOn && root.amISender && delegate.hovered && !delegate.hideQuickActions
&& !root.isViewMemberMessagesePopup && d.canPost
}
visible: active visible: active
sourceComponent: StatusFlatRoundButton { sourceComponent: StatusFlatRoundButton {
objectName: "editMessageButton" objectName: "editMessageButton"
@ -980,7 +988,7 @@ Loader {
if(delegate.hideQuickActions) if(delegate.hideQuickActions)
return false; return false;
if (!root.rootStore.permissionsStore.viewAndPostCriteriaMet) if (!d.canPost)
return false; return false;
if (root.isViewMemberMessagesePopup) { if (root.isViewMemberMessagesePopup) {
@ -1049,7 +1057,7 @@ Loader {
return false; return false;
if (delegate.hideQuickActions) if (delegate.hideQuickActions)
return false; return false;
if (!root.rootStore.permissionsStore.viewAndPostCriteriaMet) if (!d.canPost)
return false; return false;
return (root.amISender || root.amIChatAdmin) && return (root.amISender || root.amIChatAdmin) &&
(messageContentType === Constants.messageContentType.messageType || (messageContentType === Constants.messageContentType.messageType ||