fix: unbreak chat categories height and highlight

- fix chat category/section height not being (re)set to 0 properly and
  hidden
- restore the chat category header highlighting when it contains new
  messages/mentions after the new flattened chat model refactoring

Fixes #9493
This commit is contained in:
Lukáš Tinkl 2023-02-08 20:34:41 +01:00 committed by Lukáš Tinkl
parent 4dc97dde1a
commit 4cefd4af2a
3 changed files with 51 additions and 50 deletions

View File

@ -202,8 +202,7 @@ QtObject:
if self.items[i].categoryId == categoryId: if self.items[i].categoryId == categoryId:
self.items[i].categoryOpened = opened self.items[i].categoryOpened = opened
let index = self.createIndex(i, 0, nil) let index = self.createIndex(i, 0, nil)
# Also signal on CategoryId because the section header only knows the categoryId self.dataChanged(index, index, @[ModelRole.CategoryOpened.int])
self.dataChanged(index, index, @[ModelRole.CategoryId.int, ModelRole.CategoryOpened.int])
proc removeItemByIndex(self: Model, idx: int) = proc removeItemByIndex(self: Model, idx: int) =
if idx == -1: if idx == -1:
@ -240,12 +239,13 @@ QtObject:
if(it.id == id): if(it.id == id):
return it return it
proc setCategoryHasUnreadMessages*(self: Model, id: string, value: bool) = proc categoryHasUnreadMessagesChanged*(self: Model, categoryId: string, hasUnread: bool) {.signal.}
for i in 0 ..< self.items.len:
if(self.items[i].id == id): proc getCategoryHasUnreadMessages*(self: Model, categoryId: string): bool {.slot.} =
let index = self.createIndex(i, 0, nil) return self.items.anyIt(it.categoryId == categoryId and it.hasUnreadMessages)
self.items[i].hasUnreadMessages = value
self.dataChanged(index, index, @[ModelRole.HasUnreadMessages.int]) proc setCategoryHasUnreadMessages*(self: Model, categoryId: string, value: bool) =
self.categoryHasUnreadMessagesChanged(categoryId, value)
proc getCategoryAndPosition*(self: Model, id: string): (string, int) = proc getCategoryAndPosition*(self: Model, id: string): (string, int) =
let item = self.getItemById(id) let item = self.getItemById(id)

View File

@ -231,7 +231,7 @@ QtObject:
return false return false
for chat in self.channelGroups[communityId].chats: for chat in self.channelGroups[communityId].chats:
if chat.unviewedMentionsCount > 0 or chat.unviewedMentionsCount > 0: if chat.unviewedMessagesCount > 0 or chat.unviewedMentionsCount > 0:
return true return true
return false return false

View File

