fix(@desktop/communities): empty chat view during adding/removing active channel to the category

This commit is contained in:
mprakhov 2022-12-21 11:35:34 +02:00 committed by Mykhailo Prakhov
parent f3eb29bfea
commit 8b3319a1f3
5 changed files with 64 additions and 71 deletions

View File

@ -173,6 +173,11 @@ proc init*(self: Controller) =
let args = CommunityChatOrderArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onReorderChatOrCategory(args.chatId, args.position, args.categoryId)
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CATEGORY_CHANGED) do(e:Args):
let args = CommunityChatOrderArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCommunityCategoryChannelChanged(args.chatId, args.categoryId)
self.events.on(SIGNAL_RELOAD_MESSAGES) do(e: Args):
let args = ReloadMessagesArgs(e)
@ -272,13 +277,11 @@ proc getCommunityCategoryDetails*(self: Controller, communityId: string, categor
proc setActiveItemSubItem*(self: Controller, itemId: string, subItemId: string) =
self.activeItemId = itemId
self.activeSubItemId = subItemId
let chatId = self.getActiveChatId()
if chatId != "":
self.messageService.asyncLoadInitialMessagesForChat(chatId)
# We need to take other actions here like notify status go that unviewed mentions count is updated and so...
self.delegate.activeItemSubItemSet(self.activeItemId, self.activeSubItemId)
proc removeCommunityChat*(self: Controller, itemId: string) =

View File

@ -127,6 +127,9 @@ method onCommunityChannelEdited*(self: AccessInterface, chat: ChatDto) {.base.}
method onReorderChatOrCategory*(self: AccessInterface, chatOrCatId: string, position: int, newCategoryIdForChat: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCategoryChannelChanged*(self: AccessInterface, chatId: string, newCategoryIdForChat: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCategoryCreated*(self: AccessInterface, category: Category, chats: seq[ChatDto]) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -552,6 +552,13 @@ method setFirstChannelAsActive*(self: Module) =
let subItem = item.subItems.getItemAtIndex(0)
self.setActiveItemSubItem(item.id, subItem.id)
method onCommunityCategoryChannelChanged*(self: Module, channelId: string, newCategoryIdForChat: string) =
if channelId == self.controller.getActiveChatId():
if newCategoryIdForChat.len > 0:
self.setActiveItemSubItem(newCategoryIdForChat, channelId)
else:
self.setActiveItemSubItem(channelId, "")
method onReorderChatOrCategory*(self: Module, chatOrCatId: string, position: int, newCategoryIdForChat: string) =
self.view.chatsModel().reorder(chatOrCatId, position, newCategoryIdForChat)
@ -571,16 +578,18 @@ method onCommunityCategoryEdited*(self: Module, cat: Category, chats: seq[ChatDt
self.view.chatsModel().removeItemById(chatDto.id)
categoryItem.subItems().removeItemById(chatDto.id)
let isActive = chatDto.id == self.controller.getActiveChatId()
if chatDto.categoryId == cat.id:
let channelItem = initSubItem(chatDto.id, cat.id, chatDto.name, chatDto.icon,
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int,
amIChatAdmin=true, chatDto.timestamp.int, hasNotification, notificationsCount, chatDto.muted, blocked=false,
active=false, chatDto.position)
active=isActive, chatDto.position)
categoryItem.appendSubItem(channelItem)
else:
let channelItem = initItem(chatDto.id, chatDto.name, chatDto.icon,
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int, amIChatAdmin,
chatDto.timestamp.int, hasNotification, notificationsCount, chatDto.muted, blocked=false, active = false,
chatDto.timestamp.int, hasNotification, notificationsCount, chatDto.muted, blocked=false, active = isActive,
chatDto.position, categoryId="")
self.view.chatsModel().appendItem(channelItem)

View File

@ -113,6 +113,7 @@ const SIGNAL_COMMUNITY_CATEGORY_EDITED* = "communityCategoryEdited"
const SIGNAL_COMMUNITY_CATEGORY_NAME_EDITED* = "communityCategoryNameEdited"
const SIGNAL_COMMUNITY_CATEGORY_DELETED* = "communityCategoryDeleted"
const SIGNAL_COMMUNITY_CATEGORY_REORDERED* = "communityCategoryReordered"
const SIGNAL_COMMUNITY_CHANNEL_CATEGORY_CHANGED* = "communityChannelCategoryChanged"
const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved"
const SIGNAL_COMMUNITY_MEMBER_REMOVED* = "communityMemberRemoved"
const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity"
@ -380,19 +381,20 @@ QtObject:
else:
for category in community.categories:
# id is present
if findIndexById(category.id, prev_community.categories) == -1:
let index = findIndexById(category.id, prev_community.categories)
if index == -1:
continue
# but something is different
for prev_category in prev_community.categories:
if(category.id == prev_category.id and category.position != prev_category.position):
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED,
CommunityChatOrderArgs(
communityId: community.id,
categoryId: category.id,
position: category.position))
if(category.id == prev_category.id and category.name != prev_category.name):
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_NAME_EDITED,
CommunityCategoryArgs(communityId: community.id, category: category))
let prev_category = prev_community.categories[index]
if category.position != prev_category.position:
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED,
CommunityChatOrderArgs(
communityId: community.id,
categoryId: category.id,
position: category.position))
if category.name != prev_category.name:
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_NAME_EDITED,
CommunityCategoryArgs(communityId: community.id, category: category))
# channel was added
if(community.chats.len > prev_community.chats.len):
@ -416,24 +418,29 @@ QtObject:
else:
for chat in community.chats:
# id is present
if findIndexById(chat.id, prev_community.chats) == -1:
let index = findIndexById(chat.id, prev_community.chats)
if index == -1:
continue
# but something is different
for prev_chat in prev_community.chats:
# Handle position changes
if(chat.id == prev_chat.id and (chat.position != prev_chat.position or chat.categoryId != prev_chat.categoryId)):
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id,
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
let prev_chat = prev_community.chats[index]
# Handle position changes
if chat.position != prev_chat.position:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id,
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
# Handle name/description changes
if(chat.id == prev_chat.id and
(chat.name != prev_chat.name or chat.description != prev_chat.description or chat.color != prev_chat.color)):
var updatedChat = findChatById(chat.id, updatedChats)
updatedChat.updateMissingFields(chat)
self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service.
# Handle channel was added/removed to/from category
if chat.categoryId != prev_chat.categoryId:
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CATEGORY_CHANGED, CommunityChatOrderArgs(communityId: community.id,
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
let data = CommunityChatArgs(chat: updatedChat)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
# Handle name/description changes
if chat.name != prev_chat.name or chat.description != prev_chat.description or chat.color != prev_chat.color:
var updatedChat = findChatById(chat.id, updatedChats)
updatedChat.updateMissingFields(chat)
self.chatService.updateOrAddChat(updatedChat) # we have to update chats stored in the chat service.
let data = CommunityChatArgs(chat: updatedChat)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data)
self.allCommunities[community.id] = community
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))

