Gather both Accounts and Rooms in all_rooms model
This commit is contained in:
@@ -16,19 +16,19 @@ HTile {
|
||||
|
||||
HUserAvatar {
|
||||
id: avatar
|
||||
userId: accountModel.id
|
||||
displayName: accountModel.display_name
|
||||
mxc: accountModel.avatar_url
|
||||
userId: model.id
|
||||
displayName: model.display_name
|
||||
mxc: model.avatar_url
|
||||
radius: 0
|
||||
compact: account.compact
|
||||
}
|
||||
|
||||
TitleLabel {
|
||||
text: accountModel.display_name || accountModel.id
|
||||
text: model.display_name || model.id
|
||||
color:
|
||||
hovered ?
|
||||
utils.nameColor(
|
||||
accountModel.display_name || accountModel.id.substring(1),
|
||||
model.display_name || model.id.substring(1),
|
||||
) :
|
||||
theme.accountView.account.name
|
||||
|
||||
@@ -42,7 +42,7 @@ HTile {
|
||||
backgroundColor: "transparent"
|
||||
toolTip.text: qsTr("Add new chat")
|
||||
onClicked: pageLoader.showPage(
|
||||
"AddChat/AddChat", {userId: accountModel.id},
|
||||
"AddChat/AddChat", {userId: model.id},
|
||||
)
|
||||
|
||||
Layout.fillHeight: true
|
||||
@@ -57,16 +57,15 @@ HTile {
|
||||
}
|
||||
}
|
||||
|
||||
contextMenu: AccountContextMenu { userId: accountModel.id }
|
||||
contextMenu: AccountContextMenu { userId: model.id }
|
||||
|
||||
onLeftClicked: {
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": accountModel.id }
|
||||
"AccountSettings/AccountSettings", { "userId": model.id }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
property var accountModel
|
||||
property bool isCurrent: false
|
||||
|
||||
|
||||
|
@@ -33,7 +33,9 @@ HColumnLayout {
|
||||
roomList.count === 0 || roomList.currentIndex === -1 ?
|
||||
-1 :
|
||||
model.findIndex(
|
||||
roomList.model.get(roomList.currentIndex).for_account, -1,
|
||||
roomList.model.get(roomList.currentIndex).for_account ||
|
||||
roomList.model.get(roomList.currentIndex).id,
|
||||
-1,
|
||||
)
|
||||
|
||||
model: ModelStore.get("matching_accounts")
|
||||
@@ -77,6 +79,11 @@ HColumnLayout {
|
||||
|
||||
HLoader {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin:
|
||||
accountList.highlightItem ?
|
||||
accountList.highlightItem.border.width :
|
||||
0
|
||||
|
||||
opacity: model.first_sync_done ? 0 : 1
|
||||
|
||||
active: opacity > 0
|
||||
@@ -96,14 +103,12 @@ HColumnLayout {
|
||||
|
||||
contextMenu: AccountContextMenu { userId: model.id }
|
||||
|
||||
onLeftClicked: {
|
||||
model.id in roomList.sectionIndice ?
|
||||
roomList.goToAccount(model.id) :
|
||||
pageLoader.showPage("AddChat/AddChat", {userId: model.id})
|
||||
}
|
||||
onLeftClicked: roomList.goToAccount(model.id)
|
||||
}
|
||||
|
||||
highlight: Item {
|
||||
readonly property alias border: border
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: theme.accountsBar.accountList.account.selectedBackground
|
||||
@@ -112,7 +117,7 @@ HColumnLayout {
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
z: 100
|
||||
id: border
|
||||
width: theme.accountsBar.accountList.account.selectedBorderSize
|
||||
height: parent.height
|
||||
color: theme.accountsBar.accountList.account.selectedBorder
|
||||
|
@@ -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