fix(community): ensure chats are reordered when cateories have changed
We were not reordering chats when their category IDs have changed, this resulted in missing updates in community member's UIs Closes #9329
This commit is contained in:
parent
81926de731
commit
182a189818
|
@ -172,12 +172,12 @@ proc init*(self: Controller) =
|
|||
self.events.on(SIGNAL_COMMUNITY_CHANNEL_REORDERED) do(e:Args):
|
||||
let args = CommunityChatOrderArgs(e)
|
||||
if (args.communityId == self.sectionId):
|
||||
self.delegate.onReorderChat(args.chatId, args.position, args.categoryId)
|
||||
self.delegate.onReorderChat(args.chatId, args.position, args.categoryId, args.prevCategoryId, false)
|
||||
|
||||
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.delegate.onReorderChat(args.chatId, args.position, args.categoryId, args.prevCategoryId, args.prevCategoryDeleted)
|
||||
|
||||
self.events.on(SIGNAL_RELOAD_MESSAGES) do(e: Args):
|
||||
let args = ReloadMessagesArgs(e)
|
||||
|
|
|
@ -124,7 +124,7 @@ method onGroupChatDetailsUpdated*(self: AccessInterface, chatId: string, newName
|
|||
method onCommunityChannelEdited*(self: AccessInterface, chat: ChatDto) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onReorderChat*(self: AccessInterface, chattId: string, position: int, newCategoryIdForChat: string) {.base.} =
|
||||
method onReorderChat*(self: AccessInterface, chattId: string, position: int, newCategoryIdForChat: string, prevCategoryId: string, prevCategoryDeleted: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onReorderCategory*(self: AccessInterface, catId: string, position: int) {.base.} =
|
||||
|
|
|
@ -185,6 +185,12 @@ QtObject:
|
|||
idx.inc
|
||||
return -1
|
||||
|
||||
proc hasEmptyChatItem*(self: Model, categoryId: string): bool =
|
||||
for it in self.items:
|
||||
if it.id == categoryId:
|
||||
return true
|
||||
return false
|
||||
|
||||
proc getCategoryNameForCategoryId*(self: Model, categoryId: string): string {.slot.} =
|
||||
let index = self.getItemIdxByCategory(categoryId)
|
||||
if index == -1:
|
||||
|
@ -391,7 +397,7 @@ QtObject:
|
|||
continue
|
||||
item.categoryName = newName
|
||||
let modelIndex = self.createIndex(i, 0, nil)
|
||||
self.dataChanged(modelIndex, modelIndex, @[ModelRole.CategoryName.int])
|
||||
self.dataChanged(modelIndex, modelIndex, @[ModelRole.CategoryId.int, ModelRole.CategoryName.int])
|
||||
|
||||
proc renameItemById*(self: Model, id, name: string) =
|
||||
let index = self.getItemIdxById(id)
|
||||
|
|
|
@ -29,6 +29,8 @@ import ../../../../app_service/service/contacts/dto/contacts as contacts_dto
|
|||
|
||||
export io_interface
|
||||
|
||||
const CATEGORY_ID_PREFIX = "cat-"
|
||||
|
||||
logScope:
|
||||
topics = "chat-section-module"
|
||||
|
||||
|
@ -130,7 +132,7 @@ proc removeSubmodule(self: Module, chatId: string) =
|
|||
proc addEmptyChatItemForCategory(self: Module, category: Category) =
|
||||
# Add an empty chat item that has the category info
|
||||
let emptyChatItem = chat_item.initItem(
|
||||
id = "cat-" & category.id,
|
||||
id = CATEGORY_ID_PREFIX & category.id,
|
||||
name = "",
|
||||
icon = "",
|
||||
color = "",
|
||||
|
@ -599,6 +601,8 @@ method onCommunityCategoryDeleted*(self: Module, cat: Category, chats: seq[ChatD
|
|||
newCategoryName = "",
|
||||
newCategoryPosition = -1,
|
||||
)
|
||||
self.view.chatsModel().removeItemById(CATEGORY_ID_PREFIX & cat.id)
|
||||
|
||||
|
||||
method setFirstChannelAsActive*(self: Module) =
|
||||
if(self.view.chatsModel().getCount() == 0):
|
||||
|
@ -614,7 +618,7 @@ method onCommunityCategoryChannelChanged*(self: Module, channelId: string, newCa
|
|||
else:
|
||||
self.setActiveItem(channelId)
|
||||
|
||||
method onReorderChat*(self: Module, chatId: string, position: int, newCategoryIdForChat: string) =
|
||||
method onReorderChat*(self: Module, chatId: string, position: int, newCategoryIdForChat: string, prevCategoryId: string, prevCategoryDeleted: bool) =
|
||||
var newCategoryName = ""
|
||||
var newCategoryPos = -1
|
||||
if newCategoryIdForChat != "":
|
||||
|
@ -622,6 +626,10 @@ method onReorderChat*(self: Module, chatId: string, position: int, newCategoryId
|
|||
newCategoryName = newCategory.name
|
||||
newCategoryPos = newCategory.position
|
||||
self.view.chatsModel().reorderChatById(chatId, position, newCategoryIdForChat, newCategoryName, newCategoryPos)
|
||||
if prevCategoryId != "" and not prevCategoryDeleted:
|
||||
if not self.view.chatsModel().hasEmptyChatItem(CATEGORY_ID_PREFIX & prevCategoryId):
|
||||
let category = self.controller.getCommunityCategoryDetails(self.controller.getMySectionId(), prevCategoryId)
|
||||
self.addEmptyChatItemForCategory(category)
|
||||
|
||||
method onReorderCategory*(self: Module, catId: string, position: int) =
|
||||
self.view.chatsModel().reorderCategoryById(catId, position)
|
||||
|
|
|
@ -52,6 +52,8 @@ type
|
|||
chatId*: string
|
||||
categoryId*: string
|
||||
position*: int
|
||||
prevCategoryId*: string
|
||||
prevCategoryDeleted*: bool
|
||||
|
||||
CommunityCategoryOrderArgs* = ref object of Args
|
||||
communityId*: string
|
||||
|
@ -371,10 +373,14 @@ QtObject:
|
|||
if community.settings.id == "":
|
||||
community.settings = prev_community.settings
|
||||
|
||||
var deletedCategories: seq[string] = @[]
|
||||
|
||||
# category was added
|
||||
if(community.categories.len > prev_community.categories.len):
|
||||
for category in community.categories:
|
||||
if findIndexById(category.id, prev_community.categories) == -1:
|
||||
self.allCommunities[community.id].categories.add(category)
|
||||
self.joinedCommunities[community.id].categories.add(category)
|
||||
let chats = self.getChatsInCategory(community, category.id)
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_CREATED,
|
||||
|
@ -384,6 +390,7 @@ QtObject:
|
|||
elif(community.categories.len < prev_community.categories.len):
|
||||
for prv_category in prev_community.categories:
|
||||
if findIndexById(prv_category.id, community.categories) == -1:
|
||||
deletedCategories.add(prv_category.id)
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_DELETED,
|
||||
CommunityCategoryArgs(communityId: community.id, category: Category(id: prv_category.id)))
|
||||
|
||||
|
@ -440,8 +447,16 @@ QtObject:
|
|||
|
||||
# Handle channel was added/removed to/from category
|
||||
if chat.categoryId != prev_chat.categoryId:
|
||||
|
||||
var prevCategoryDeleted = false
|
||||
if chat.categoryId == "":
|
||||
for catId in deletedCategories:
|
||||
if prev_chat.categoryId == catId:
|
||||
prevCategoryDeleted = true
|
||||
break
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CATEGORY_CHANGED, CommunityChatOrderArgs(communityId: community.id,
|
||||
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
|
||||
chatId: chat.id, categoryId: chat.categoryId, position: chat.position, prevCategoryId: prev_chat.categoryId, prevCategoryDeleted: prevCategoryDeleted))
|
||||
|
||||
# Handle name/description changes
|
||||
if chat.name != prev_chat.name or chat.description != prev_chat.description or chat.color != prev_chat.color:
|
||||
|
|
Loading…
Reference in New Issue