Move code that sets active flag on session to initSession

It doesn't belong in the `converse-status` plugin and the event handler
doesn't get registered when all CSI-related timeouts are set to 0.
This commit is contained in:
JC Brand 2022-07-25 11:59:25 +02:00
parent 0df1c1880e
commit 71d1383604
2 changed files with 9 additions and 4 deletions

View File

@ -101,10 +101,11 @@ export function sendCSI (stat) {
_converse.inactive = (stat === _converse.INACTIVE) ? true : false;
}
/**
* Set an interval of one second and register a handler for it.
* Required for the auto_away, auto_xa and csi_waiting_time features.
*/
export function registerIntervalHandler () {
/* Set an interval of one second and register a handler for it.
* Required for the auto_away, auto_xa and csi_waiting_time features.
*/
if (
api.settings.get("auto_away") < 1 &&
api.settings.get("auto_xa") < 1 &&
@ -123,7 +124,6 @@ export function registerIntervalHandler () {
window.addEventListener('keypress', _converse.onUserActivity);
window.addEventListener('mousemove', _converse.onUserActivity);
window.addEventListener(unloadevent, _converse.onUserActivity, {'once': true, 'passive': true});
window.addEventListener(unloadevent, () => _converse.session?.save('active', false));
_converse.everySecondTrigger = window.setInterval(_converse.onEverySecond, 1000);
}

View File

@ -136,6 +136,7 @@ function saveJIDtoSession (_converse, jid) {
// We use the `active` flag to determine whether we should use the values from sessionStorage.
// When "cloning" a tab (e.g. via middle-click), the `active` flag will be set and we'll create
// a new empty user session, otherwise it'll be false and we can re-use the user session.
// When the tab is reloaded, the `active` flag is set to `false`.
'active': true
});
// Set JID on the connection object so that when we call `connection.bind`
@ -184,6 +185,10 @@ export async function initSession (_converse, jid) {
_converse.session.save({id});
}
saveJIDtoSession(_converse, jid);
// Set `active` flag to false when the tab gets reloaded
window.addEventListener(_converse.unloadevent, () => _converse.session?.save('active', false));
/**
* Triggered once the user's session has been initialized. The session is a
* cache which stores information about the user's current session.