Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

presence: Use server-provided params in the webapp.

Mateusz Mandera8ef889f3921f
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index d554b61f2f1..1b3bbf97f14 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -577,6 +577,8 @@ test("update_presence_info", ({override}) => {
override(pm_list, "update_private_messages", () => {});
page_params.realm_presence_disabled = false;
+ page_params.server_presence_ping_interval_seconds = 50;
+ page_params.server_presence_offline_threshold_seconds = 140;
const server_time = 500;
const info = {
diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.js
index cb2073db7f8..6c4244f6210 100644
--- a/frontend_tests/node_tests/buddy_data.js
+++ b/frontend_tests/node_tests/buddy_data.js
@@ -422,6 +422,8 @@ test("always show me", () => {
});
test("level", () => {
+ page_params.server_presence_offline_threshold_seconds = 140;
+
add_canned_users();
assert.equal(buddy_data.level(me.user_id), 0);
assert.equal(buddy_data.level(selma.user_id), 3);
diff --git a/frontend_tests/node_tests/presence.js b/frontend_tests/node_tests/presence.js
index 7a6814bc8eb..afc770a86c1 100644
--- a/frontend_tests/node_tests/presence.js
+++ b/frontend_tests/node_tests/presence.js
@@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip");
-const {user_settings} = require("../zjsunit/zpage_params");
+const {page_params, user_settings} = require("../zjsunit/zpage_params");
const reload_state = mock_esm("../../static/js/reload_state", {
is_in_progress: () => false,
@@ -78,6 +78,7 @@ people.initialize_current_user(me.user_id);
function test(label, f) {
run_test(label, ({override}) => {
+ page_params.server_presence_offline_threshold_seconds = OFFLINE_THRESHOLD_SECS;
user_settings.presence_enabled = true;
presence.clear_internal_data();
f({override});
diff --git a/static/js/activity.js b/static/js/activity.js
index 065287fc516..69097be7c38 100644
--- a/static/js/activity.js
+++ b/static/js/activity.js
@@ -27,8 +27,6 @@ export let user_filter;
/* Broadcast "idle" to server after 5 minutes of local inactivity */
const DEFAULT_IDLE_TIMEOUT_MS = 5 * 60 * 1000;
-/* Time between keep-alive pings */
-const ACTIVE_PING_INTERVAL_MS = 50 * 1000;
/* Keep in sync with views.py:update_active_status_backend() */
export const ACTIVE = "active";
@@ -246,7 +244,9 @@ export function initialize() {
send_presence_to_server(true);
}
- util.call_function_periodically(get_full_presence_list_update, ACTIVE_PING_INTERVAL_MS);
+ /* Time between keep-alive pings */
+ const active_ping_interval_ms = page_params.server_presence_ping_interval_seconds * 1000;
+ util.call_function_periodically(get_full_presence_list_update, active_ping_interval_ms);
// Let the server know we're here, but pass "false" for
// want_redraw, since we just got all this info in page_params.
diff --git a/static/js/presence.js b/static/js/presence.js
index efde1b10425..0d9aa494136 100644
--- a/static/js/presence.js
+++ b/static/js/presence.js
@@ -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,
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index c9d4a5b14c8..3c843bd977c 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -488,7 +488,6 @@ LOG_API_EVENT_TYPES = False
STAGING = False
# How long to wait before presence should treat a user as offline.
-# Should match the presence.js constant.
OFFLINE_THRESHOLD_SECS = 140
# How often a client should ping by asking for presence data of all users.