Gather both Accounts and Rooms in all_rooms model
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQml.Models 2.12
|
||||
import Qt.labs.qmlmodels 1.0
|
||||
import ".."
|
||||
import "../Base"
|
||||
|
||||
@@ -10,82 +11,96 @@ HListView {
|
||||
id: roomList
|
||||
model: ModelStore.get("all_rooms")
|
||||
|
||||
delegate: Room {
|
||||
id: room
|
||||
width: roomList.width
|
||||
onActivated: showRoomAtIndex(model.index)
|
||||
}
|
||||
delegate: DelegateChooser {
|
||||
role: "type"
|
||||
|
||||
section.property: "for_account"
|
||||
section.labelPositioning:
|
||||
ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
|
||||
DelegateChoice {
|
||||
roleValue: "Account"
|
||||
Account { width: roomList.width }
|
||||
}
|
||||
|
||||
section.delegate: Account {
|
||||
width: roomList.width
|
||||
accountModel: ModelStore.get("accounts").find(section)
|
||||
DelegateChoice {
|
||||
roleValue: "Room"
|
||||
Room {
|
||||
width: roomList.width
|
||||
onActivated: showItemAtIndex(model.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onFilterChanged: py.callCoro("set_substring_filter", ["all_rooms", filter])
|
||||
|
||||
|
||||
property string filter: ""
|
||||
readonly property var sectionIndice: {
|
||||
const sections = {}
|
||||
let currentUserId = null
|
||||
readonly property var accountIndice: {
|
||||
const accounts = {}
|
||||
|
||||
for (let i = 0; i < model.count; i++) {
|
||||
const userId = model.get(i).for_account
|
||||
|
||||
if (userId !== currentUserId) {
|
||||
sections[userId] = i
|
||||
currentUserId = userId
|
||||
}
|
||||
if (model.get(i).type === "Account")
|
||||
accounts[model.get(i).id] = i
|
||||
}
|
||||
|
||||
return sections
|
||||
return accounts
|
||||
}
|
||||
|
||||
|
||||
function goToAccount(userId) {
|
||||
currentIndex = sectionIndice[userId]
|
||||
model.get(accountIndice[userId] + 1).type === "Room" ?
|
||||
currentIndex = accountIndice[userId] + 1 :
|
||||
currentIndex = accountIndice[userId]
|
||||
|
||||
showItemLimiter.restart()
|
||||
}
|
||||
|
||||
function goToAccountNumber(num) {
|
||||
currentIndex = Object.values(sectionIndice).sort()[num]
|
||||
const index = Object.values(accountIndice).sort()[num]
|
||||
|
||||
model.get(index + 1).type === "Room" ?
|
||||
currentIndex = index + 1 :
|
||||
currentIndex = index
|
||||
|
||||
showItemLimiter.restart()
|
||||
}
|
||||
|
||||
function showRoomAtIndex(index=currentIndex) {
|
||||
function showItemAtIndex(index=currentIndex) {
|
||||
if (index === -1) index = 0
|
||||
index = Math.min(index, model.count - 1)
|
||||
|
||||
const room = model.get(index)
|
||||
pageLoader.showRoom(room.for_account, room.id)
|
||||
const item = model.get(index)
|
||||
|
||||
item.type === "Account" ?
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": item.id }
|
||||
) :
|
||||
pageLoader.showRoom(item.for_account, item.id)
|
||||
|
||||
currentIndex = index
|
||||
}
|
||||
|
||||
function showAccountRoomAtIndex(index) {
|
||||
const currentUserId = model.get(
|
||||
currentIndex === -1 ? 0 : currentIndex
|
||||
).for_account
|
||||
const item = model.get(currentIndex === -1 ? 0 : currentIndex)
|
||||
|
||||
showRoomAtIndex(sectionIndice[currentUserId] + index)
|
||||
const currentUserId =
|
||||
item.type === "Account" ? item.id : item.for_account
|
||||
|
||||
showItemAtIndex(accountIndice[currentUserId] + 1 + index)
|
||||
}
|
||||
|
||||
|
||||
Timer {
|
||||
id: showRoomLimiter
|
||||
id: showItemLimiter
|
||||
interval: 200
|
||||
onTriggered: showRoomAtIndex()
|
||||
onTriggered: showItemAtIndex()
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.goToPreviousRoom
|
||||
onActivated: { decrementCurrentIndex(); showRoomLimiter.restart() }
|
||||
onActivated: { decrementCurrentIndex(); showItemLimiter.restart() }
|
||||
}
|
||||
|
||||
HShortcut {
|
||||
sequences: window.settings.keys.goToNextRoom
|
||||
onActivated: { incrementCurrentIndex(); showRoomLimiter.restart() }
|
||||
onActivated: { incrementCurrentIndex(); showItemLimiter.restart() }
|
||||
}
|
||||
|
||||
Repeater {
|
||||
|
Reference in New Issue
Block a user