mirror of https://github.com/zulip/zulip.git
presence: Remove paranoid handling of falsy timestamps.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
a36ef0b593
commit
f88e3b9735
|
@ -219,8 +219,8 @@ export function set_info(
|
|||
|
||||
const raw: RawPresence = {
|
||||
server_timestamp,
|
||||
active_timestamp: info.active_timestamp || undefined,
|
||||
idle_timestamp: info.idle_timestamp || undefined,
|
||||
active_timestamp: info.active_timestamp,
|
||||
idle_timestamp: info.idle_timestamp,
|
||||
};
|
||||
|
||||
raw_info.set(user_id, raw);
|
||||
|
|
|
@ -206,24 +206,18 @@ test("set_presence_info", () => {
|
|||
assert.equal(presence.get_status(jane.user_id), "idle");
|
||||
});
|
||||
|
||||
test("falsy values", () => {
|
||||
test("missing values", () => {
|
||||
/*
|
||||
When a user does not have a relevant active timestamp,
|
||||
the server just leaves off the `active_timestamp` field
|
||||
to save bandwidth, which looks like `undefined` to us
|
||||
if we try to dereference it.
|
||||
|
||||
Our code should just treat all falsy values the same way,
|
||||
though, to defend against bugs where we say the person
|
||||
was last online in 1970 or silly things like that.
|
||||
*/
|
||||
const now = 2000000;
|
||||
const a_bit_ago = now - 5;
|
||||
const presences = {};
|
||||
|
||||
for (const falsy_value of [undefined, 0, null]) {
|
||||
presences[zoe.user_id.toString()] = {
|
||||
active_timestamp: falsy_value,
|
||||
idle_timestamp: a_bit_ago,
|
||||
};
|
||||
|
||||
|
@ -234,10 +228,7 @@ test("falsy values", () => {
|
|||
last_active: a_bit_ago,
|
||||
});
|
||||
|
||||
presences[zoe.user_id.toString()] = {
|
||||
active_timestamp: falsy_value,
|
||||
idle_timestamp: falsy_value,
|
||||
};
|
||||
presences[zoe.user_id.toString()] = {};
|
||||
|
||||
presence.set_info(presences, now);
|
||||
|
||||
|
@ -245,7 +236,6 @@ test("falsy values", () => {
|
|||
status: "offline",
|
||||
last_active: undefined,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("big realms", ({override_rewire}) => {
|
||||
|
|
Loading…
Reference in New Issue