2019-08-18 03:27:00 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../Base"
|
2019-08-19 10:28:49 -04:00
|
|
|
import "../utils.js" as Utils
|
2019-08-18 03:27:00 -04:00
|
|
|
|
|
|
|
HListView {
|
2019-08-30 11:05:11 -04:00
|
|
|
id: sidePaneList
|
2019-08-18 03:27:00 -04:00
|
|
|
|
2019-08-19 10:28:49 -04:00
|
|
|
|
|
|
|
readonly property var originSource: window.sidePaneModelSource
|
|
|
|
readonly property var collapseAccounts: window.uiState.collapseAccounts
|
2019-08-30 13:48:24 -04:00
|
|
|
readonly property string filter: toolBar.roomFilter
|
2019-08-23 10:53:54 -04:00
|
|
|
readonly property alias activateLimiter: activateLimiter
|
2019-08-19 10:28:49 -04:00
|
|
|
|
2019-08-22 14:16:49 -04:00
|
|
|
onOriginSourceChanged: filterLimiter.restart()
|
|
|
|
onFilterChanged: filterLimiter.restart()
|
|
|
|
onCollapseAccountsChanged: filterLimiter.restart()
|
2019-08-19 10:28:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
function filterSource() {
|
|
|
|
let show = []
|
|
|
|
|
2019-08-30 11:05:11 -04:00
|
|
|
// Hide a harmless error when activating a RoomDelegate
|
2019-08-19 13:09:05 -04:00
|
|
|
try { window.sidePaneModelSource } catch (err) { return }
|
|
|
|
|
2019-08-19 10:28:49 -04:00
|
|
|
for (let i = 0; i < window.sidePaneModelSource.length; i++) {
|
|
|
|
let item = window.sidePaneModelSource[i]
|
|
|
|
|
|
|
|
if (item.type == "Account" ||
|
|
|
|
(filter ?
|
|
|
|
Utils.filterMatches(filter, item.data.filter_string) :
|
|
|
|
! window.uiState.collapseAccounts[item.user_id]))
|
|
|
|
{
|
|
|
|
if (filter && show.length && item.type == "Account" &&
|
|
|
|
show[show.length - 1].type == "Account" &&
|
2019-08-19 11:34:51 -04:00
|
|
|
! Utils.filterMatches(
|
|
|
|
filter, show[show.length - 1].data.filter_string)
|
|
|
|
) {
|
2019-08-19 18:49:56 -04:00
|
|
|
// If filter active, current and previous items are
|
|
|
|
// both accounts and previous account doesn't match filter,
|
2019-08-19 10:28:49 -04:00
|
|
|
// that means the previous account had no matching rooms.
|
|
|
|
show.pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
show.push(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 18:49:56 -04:00
|
|
|
let last = show[show.length - 1]
|
|
|
|
if (show.length && filter && last.type == "Account" &&
|
|
|
|
! Utils.filterMatches(filter, last.data.filter_string))
|
|
|
|
{
|
|
|
|
// If filter active, last item is an account and last item
|
|
|
|
// doesn't match filter, that account had no matching rooms.
|
|
|
|
show.pop()
|
|
|
|
}
|
2019-08-19 10:28:49 -04:00
|
|
|
|
|
|
|
model.source = show
|
|
|
|
}
|
|
|
|
|
2019-08-20 13:41:55 -04:00
|
|
|
function previous(activate=true) {
|
2019-08-19 14:28:12 -04:00
|
|
|
decrementCurrentIndex()
|
2019-08-22 14:16:49 -04:00
|
|
|
if (activate) activateLimiter.restart()
|
2019-08-19 13:09:05 -04:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:41:55 -04:00
|
|
|
function next(activate=true) {
|
2019-08-19 14:28:12 -04:00
|
|
|
incrementCurrentIndex()
|
2019-08-22 14:16:49 -04:00
|
|
|
if (activate) activateLimiter.restart()
|
2019-08-20 13:41:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function activate() {
|
2019-08-21 04:39:07 -04:00
|
|
|
currentItem.item.activated()
|
2019-08-19 14:28:12 -04:00
|
|
|
}
|
|
|
|
|
2019-11-10 08:54:45 -04:00
|
|
|
function accountSettings() {
|
|
|
|
if (! currentItem) incrementCurrentIndex()
|
|
|
|
|
|
|
|
pageLoader.showPage(
|
2019-11-10 09:07:35 -04:00
|
|
|
"AccountSettings/AccountSettings",
|
2019-11-10 08:54:45 -04:00
|
|
|
{userId: currentItem.item.delegateModel.user_id},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-10 08:32:17 -04:00
|
|
|
function addNewChat() {
|
|
|
|
if (! currentItem) incrementCurrentIndex()
|
|
|
|
|
|
|
|
pageLoader.showPage(
|
|
|
|
"AddChat/AddChat",
|
|
|
|
{userId: currentItem.item.delegateModel.user_id},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-08-19 14:28:12 -04:00
|
|
|
function toggleCollapseAccount() {
|
2019-11-10 08:34:05 -04:00
|
|
|
if (filter) return
|
|
|
|
|
|
|
|
if (! currentItem) incrementCurrentIndex()
|
2019-08-19 14:28:12 -04:00
|
|
|
|
|
|
|
if (currentItem.item.delegateModel.type == "Account") {
|
|
|
|
currentItem.item.toggleCollapse()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < model.source.length; i++) {
|
|
|
|
let item = model.source[i]
|
|
|
|
|
|
|
|
if (item.type == "Account" && item.user_id ==
|
|
|
|
currentItem.item.delegateModel.user_id)
|
|
|
|
{
|
|
|
|
currentIndex = i
|
|
|
|
currentItem.item.toggleCollapse()
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 13:09:05 -04:00
|
|
|
}
|
|
|
|
|
2019-08-18 03:27:00 -04:00
|
|
|
|
|
|
|
model: HListModel {
|
|
|
|
keyField: "id"
|
2019-08-19 10:28:49 -04:00
|
|
|
source: originSource
|
2019-08-18 03:27:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
delegate: Loader {
|
2019-08-30 11:05:11 -04:00
|
|
|
width: sidePaneList.width
|
2019-08-21 06:02:00 -04:00
|
|
|
Component.onCompleted: setSource(
|
|
|
|
model.type == "Account" ?
|
2019-08-30 11:05:11 -04:00
|
|
|
"AccountDelegate.qml" : "RoomDelegate.qml",
|
|
|
|
{view: sidePaneList}
|
2019-08-21 06:02:00 -04:00
|
|
|
)
|
2019-08-18 03:27:00 -04:00
|
|
|
}
|
2019-08-19 18:17:59 -04:00
|
|
|
|
|
|
|
|
2019-08-22 14:16:49 -04:00
|
|
|
Timer {
|
2019-08-19 20:50:14 -04:00
|
|
|
id: filterLimiter
|
2019-08-22 14:16:49 -04:00
|
|
|
interval: 16
|
|
|
|
onTriggered: filterSource()
|
2019-08-19 20:50:14 -04:00
|
|
|
}
|
|
|
|
|
2019-08-22 14:16:49 -04:00
|
|
|
Timer {
|
2019-08-19 18:17:59 -04:00
|
|
|
id: activateLimiter
|
2019-08-22 14:16:49 -04:00
|
|
|
interval: 300
|
|
|
|
onTriggered: activate()
|
2019-08-19 18:17:59 -04:00
|
|
|
}
|
2019-08-18 03:27:00 -04:00
|
|
|
}
|