@ -1,6 +1,5 @@
import QtQuick 2.14 import QtQuick 2.15
import QtQml.Models 2.14 import QtQuick.Controls 2.15 as QC
import QtQuick.Controls 2.14 as QC
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
@ -38,37 +37,30 @@ Item {
height: contentHeight height: contentHeight
objectName: "chatListItems" objectName: "chatListItems"
model: root.model model: root.model
spacing: 4 spacing: 0
section.property: "categoryId" section.property: "categoryId"
section.criteria: ViewSection.FullString section.criteria: ViewSection.FullString
section.delegate: Loader { section.delegate: Loader {
readonly property string categoryId: {
// Update category data from here because `dataChanged` signals on the Name do not affect the section
// The section is only affected by CategoryId changes, but it never actually changes, so `categoryName` doesn't update automatically
updateCategoryData(section)
return section
}
property string categoryName: ""
property bool categoryOpened: true
function updateCategoryData(catId) {
categoryName = root.model.sourceModel.getCategoryNameForCategoryId(catId)
categoryOpened = root.model.sourceModel.getCategoryOpenedForCategoryId(catId)
}
id: statusChatListCategoryItemLoader id: statusChatListCategoryItemLoader
active: !!categoryId active: !!section
required property string section
sourceComponent: StatusChatListCategoryItem { sourceComponent: StatusChatListCategoryItem {
id: statusChatListCategoryItem id: statusChatListCategoryItem
function setupPopup() { function setupPopup() {
categoryPopupMenuSlot.item.categoryId = statusChatListCategoryItemLoader.categoryId categoryPopupMenuSlot.item.categoryId = statusChatListCategoryItemLoader.section
}
function toggleCategory() {
root.model.sourceModel.changeCategoryOpened(statusChatListCategoryItemLoader.section, !opened)
opened = root.model.sourceModel.getCategoryOpenedForCategoryId(statusChatListCategoryItemLoader.section)
} }
Connections { Connections {
enabled: categoryPopupMenuSlot.active && highlighted enabled: categoryPopupMenuSlot.active && statusChatListCategoryItem.highlighted
target: categoryPopupMenuSlot.item target: categoryPopupMenuSlot.item
function onClosed() { function onClosed() {
statusChatListCategoryItem.highlighted = false statusChatListCategoryItem.highlighted = false
@ -76,16 +68,26 @@ Item {
} }
} }
title: categoryName title: root.model.sourceModel.getCategoryNameForCategoryId(statusChatListCategoryItemLoader.section)
opened: categoryOpened opened: root.model.sourceModel.getCategoryOpenedForCategoryId(statusChatListCategoryItemLoader.section)
sensor.pressAndHoldInterval: 150 sensor.pressAndHoldInterval: 150
propagateTitleClicks: true // title click is handled as a normal click (fallthru) propagateTitleClicks: true // title click is handled as a normal click (fallthru)
showAddButton: showCategoryActionButtons showAddButton: showCategoryActionButtons
showMenuButton: !!root.popupMenu showMenuButton: !!root.popupMenu
// TODO uncomment this when drag and drop is reimplemented highlighted: false//statusChatListCategory.dragged // FIXME DND
highlighted: false//statusChatListCategory.dragged
hasUnreadMessages: root.model.sourceModel.getCategoryHasUnreadMessages(statusChatListCategoryItemLoader.section)
Connections {
target: root.model.sourceModel
function onCategoryHasUnreadMessagesChanged(categoryId: string, hasUnread: bool) {
if (categoryId === statusChatListCategoryItemLoader.section) {
statusChatListCategoryItem.hasUnreadMessages = hasUnread
}
}
}
onClicked: { onClicked: {
if (sensor.enabled) { if (sensor.enabled) {
if (mouse.button === Qt.RightButton && showCategoryActionButtons && !!root.categoryPopupMenu) { if (mouse.button === Qt.RightButton && showCategoryActionButtons && !!root.categoryPopupMenu) {
@ -93,11 +95,11 @@ Item {
highlighted = true; highlighted = true;
categoryPopupMenuSlot.item.popup() categoryPopupMenuSlot.item.popup()
} else if (mouse.button === Qt.LeftButton) { } else if (mouse.button === Qt.LeftButton) {
root.model.sourceModel.changeCategoryOpened(section, !statusChatListCategoryItem.opened) toggleCategory()
} }
} }
} }
onToggleButtonClicked: root.model.sourceModel.changeCategoryOpened(section, !statusChatListCategoryItem.opened) onToggleButtonClicked: toggleCategory()
onMenuButtonClicked: { onMenuButtonClicked: {
statusChatListCategoryItem.setupPopup() statusChatListCategoryItem.setupPopup()
highlighted = true highlighted = true
@ -114,25 +116,25 @@ Item {
delegate: Loader { delegate: Loader {
id: chatLoader id: chatLoader
active: model.type !== d.chatTypeCategory && model.categoryOpened active: model.type !== d.chatTypeCategory
// TODO fix height not adjusting height: active && item ? item.height : 0
// This below doesn't work well, the height stays at 0 after reopening visible: height
// height: active && item ? item.height : 0
sourceComponent: QC.Control {
sourceComponent: Item {
id: draggable id: draggable
objectName: model.name objectName: model.name
width: root.width width: root.width
height: statusChatListItem.height height: model.categoryOpened ? statusChatListItem.height : 0
verticalPadding: 2
property alias chatListItem: statusChatListItem property alias chatListItem: statusChatListItem
MouseArea { contentItem: MouseArea {
id: dragSensor id: dragSensor
anchors.fill: parent anchors.fill: parent
cursorShape: active ? Qt.ClosedHandCursor : Qt.PointingHandCursor cursorShape: active ? Qt.ClosedHandCursor : Qt.PointingHandCursor
hoverEnabled: true hoverEnabled: true
pressAndHoldInterval: 150
enabled: root.draggableItems enabled: root.draggableItems
property bool active: false property bool active: false
@ -140,7 +142,6 @@ Item {
property real startX: 0 property real startX: 0
drag.target: draggedListItemLoader.item drag.target: draggedListItemLoader.item
drag.threshold: 0.1
drag.filterChildren: true drag.filterChildren: true
onPressed: { onPressed: {
@ -173,7 +174,7 @@ Item {
opacity: dragSensor.active ? 0.0 : 1.0 opacity: dragSensor.active ? 0.0 : 1.0
originalOrder: model.position originalOrder: model.position
chatId: model.itemId chatId: model.itemId
categoryId: model.parentItemId? model.parentItemId : "" categoryId: model.categoryId
name: model.name name: model.name
type: !!model.type ? model.type : StatusChatListItem.Type.CommunityChat type: !!model.type ? model.type : StatusChatListItem.Type.CommunityChat
muted: model.muted muted: model.muted
@ -201,7 +202,7 @@ Item {
popupMenuSlot.item.openHandler = function () { popupMenuSlot.item.openHandler = function () {
if (!!originalOpenHandler) { if (!!originalOpenHandler) {
originalOpenHandler(model.itemId) originalOpenHandler(statusChatListItem.chatId)
} }
} }
@ -221,10 +222,10 @@ Item {
return return
} }
if (!statusChatListItem.selected) { if (!statusChatListItem.selected) {
root.chatItemSelected(model.parentItemId, model.itemId) root.chatItemSelected(statusChatListItem.categoryId, statusChatListItem.chatId)
} }
} }
onUnmute: root.chatItemUnmuted(model.itemId) onUnmute: root.chatItemUnmuted(statusChatListItem.chatId)
} }
} }