diff --git a/src/app/modules/main/chat_section/model.nim b/src/app/modules/main/chat_section/model.nim index e48e6984cd..1ca4cd8d1b 100644 --- a/src/app/modules/main/chat_section/model.nim +++ b/src/app/modules/main/chat_section/model.nim @@ -532,6 +532,8 @@ QtObject: categoryId: string, position: int, ) = + self.beginResetModel() + for i in 0 ..< self.items.len: var item = self.items[i] if item.categoryId != categoryId: @@ -539,8 +541,9 @@ QtObject: if item.categoryPosition == position: continue item.categoryPosition = position - let modelIndex = self.createIndex(i, 0, nil) - self.dataChanged(modelIndex, modelIndex, @[ModelRole.CategoryPosition.int]) + + self.items.sort(cmpChatsAndCats) + self.endResetModel() proc clearItems*(self: Model) = self.beginResetModel() diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 055ca92c47..0b1634926a 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -1123,8 +1123,12 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) = ) self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true) -method reorderCommunityCategories*(self: Module, categoryId: string, position: int) = - self.controller.reorderCommunityCategories(categoryId, position) +method reorderCommunityCategories*(self: Module, categoryId: string, categoryPositon: int) = + var finalPosition = categoryPositon + if finalPosition < 0: + finalPosition = 0 + + self.controller.reorderCommunityCategories(categoryId, finalPosition) method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, toPosition: int): string = # Calculate actual position, since the position coming from the UI is assuming a single list where categories are items diff --git a/src/app/modules/main/chat_section/view.nim b/src/app/modules/main/chat_section/view.nim index 8e8c66b1cf..9a031f9abc 100644 --- a/src/app/modules/main/chat_section/view.nim +++ b/src/app/modules/main/chat_section/view.nim @@ -344,8 +344,8 @@ QtObject: proc prepareEditCategoryModel*(self: View, categoryId: string) {.slot.} = self.delegate.prepareEditCategoryModel(categoryId) - proc reorderCommunityCategories*(self: View, categoryId: string, position: int) {.slot} = - self.delegate.reorderCommunityCategories(categoryId, position) + proc reorderCommunityCategories*(self: View, categoryId: string, categoryPositon: int) {.slot} = + self.delegate.reorderCommunityCategories(categoryId, categoryPositon) proc reorderCommunityChat*(self: View, categoryId: string, chatId: string, position: int): string {.slot} = self.delegate.reorderCommunityChat(categoryId, chatId, position) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index cfc6e84623..ecad93ceed 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -401,22 +401,22 @@ QtObject: proc checkForCategoryPropertyUpdates(self: Service, community: CommunityDto, prev_community: CommunityDto) = for category in community.categories: - # id is present - let index = findIndexById(category.id, prev_community.categories) - if index == -1: - continue - # but something is different - let prev_category = prev_community.categories[index] + # id is present + let index = findIndexById(category.id, prev_community.categories) + if index == -1: + continue + # but something is different + let prev_category = prev_community.categories[index] - if category.position != prev_category.position: - self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED, - CommunityCategoryOrderArgs( - 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)) + if category.position != prev_category.position: + self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED, + CommunityCategoryOrderArgs( + 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)) proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string]) = @@ -1315,6 +1315,10 @@ QtObject: let error = Json.decode($response.error, RpcError) raise newException(RpcException, "Error reordering community category: " & error.message) + let updatedCommunity = response.result["communities"][0].toCommunityDto() + # Update community categories + self.checkForCategoryPropertyUpdates(updatedCommunity, self.communities[communityId]) + self.communities[communityId].categories = updatedCommunity.categories except Exception as e: error "Error reordering category channel", msg = e.msg, communityId, categoryId, position diff --git a/ui/StatusQ/src/StatusQ/Components/StatusChatList.qml b/ui/StatusQ/src/StatusQ/Components/StatusChatList.qml index 3096a670cf..d97095f609 100644 --- a/ui/StatusQ/src/StatusQ/Components/StatusChatList.qml +++ b/ui/StatusQ/src/StatusQ/Components/StatusChatList.qml @@ -51,6 +51,7 @@ Item { readonly property int visualIndex: index readonly property string chatId: model.itemId readonly property string categoryId: model.categoryId + readonly property int categoryPosition: model.categoryPosition // needed for the DnD readonly property bool isCategory: model.isCategory readonly property Item item: isCategory ? draggableItem.actions[0] : draggableItem.actions[1] @@ -72,7 +73,7 @@ Item { if (!drop.source.isCategory) { root.chatItemReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(from).chatId, to); } else { - root.categoryReordered(statusChatListItems.itemAtIndex(from).categoryId, to); + root.categoryReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(to).categoryPosition); } }