refactor(DnD): improve chat reorder by passing destination directly
This commit is contained in:
parent
a69b8de3c3
commit
4dd383ffb5
|
@ -612,7 +612,7 @@ proc inviteUsersToCommunity*(self: Controller, pubKeys: string, inviteMessage: s
|
|||
proc reorderCommunityCategories*(self: Controller, categoryId: string, position: int) =
|
||||
self.communityService.reorderCommunityCategories(self.sectionId, categoryId, position)
|
||||
|
||||
proc reorderCommunityChat*(self: Controller, categoryId: string, chatId: string, position: int): string =
|
||||
proc reorderCommunityChat*(self: Controller, categoryId: string, chatId: string, position: int) =
|
||||
self.communityService.reorderCommunityChat(self.sectionId, categoryId, chatId, position)
|
||||
|
||||
proc getRenderedText*(self: Controller, parsedTextArray: seq[ParsedText], communityChats: seq[ChatDto]): string =
|
||||
|
|
|
@ -328,7 +328,7 @@ method prepareEditCategoryModel*(self: AccessInterface, categoryId: string) {.ba
|
|||
method reorderCommunityCategories*(self: AccessInterface, categoryId: string, position: int) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method reorderCommunityChat*(self: AccessInterface, categoryId: string, chatId: string, position: int): string {.base.} =
|
||||
method reorderCommunityChat*(self: AccessInterface, categoryId: string, chatId: string, position: int) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method downloadMessages*(self: AccessInterface, chatId: string, filePath: string) {.base.} =
|
||||
|
|
|
@ -174,15 +174,6 @@ QtObject:
|
|||
proc getItemIdxById*(self: Model, id: string): int =
|
||||
return getItemIdxById(self.items, id)
|
||||
|
||||
proc getClosestCategoryAtIndex*(self: Model, index: int): tuple[categoryIem: Item, categoryIndex: int] =
|
||||
if index > self.items.len:
|
||||
return (Item(), -1)
|
||||
# Count down from the index to 0 and find the first category
|
||||
for i in countdown(index - 1, 0):
|
||||
if self.items[i].isCategory:
|
||||
return (self.items[i], i)
|
||||
return (Item(), -1)
|
||||
|
||||
proc cmpChatsAndCats*(x, y: Item): int =
|
||||
# Sort proc to compare chats and categories
|
||||
# Compares first by categoryPosition, then by position
|
||||
|
|
|
@ -1123,28 +1123,15 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
|
|||
)
|
||||
self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true)
|
||||
|
||||
method reorderCommunityCategories*(self: Module, categoryId: string, categoryPositon: int) =
|
||||
var finalPosition = categoryPositon
|
||||
method reorderCommunityCategories*(self: Module, categoryId: string, categoryPosition: int) =
|
||||
var finalPosition = categoryPosition
|
||||
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
|
||||
# eg: if we have 2 categories with 2 channels each, then it means 6 items (2 categories, 2 chats)
|
||||
# if we move the 2nd channel of the 2nd category to the 1st position of the 2nd category, then the UI would say
|
||||
# that we move the chat from position 5 to position 4
|
||||
# We need to translate that to position 1 of category 2
|
||||
let (category, categoryIndex) = self.view.chatsModel().getClosestCategoryAtIndex(toPosition + 1)
|
||||
var categoryId = ""
|
||||
var newPos = toPosition
|
||||
if (categoryIndex > -1):
|
||||
categoryId = category.id
|
||||
newPos = toPosition - categoryIndex - 1 # position is 0 based
|
||||
if newPos < 0:
|
||||
newPos = 0
|
||||
self.controller.reorderCommunityChat(categoryId, chatId, newPos)
|
||||
method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, toPosition: int) =
|
||||
self.controller.reorderCommunityChat(categoryId, chatId, toPosition + 1)
|
||||
|
||||
method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
|
||||
self.view.setLoadingHistoryMessagesInProgress(isLoading)
|
||||
|
|
|
@ -344,10 +344,10 @@ QtObject:
|
|||
proc prepareEditCategoryModel*(self: View, categoryId: string) {.slot.} =
|
||||
self.delegate.prepareEditCategoryModel(categoryId)
|
||||
|
||||
proc reorderCommunityCategories*(self: View, categoryId: string, categoryPositon: int) {.slot} =
|
||||
self.delegate.reorderCommunityCategories(categoryId, categoryPositon)
|
||||
proc reorderCommunityCategories*(self: View, categoryId: string, categoryPosition: int) {.slot} =
|
||||
self.delegate.reorderCommunityCategories(categoryId, categoryPosition)
|
||||
|
||||
proc reorderCommunityChat*(self: View, categoryId: string, chatId: string, position: int): string {.slot} =
|
||||
proc reorderCommunityChat*(self: View, categoryId: string, chatId: string, position: int) {.slot} =
|
||||
self.delegate.reorderCommunityChat(categoryId, chatId, position)
|
||||
|
||||
proc loadingHistoryMessagesInProgressChanged*(self: View) {.signal.}
|
||||
|
|
|
@ -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 position: model.position // needed for the DnD
|
||||
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]
|
||||
|
@ -70,10 +71,18 @@ Item {
|
|||
const to = chatListDelegate.visualIndex;
|
||||
if (to === from)
|
||||
return;
|
||||
if (!drop.source.isCategory) {
|
||||
root.chatItemReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(from).chatId, to);
|
||||
if (drop.source.isCategory) {
|
||||
root.categoryReordered(
|
||||
statusChatListItems.itemAtIndex(from).categoryId,
|
||||
statusChatListItems.itemAtIndex(to).categoryPosition
|
||||
);
|
||||
|
||||
} else {
|
||||
root.categoryReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(to).categoryPosition);
|
||||
root.chatItemReordered(
|
||||
statusChatListItems.itemAtIndex(to).categoryId,
|
||||
statusChatListItems.itemAtIndex(from).chatId,
|
||||
statusChatListItems.itemAtIndex(to).position,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue