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-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:
|
2020-07-11 00:42:42 +10:00
|
|
|
window.uiState.page === "Pages/AccountSettings/AccountSettings.qml" ||
|
|
|
|
window.uiState.page === "Pages/AddChat/AddChat.qml"
|
2020-07-12 14:25:57 +10:00
|
|
|
|
2020-05-14 12:40:24 +10:00
|
|
|
readonly property bool currentShouldBeRoom:
|
|
|
|
window.uiState.page === "Pages/Chat/Chat.qml"
|
2020-07-12 14:25:57 +10:00
|
|
|
|
2020-05-14 12:40:24 +10:00
|
|
|
readonly property string wantedUserId:
|
|
|
|
window.uiState.pageProperties.userId || ""
|
2020-07-12 14:25:57 +10:00
|
|
|
|
2020-05-14 12:40:24 +10:00
|
|
|
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-06-01 09:13:19 +10:00
|
|
|
function cycleUnreadRooms(forward=true, highlights=false) {
|
|
|
|
const prop = highlights ? "highlights" : "unreads"
|
2020-05-14 15:21:44 +10:00
|
|
|
const start = currentIndex === -1 ? 0 : currentIndex
|
|
|
|
let index = start
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
index += forward ? 1 : -1
|
|
|
|
|
2020-05-16 07:07:43 +10:00
|
|
|
if (index < 0) index = model.count - 1
|
2020-05-14 15:21:44 +10:00
|
|
|
if (index > model.count - 1) index = 0
|
2020-05-16 07:07:43 +10:00
|
|
|
|
2020-06-01 09:13:19 +10:00
|
|
|
if (index === start && highlights)
|
2020-05-16 07:07:43 +10:00
|
|
|
return cycleUnreadRooms(forward, false)
|
|
|
|
else if (index === start)
|
|
|
|
return false
|
2020-05-14 15:21:44 +10:00
|
|
|
|
|
|
|
const item = model.get(index)
|
|
|
|
|
|
|
|
if (item.type === "Room" && item[prop]) {
|
|
|
|
currentIndex = index
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-06-05 15:07:39 +10:00
|
|
|
function startCorrectItemSearch() {
|
|
|
|
correctTimer.start()
|
|
|
|
}
|
|
|
|
|
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" &&
|
2020-05-18 05:32:10 +10:00
|
|
|
item.id === wantedUserId
|
2020-05-14 12:40:24 +10:00
|
|
|
)) {
|
|
|
|
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-07-12 14:25:57 +10:00
|
|
|
model: ModelStore.get("all_rooms")
|
|
|
|
|
|
|
|
delegate: DelegateChooser {
|
|
|
|
role: "type"
|
|
|
|
|
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Account"
|
|
|
|
AccountDelegate {
|
|
|
|
width: roomList.width
|
|
|
|
leftPadding: theme.spacing
|
|
|
|
rightPadding: 0 // the right buttons have padding
|
|
|
|
|
|
|
|
filterActive: Boolean(filter)
|
|
|
|
enableKeybinds: Boolean(
|
|
|
|
roomList.model.get(currentIndex) && (
|
|
|
|
roomList.model.get(currentIndex).for_account ||
|
|
|
|
roomList.model.get(currentIndex).id
|
|
|
|
) === model.id
|
|
|
|
)
|
|
|
|
|
|
|
|
totalMessageIndicator.visible: false
|
|
|
|
|
|
|
|
onLeftClicked: showItemAtIndex(model.index)
|
|
|
|
onCollapsedChanged:
|
|
|
|
if (wantedUserId === model.id) startCorrectItemSearch()
|
|
|
|
|
|
|
|
onWentToAccountPage: roomList.currentIndex = model.index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Room"
|
|
|
|
RoomDelegate {
|
|
|
|
width: roomList.width
|
|
|
|
onLeftClicked: showItemAtIndex(model.index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onFilterChanged: {
|
|
|
|
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
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
startCorrectItemSearch()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-14 12:47:04 +10:00
|
|
|
Connections {
|
|
|
|
target: pageLoader
|
2020-06-23 04:11:56 +10:00
|
|
|
|
|
|
|
function onPreviousShown(componentUrl, properties) {
|
2020-06-05 15:07:39 +10:00
|
|
|
if (setCorrectCurrentItem() === false) startCorrectItemSearch()
|
2020-06-23 04:11:56 +10:00
|
|
|
}
|
2020-05-14 12:47:04 +10:00
|
|
|
}
|
|
|
|
|
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-05-17 08:21:59 +10:00
|
|
|
onRunningChanged: if (running && currentIndex !== -1) currentIndex = -1
|
2020-05-14 12:40:24 +10:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|