presence: Use server-provided params in the webapp.

As of the previous commit, the server provides these parameters in
page_params. The defaults match the values hard-coded in the webapp so
far - so get rid of the hard-coded values in favor of taking them from
page_params.
This commit is contained in:
Mateusz Mandera
2023-02-21 11:52:30 +01:00
committed by Tim Abbott
parent a593089770
commit 8ef889f392
6 changed files with 16 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
import * as blueslip from "./blueslip";
import {page_params} from "./page_params";
import * as people from "./people";
import * as reload_state from "./reload_state";
import {user_settings} from "./user_settings";
@@ -22,11 +23,6 @@ export function clear_internal_data() {
presence_info.clear();
}
/* Mark users as offline after 140 seconds since their last checkin,
* Keep in sync with zerver/tornado/event_queue.py:receiver_is_idle
*/
const OFFLINE_THRESHOLD_SECS = 140;
const BIG_REALM_COUNT = 250;
export function get_status(user_id) {
@@ -58,6 +54,10 @@ export function status_from_raw(raw) {
server_timestamp: 1585745140
}
*/
/* Mark users as offline after this many seconds since their last checkin, */
const offline_threshold_secs = page_params.server_presence_offline_threshold_seconds;
function age(timestamp) {
return raw.server_timestamp - (timestamp || 0);
}
@@ -79,14 +79,14 @@ export function status_from_raw(raw) {
show the user as active (even if there's a newer
timestamp for idle).
*/
if (age(active_timestamp) < OFFLINE_THRESHOLD_SECS) {
if (age(active_timestamp) < offline_threshold_secs) {
return {
status: "active",
last_active,
};
}
if (age(idle_timestamp) < OFFLINE_THRESHOLD_SECS) {
if (age(idle_timestamp) < offline_threshold_secs) {
return {
status: "idle",
last_active,