fix(Communities/ChatsList): chats order updates handled correctly, subitems reordering fixed
fixes #6292
This commit is contained in:
parent
d048939b5d
commit
8d3f1a88a4
|
@ -73,13 +73,5 @@ proc appendSubItem*(self: Item, item: SubItem) =
|
||||||
self.subItems.appendItem(item)
|
self.subItems.appendItem(item)
|
||||||
self.BaseItem.muted = self.subItems.isAllMuted()
|
self.BaseItem.muted = self.subItems.isAllMuted()
|
||||||
|
|
||||||
proc prependSubItems*(self: Item, items: seq[SubItem]) =
|
|
||||||
self.subItems.prependItems(items)
|
|
||||||
self.BaseItem.muted = self.subItems.isAllMuted()
|
|
||||||
|
|
||||||
proc prependSubItem*(self: Item, item: SubItem) =
|
|
||||||
self.subItems.prependItem(item)
|
|
||||||
self.BaseItem.muted = self.subItems.isAllMuted()
|
|
||||||
|
|
||||||
proc setActiveSubItem*(self: Item, subItemId: string) =
|
proc setActiveSubItem*(self: Item, subItemId: string) =
|
||||||
self.subItems.setActiveItem(subItemId)
|
self.subItems.setActiveItem(subItemId)
|
||||||
|
|
|
@ -326,9 +326,15 @@ QtObject:
|
||||||
result.hasNotifications = result.hasNotifications or self.items[i].BaseItem.hasUnreadMessages
|
result.hasNotifications = result.hasNotifications or self.items[i].BaseItem.hasUnreadMessages
|
||||||
result.notificationsCount = result.notificationsCount + self.items[i].BaseItem.notificationsCount
|
result.notificationsCount = result.notificationsCount + self.items[i].BaseItem.notificationsCount
|
||||||
|
|
||||||
|
proc reorderSubModel(self: Model, chatId: string, position: int) =
|
||||||
|
for it in self.items:
|
||||||
|
if(it.subItems.getCount() > 0):
|
||||||
|
it.subItems.reorder(chatId, position)
|
||||||
|
|
||||||
proc reorder*(self: Model, chatOrCategoryId: string, position: int) =
|
proc reorder*(self: Model, chatOrCategoryId: string, position: int) =
|
||||||
let index = self.getItemIdxById(chatOrCategoryId)
|
let index = self.getItemIdxById(chatOrCategoryId)
|
||||||
if(index == -1):
|
if(index == -1):
|
||||||
|
self.reorderSubModel(chatOrCategoryId, position)
|
||||||
return
|
return
|
||||||
|
|
||||||
if(self.items[index].BaseItem.position == position):
|
if(self.items[index].BaseItem.position == position):
|
||||||
|
|
|
@ -201,7 +201,7 @@ proc buildChatSectionUI(
|
||||||
description="", ChatType.Unknown.int, amIChatAdmin=false, hasNotificationPerCategory,
|
description="", ChatType.Unknown.int, amIChatAdmin=false, hasNotificationPerCategory,
|
||||||
notificationsCountPerCategory, muted=false, blocked=false, active=false,
|
notificationsCountPerCategory, muted=false, blocked=false, active=false,
|
||||||
cat.position, cat.id)
|
cat.position, cat.id)
|
||||||
categoryItem.prependSubItems(categoryChannels)
|
categoryItem.appendSubItems(categoryChannels)
|
||||||
self.view.chatsModel().appendItem(categoryItem)
|
self.view.chatsModel().appendItem(categoryItem)
|
||||||
|
|
||||||
self.setActiveItemSubItem(selectedItemId, selectedSubItemId)
|
self.setActiveItemSubItem(selectedItemId, selectedSubItemId)
|
||||||
|
@ -478,7 +478,7 @@ method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatD
|
||||||
self.view.chatsModel().removeItemById(chatDto.id)
|
self.view.chatsModel().removeItemById(chatDto.id)
|
||||||
categoryChannels.add(channelItem)
|
categoryChannels.add(channelItem)
|
||||||
|
|
||||||
categoryItem.prependSubItems(categoryChannels)
|
categoryItem.appendSubItems(categoryChannels)
|
||||||
self.view.chatsModel().appendItem(categoryItem)
|
self.view.chatsModel().appendItem(categoryItem)
|
||||||
|
|
||||||
method onCommunityCategoryDeleted*(self: Module, cat: Category) =
|
method onCommunityCategoryDeleted*(self: Module, cat: Category) =
|
||||||
|
@ -534,7 +534,7 @@ method onCommunityCategoryEdited*(self: Module, cat: Category, chats: seq[ChatDt
|
||||||
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int,
|
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int,
|
||||||
amIChatAdmin=true, hasNotification, notificationsCount, chatDto.muted, blocked=false,
|
amIChatAdmin=true, hasNotification, notificationsCount, chatDto.muted, blocked=false,
|
||||||
active=false, chatDto.position)
|
active=false, chatDto.position)
|
||||||
categoryItem.prependSubItem(channelItem)
|
categoryItem.appendSubItem(channelItem)
|
||||||
else:
|
else:
|
||||||
let channelItem = initItem(chatDto.id, chatDto.name, chatDto.icon,
|
let channelItem = initItem(chatDto.id, chatDto.name, chatDto.icon,
|
||||||
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int, amIChatAdmin,
|
chatDto.color, chatDto.emoji, chatDto.description, chatDto.chatType.int, amIChatAdmin,
|
||||||
|
|
|
@ -143,28 +143,6 @@ QtObject:
|
||||||
|
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
|
|
||||||
proc prependItems*(self: SubModel, items: seq[SubItem]) =
|
|
||||||
let parentModelIndex = newQModelIndex()
|
|
||||||
defer: parentModelIndex.delete
|
|
||||||
|
|
||||||
let first = 0
|
|
||||||
let last = items.len - 1
|
|
||||||
self.beginInsertRows(parentModelIndex, first, last)
|
|
||||||
self.items = items & self.items
|
|
||||||
self.endInsertRows()
|
|
||||||
|
|
||||||
self.countChanged()
|
|
||||||
|
|
||||||
proc prependItem*(self: SubModel, item: SubItem) =
|
|
||||||
let parentModelIndex = newQModelIndex()
|
|
||||||
defer: parentModelIndex.delete
|
|
||||||
|
|
||||||
self.beginInsertRows(parentModelIndex, 0, 0)
|
|
||||||
self.items = item & self.items
|
|
||||||
self.endInsertRows()
|
|
||||||
|
|
||||||
self.countChanged()
|
|
||||||
|
|
||||||
proc getItemById*(self: SubModel, id: string): SubItem =
|
proc getItemById*(self: SubModel, id: string): SubItem =
|
||||||
for it in self.items:
|
for it in self.items:
|
||||||
if(it.id == id):
|
if(it.id == id):
|
||||||
|
@ -247,6 +225,16 @@ QtObject:
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
|
|
||||||
|
proc reorder*(self: SubModel, id: string, position: int) =
|
||||||
|
let index = self.getItemIdxById(id)
|
||||||
|
if index == -1:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.items[index].BaseItem.position = position
|
||||||
|
|
||||||
|
let modelIndex = self.createIndex(index, 0, nil)
|
||||||
|
self.dataChanged(modelIndex, modelIndex, @[ModelRole.Position.int])
|
||||||
|
|
||||||
proc updateNotificationsForItemById*(self: SubModel, id: string, hasUnreadMessages: bool,
|
proc updateNotificationsForItemById*(self: SubModel, id: string, hasUnreadMessages: bool,
|
||||||
notificationsCount: int): bool =
|
notificationsCount: int): bool =
|
||||||
for i in 0 ..< self.items.len:
|
for i in 0 ..< self.items.len:
|
||||||
|
|
|
@ -320,7 +320,7 @@ QtObject:
|
||||||
# Handle position changes
|
# Handle position changes
|
||||||
if(chat.id == prev_chat.id and chat.position != prev_chat.position):
|
if(chat.id == prev_chat.id and chat.position != prev_chat.position):
|
||||||
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id,
|
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id,
|
||||||
chatId: community.id&chat.id, categoryId: chat.categoryId, position: chat.position))
|
chatId: chat.id, categoryId: chat.categoryId, position: chat.position))
|
||||||
|
|
||||||
# Handle name/description changes
|
# Handle name/description changes
|
||||||
if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)):
|
if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)):
|
||||||
|
|
Loading…
Reference in New Issue