2020-09-24 09:57:54 +10:00
|
|
|
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
2020-07-11 14:51:53 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import CppUtils 0.1
|
|
|
|
import "."
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
readonly property ListModel accounts: ModelStore.get("accounts")
|
|
|
|
readonly property var accountsSet: new Set()
|
|
|
|
|
|
|
|
function setPresence(userId, presence) {
|
|
|
|
py.callClientCoro(userId, "set_presence", [presence, undefined, false])
|
|
|
|
}
|
|
|
|
|
|
|
|
interval: 1000
|
|
|
|
repeat: true
|
2020-07-17 09:09:09 +10:00
|
|
|
running:
|
2020-10-08 11:12:32 +11:00
|
|
|
window.settings.Presence.auto_away_after > 0 &&
|
2020-07-17 09:09:09 +10:00
|
|
|
CppUtils.idleMilliseconds() !== -1
|
2020-07-11 14:51:53 +10:00
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
let changes = false
|
|
|
|
|
|
|
|
const beUnavailable =
|
|
|
|
CppUtils.idleMilliseconds() / 1000 >=
|
2020-10-08 11:12:32 +11:00
|
|
|
window.settings.Presence.auto_away_after
|
2020-07-11 14:51:53 +10:00
|
|
|
|
|
|
|
for (let i = 0; i < accounts.count; i++) {
|
|
|
|
const account = accounts.get(i)
|
|
|
|
|
2020-07-12 07:39:40 +10:00
|
|
|
if (! account.presence_support) continue
|
|
|
|
|
2020-07-11 14:51:53 +10:00
|
|
|
if (beUnavailable && account.presence === "online") {
|
|
|
|
setPresence(account.id, "unavailable")
|
|
|
|
accountsSet.add(account.id)
|
|
|
|
changes = true
|
|
|
|
|
|
|
|
} else if (! beUnavailable && accountsSet.has(account.id)) {
|
|
|
|
setPresence(account.id, "online")
|
|
|
|
accountsSet.delete(account.id)
|
|
|
|
changes = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes) accountsSetChanged()
|
|
|
|
}
|
|
|
|
}
|