api: Add server_timestamp to register response.

Since this is currently only useful to interpret presence data, we
send this only if presence is requested.

I'm not sure that server_timestamp is the right name for this field,
but ultimately it should match the main presence API format.
This commit is contained in:
Tim Abbott
2021-05-20 11:01:51 -07:00
committed by Tim Abbott
parent 637c7e297c
commit 2e67b879ed
10 changed files with 27 additions and 6 deletions

View File

@@ -181,7 +181,7 @@ test("set_presence_info", () => {
const params = {}; const params = {};
params.presences = presences; params.presences = presences;
params.initial_servertime = now; params.server_timestamp = now;
presence.initialize(params); presence.initialize(params);
assert.deepEqual(presence.presence_info.get(alice.user_id), { assert.deepEqual(presence.presence_info.get(alice.user_id), {

View File

@@ -253,5 +253,5 @@ export function last_active_date(user_id) {
} }
export function initialize(params) { export function initialize(params) {
set_info(params.presences, params.initial_servertime); set_info(params.presences, params.server_timestamp);
} }

View File

@@ -446,7 +446,7 @@ export function initialize_everything() {
const pm_conversations_params = pop_fields("recent_private_conversations"); const pm_conversations_params = pop_fields("recent_private_conversations");
const presence_params = pop_fields("presences", "initial_servertime"); const presence_params = pop_fields("presences", "server_timestamp");
const stream_data_params = pop_fields( const stream_data_params = pop_fields(
"subscriptions", "subscriptions",

View File

@@ -11,6 +11,12 @@ below features are supported.
## Changes in Zulip 5.0 ## Changes in Zulip 5.0
**Feature level 70**
* [`POST /register`](/api/register-queue): Added new top-level
`server_timestamp` field when fetching presence data, to match the
existing presence API.
Feature levels 66-69 are reserved for future use in 4.x maintenance Feature levels 66-69 are reserved for future use in 4.x maintenance
releases. releases.

View File

@@ -32,7 +32,7 @@ DESKTOP_WARNING_VERSION = "5.4.3"
# #
# Changes should be accompanied by documentation explaining what the # Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md. # new level means in templates/zerver/api/changelog.md.
API_FEATURE_LEVEL = 65 API_FEATURE_LEVEL = 70
# Bump the minor PROVISION_VERSION to indicate that folks should provision # Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump # only when going from an old version of the code to a newer version. Bump

View File

@@ -1,6 +1,7 @@
# See https://zulip.readthedocs.io/en/latest/subsystems/events-system.html for # See https://zulip.readthedocs.io/en/latest/subsystems/events-system.html for
# high-level documentation on how this system works. # high-level documentation on how this system works.
import copy import copy
import time
from typing import Any, Callable, Collection, Dict, Iterable, Optional, Sequence, Set from typing import Any, Callable, Collection, Dict, Iterable, Optional, Sequence, Set
from django.conf import settings from django.conf import settings
@@ -177,6 +178,8 @@ def fetch_initial_state_data(
state["presences"] = ( state["presences"] = (
{} if user_profile is None else get_presences_for_realm(realm, slim_presence) {} if user_profile is None else get_presences_for_realm(realm, slim_presence)
) )
# Send server_timestamp, to match the format of `GET /presence` requests.
state["server_timestamp"] = time.time()
if want("realm"): if want("realm"):
# The realm bundle includes both realm properties and server # The realm bundle includes both realm properties and server

View File

@@ -233,7 +233,6 @@ def build_page_params_for_home_page_load(
# Only show marketing email settings if on Zulip Cloud # Only show marketing email settings if on Zulip Cloud
enable_marketing_emails_enabled=settings.CORPORATE_ENABLED, enable_marketing_emails_enabled=settings.CORPORATE_ENABLED,
# Misc. extra data. # Misc. extra data.
initial_servertime=time.time(), # Used for calculating relative presence age
default_language_name=get_language_name(register_ret["default_language"]), default_language_name=get_language_name(register_ret["default_language"]),
language_list_dbl_col=get_language_list_for_templates(register_ret["default_language"]), language_list_dbl_col=get_language_list_for_templates(register_ret["default_language"]),
language_list=get_language_list(), language_list=get_language_list(),

View File

@@ -7368,6 +7368,17 @@ paths:
id or email. id or email.
additionalProperties: additionalProperties:
$ref: "#/components/schemas/Presence" $ref: "#/components/schemas/Presence"
server_timestamp:
type: number
description: |
Present if `presence` is present in `fetch_event_types`.
The time when the server fetched the
`presences` data included in the response.
Matches the similar field in presence
responses.
**Changes**: New in Zulip 5.0 (feature level 70).
realm_domains: realm_domains:
type: array type: array
description: | description: |

View File

@@ -342,6 +342,8 @@ class BaseAction(ZulipTestCase):
state["unsubscribed"] = {u["name"]: u for u in state["unsubscribed"]} state["unsubscribed"] = {u["name"]: u for u in state["unsubscribed"]}
if "realm_bots" in state: if "realm_bots" in state:
state["realm_bots"] = {u["email"]: u for u in state["realm_bots"]} state["realm_bots"] = {u["email"]: u for u in state["realm_bots"]}
# Since time is different for every call, just fix the value
state["server_timestamp"] = 0
normalize(state1) normalize(state1)
normalize(state2) normalize(state2)

View File

@@ -92,7 +92,6 @@ class HomeTest(ZulipTestCase):
"has_zoom_token", "has_zoom_token",
"high_contrast_mode", "high_contrast_mode",
"hotspots", "hotspots",
"initial_servertime",
"insecure_desktop_app", "insecure_desktop_app",
"is_admin", "is_admin",
"is_guest", "is_guest",
@@ -214,6 +213,7 @@ class HomeTest(ZulipTestCase):
"server_inline_url_embed_preview", "server_inline_url_embed_preview",
"server_name_changes_disabled", "server_name_changes_disabled",
"server_needs_upgrade", "server_needs_upgrade",
"server_timestamp",
"settings_send_digest_emails", "settings_send_digest_emails",
"starred_message_counts", "starred_message_counts",
"starred_messages", "starred_messages",