2020-04-27 04:20:45 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2020-05-12 20:09:07 +10:00
|
|
|
import Qt.labs.qmlmodels 1.0
|
2020-04-27 04:20:45 +10:00
|
|
|
import ".."
|
|
|
|
import "../Base"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: roomList
|
2020-05-06 15:49:25 +10:00
|
|
|
model: ModelStore.get("all_rooms")
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
delegate: DelegateChooser {
|
|
|
|
role: "type"
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Account"
|
2020-05-14 04:16:37 +10:00
|
|
|
Account {
|
|
|
|
width: roomList.width
|
2020-05-15 08:42:50 +10:00
|
|
|
leftPadding: theme.spacing
|
|
|
|
rightPadding: 0 // the right buttons have padding
|
|
|
|
|
2020-05-14 04:16:37 +10:00
|
|
|
filterActive: Boolean(filter)
|
2020-05-15 10:01:58 +10:00
|
|
|
enableKeybinds: Boolean(
|
|
|
|
roomList.model.get(currentIndex) && (
|
|
|
|
roomList.model.get(currentIndex).for_account ||
|
|
|
|
roomList.model.get(currentIndex).id
|
|
|
|
) === model.id
|
|
|
|
)
|
2020-05-15 08:42:50 +10:00
|
|
|
|
|
|
|
totalMessageIndicator.visible: false
|
|
|
|
|
|
|
|
onLeftClicked: pageLoader.showPage(
|
|
|
|
"AccountSettings/AccountSettings", {userId: model.id}
|
|
|
|
)
|
2020-05-14 04:16:37 +10:00
|
|
|
}
|
2020-05-12 20:09:07 +10:00
|
|
|
}
|
2020-05-02 02:26:32 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Room"
|
|
|
|
Room {
|
|
|
|
width: roomList.width
|
2020-05-15 08:42:50 +10:00
|
|
|
onLeftClicked: showItemAtIndex(model.index)
|
2020-05-12 20:09:07 +10:00
|
|
|
}
|
|
|
|
}
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-05-15 10:01:58 +10:00
|
|
|
onFilterChanged: {
|
2020-05-15 10:23:21 +10:00
|
|
|
py.callCoro("set_substring_filter", ["all_rooms", filter], () => {
|
|
|
|
if (filter) {
|
|
|
|
currentIndex = 1 // highlight the first matching room
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const item = model.get(currentIndex)
|
|
|
|
|
|
|
|
if (
|
|
|
|
! filter &&
|
|
|
|
item && (
|
|
|
|
currentIndex === 1 || // required, related to the if above
|
|
|
|
(
|
|
|
|
currentShouldBeAccount &&
|
|
|
|
wantedUserId !== item.id
|
|
|
|
) || (
|
|
|
|
currentShouldBeRoom && (
|
|
|
|
wantedUserId !== item.for_account ||
|
|
|
|
wantedRoomId !== item.id
|
|
|
|
)
|
|
|
|
)
|
2020-05-15 10:01:58 +10:00
|
|
|
)
|
2020-05-15 10:23:21 +10:00
|
|
|
)
|
|
|
|
currentIndex = -1 // will trigger the correctTimer
|
|
|
|
})
|
2020-05-15 10:01:58 +10:00
|
|
|
}
|
2020-05-06 15:49:25 +10:00
|
|
|
|
2020-04-28 12:10:10 +10:00
|
|
|
|
2020-05-06 15:49:25 +10:00
|
|
|
property string filter: ""
|
2020-05-14 12:40:24 +10:00
|
|
|
|
|
|
|
readonly property bool currentShouldBeAccount:
|
|
|
|
window.uiState.page === "Pages/AccountSettings/AccountSettings.qml"
|
|
|
|
readonly property bool currentShouldBeRoom:
|
|
|
|
window.uiState.page === "Pages/Chat/Chat.qml"
|
|
|
|
readonly property string wantedUserId:
|
|
|
|
window.uiState.pageProperties.userId || ""
|
|
|
|
readonly property string wantedRoomId:
|
|
|
|
window.uiState.pageProperties.roomId || ""
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
readonly property var accountIndice: {
|
|
|
|
const accounts = {}
|
2020-05-02 03:02:20 +10:00
|
|
|
|
2020-05-06 15:49:25 +10:00
|
|
|
for (let i = 0; i < model.count; i++) {
|
2020-05-12 20:09:07 +10:00
|
|
|
if (model.get(i).type === "Account")
|
|
|
|
accounts[model.get(i).id] = i
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
return accounts
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function goToAccount(userId) {
|
2020-05-14 17:49:52 +10:00
|
|
|
accountIndice[userId] + 1 <= model.count -1 &&
|
2020-05-12 20:09:07 +10:00
|
|
|
model.get(accountIndice[userId] + 1).type === "Room" ?
|
|
|
|
currentIndex = accountIndice[userId] + 1 :
|
|
|
|
currentIndex = accountIndice[userId]
|
|
|
|
|
|
|
|
showItemLimiter.restart()
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
function goToAccountNumber(num) {
|
2020-05-14 16:48:48 +10:00
|
|
|
const index = Object.entries(accountIndice).sort()[num][1]
|
2020-05-12 20:09:07 +10:00
|
|
|
|
|
|
|
model.get(index + 1).type === "Room" ?
|
|
|
|
currentIndex = index + 1 :
|
|
|
|
currentIndex = index
|
|
|
|
|
|
|
|
showItemLimiter.restart()
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
function showItemAtIndex(index=currentIndex) {
|
2020-04-28 12:10:10 +10:00
|
|
|
if (index === -1) index = 0
|
2020-05-06 15:49:25 +10:00
|
|
|
index = Math.min(index, model.count - 1)
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
const item = model.get(index)
|
|
|
|
|
|
|
|
item.type === "Account" ?
|
|
|
|
pageLoader.showPage(
|
|
|
|
"AccountSettings/AccountSettings", { "userId": item.id }
|
|
|
|
) :
|
|
|
|
pageLoader.showRoom(item.for_account, item.id)
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
currentIndex = index
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function showAccountRoomAtIndex(index) {
|
2020-05-12 20:09:07 +10:00
|
|
|
const item = model.get(currentIndex === -1 ? 0 : currentIndex)
|
|
|
|
|
|
|
|
const currentUserId =
|
|
|
|
item.type === "Account" ? item.id : item.for_account
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
showItemAtIndex(accountIndice[currentUserId] + 1 + index)
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
2020-05-14 15:21:44 +10:00
|
|
|
function cycleUnreadRooms(forward=true, mentions=false) {
|
|
|
|
const prop = mentions ? "mentions" : "unreads"
|
|
|
|
const start = currentIndex === -1 ? 0 : currentIndex
|
|
|
|
let index = start
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
index += forward ? 1 : -1
|
|
|
|
|
|
|
|
if (index < 0) index = model.count - 1
|
|
|
|
if (index > model.count - 1) index = 0
|
|
|
|
if (index === start) return false
|
|
|
|
|
|
|
|
const item = model.get(index)
|
|
|
|
|
|
|
|
if (item.type === "Room" && item[prop]) {
|
|
|
|
currentIndex = index
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-05-14 12:40:24 +10:00
|
|
|
function setCorrectCurrentItem() {
|
|
|
|
if (! currentShouldBeRoom && ! currentShouldBeAccount) {
|
|
|
|
currentIndex = -1
|
2020-05-14 12:47:04 +10:00
|
|
|
return null
|
2020-05-14 12:40:24 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < model.count; i++) {
|
|
|
|
const item = model.get(i)
|
|
|
|
|
|
|
|
if ((
|
|
|
|
currentShouldBeRoom &&
|
|
|
|
item.type === "Room" &&
|
|
|
|
item.id === wantedRoomId &&
|
|
|
|
item.for_account === wantedUserId
|
|
|
|
) || (
|
|
|
|
currentShouldBeAccount &&
|
|
|
|
item.type === "Account" &&
|
|
|
|
item.id === wantedRoomId &&
|
|
|
|
item.for_account === wantedUserId
|
|
|
|
)) {
|
|
|
|
currentIndex = i
|
2020-05-14 12:47:04 +10:00
|
|
|
return true
|
2020-05-14 12:40:24 +10:00
|
|
|
}
|
|
|
|
}
|
2020-05-14 12:47:04 +10:00
|
|
|
|
|
|
|
return false
|
2020-05-14 12:40:24 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-14 12:47:04 +10:00
|
|
|
Connections {
|
|
|
|
target: pageLoader
|
|
|
|
onPreviousShown:
|
|
|
|
// Will trigger the timer above if item isn't found
|
|
|
|
if (setCorrectCurrentItem() === false) currentIndex = -1
|
|
|
|
}
|
|
|
|
|
2020-05-14 12:40:24 +10:00
|
|
|
Timer {
|
|
|
|
// On startup, the account/room takes an unknown amount of time to
|
|
|
|
// arrive in the model, try to find it until then.
|
2020-05-15 10:01:58 +10:00
|
|
|
id: correctTimer
|
2020-05-14 12:40:24 +10:00
|
|
|
interval: 200
|
|
|
|
running: currentIndex === -1
|
|
|
|
repeat: true
|
|
|
|
triggeredOnStart: true
|
|
|
|
onTriggered: setCorrectCurrentItem()
|
|
|
|
}
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
Timer {
|
2020-05-12 20:09:07 +10:00
|
|
|
id: showItemLimiter
|
2020-04-27 04:20:45 +10:00
|
|
|
interval: 200
|
2020-05-12 20:09:07 +10:00
|
|
|
onTriggered: showItemAtIndex()
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToPreviousRoom
|
2020-05-12 20:09:07 +10:00
|
|
|
onActivated: { decrementCurrentIndex(); showItemLimiter.restart() }
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToNextRoom
|
2020-05-12 20:09:07 +10:00
|
|
|
onActivated: { incrementCurrentIndex(); showItemLimiter.restart() }
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
2020-05-14 15:21:44 +10:00
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToPreviousUnreadRoom
|
|
|
|
onActivated: { cycleUnreadRooms(false) && showItemLimiter.restart() }
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToNextUnreadRoom
|
|
|
|
onActivated: { cycleUnreadRooms(true) && showItemLimiter.restart() }
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToPreviousMentionedRoom
|
|
|
|
onActivated: cycleUnreadRooms(false, true) && showItemLimiter.restart()
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToNextMentionedRoom
|
|
|
|
onActivated: cycleUnreadRooms(true, true) && showItemLimiter.restart()
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:48:48 +10:00
|
|
|
Repeater {
|
|
|
|
model: Object.keys(window.settings.keys.focusAccountAtIndex)
|
|
|
|
|
|
|
|
Item {
|
|
|
|
HShortcut {
|
|
|
|
sequence: window.settings.keys.focusAccountAtIndex[modelData]
|
|
|
|
onActivated: goToAccountNumber(parseInt(modelData - 1, 10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 15:21:44 +10:00
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
Repeater {
|
|
|
|
model: Object.keys(window.settings.keys.focusRoomAtIndex)
|
|
|
|
|
|
|
|
Item {
|
|
|
|
HShortcut {
|
|
|
|
sequence: window.settings.keys.focusRoomAtIndex[modelData]
|
2020-04-30 04:00:02 +10:00
|
|
|
onActivated:
|
|
|
|
showAccountRoomAtIndex(parseInt(modelData - 1, 10))
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 13:49:36 +10:00
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
z: -100
|
2020-05-13 22:24:53 +10:00
|
|
|
color: theme.mainPane.listView.background
|
2020-04-28 13:49:36 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|