View File

@ -166,16 +166,6 @@ Item {
model: parentModule && parentModule.model
delegate: delegateChooser
function isChatActive(myChatId) {
if(!myChatId || !root.isSectionActive)
return false
if(myChatId === root.activeChatId || myChatId === root.activeSubItemId)
return true
return false
}
DelegateChooser {
id: delegateChooser
role: "type"
@ -189,25 +179,15 @@ Item {
return subItems
}
delegate: Loader {
property bool isActiveChannel: chatRepeater.isChatActive(model.itemId)
id: categoryChatLoader
// Channels are not loaded by default and only load when first put active
active: false
active: model.active
visible: model.active
width: parent.width
height: isActiveChannel ? parent.height : 0
height: parent.height
Connections {
id: loaderConnections
target: categoryChatLoader
// First time this channel turns active, activate the Loader
onIsActiveChannelChanged: {
if (categoryChatLoader.isActiveChannel) {
categoryChatLoader.active = true
loaderConnections.enabled = false
}
}
}
// Removing the binding in order not to unload the content
onStatusChanged: if (status == Loader.Ready) active = true
sourceComponent: ChatContentView {
visible: !root.rootStore.openCreateChat && isActiveChannel
@ -221,7 +201,7 @@ Item {
sendTransactionWithEnsModal: cmpSendTransactionWithEns
stickersLoaded: root.stickersLoaded
isBlocked: model.blocked
isActiveChannel: categoryChatLoader.isActiveChannel
isActiveChannel: categoryChatLoader.visible
onOpenStickerPackPopup: {
root.openStickerPackPopup(stickerPackId)
}
@ -239,24 +219,15 @@ Item {
}
DelegateChoice { // In all other cases
delegate: Loader {
property bool isActiveChannel: chatRepeater.isChatActive(model.itemId)
id: chatLoader
// Channels are not loaded by default and only load when first put active
active: false
active: model.active
visible: model.active
width: parent.width
height: isActiveChannel ? parent.height : 0
Connections {
id: defaultLoaderConnections
target: chatLoader
// First time this channel turns active, activate the Loader
onIsActiveChannelChanged: {
if (chatLoader.isActiveChannel) {
chatLoader.active = true
defaultLoaderConnections.enabled = false
}
}
}
height: parent.height
// Removing the binding in order not to unload the content
onStatusChanged: if (status == Loader.Ready) active = true
sourceComponent: ChatContentView {
visible: !root.rootStore.openCreateChat && isActiveChannel
@ -270,7 +241,7 @@ Item {
sendTransactionWithEnsModal: cmpSendTransactionWithEns
stickersLoaded: root.stickersLoaded
isBlocked: model.blocked
isActiveChannel: chatLoader.isActiveChannel
isActiveChannel: chatLoader.visible
onOpenStickerPackPopup: {
root.openStickerPackPopup(stickerPackId)
}