api: Improve encoding of stream/topic max field lengths.

Previously, you had to request the `stream` event type in order to get
the stream-level parameters; this was a bad design in part because the
`subscription` event type has similar data and is preferred by most
clients.

So we move these to the `realm` object.  We also add the maximum topic
length, as an adjacent parameter.

While changing this, we also fix these to better match the names of
similar API parameters.
This commit is contained in:
Tim Abbott
2021-04-10 08:50:58 -07:00
parent 1b5a16bd1f
commit 4a3ad0da06
6 changed files with 53 additions and 23 deletions

View File

@@ -49,6 +49,7 @@ from zerver.lib.user_mutes import get_user_mutes
from zerver.lib.user_status import get_user_info_dict
from zerver.lib.users import get_cross_realm_dicts, get_raw_user_data, is_administrator_role
from zerver.models import (
MAX_TOPIC_NAME_LENGTH,
Client,
CustomProfileField,
Message,
@@ -250,6 +251,10 @@ def fetch_initial_state_data(
else:
state["realm_signup_notifications_stream_id"] = -1
state["max_stream_name_length"] = Stream.MAX_NAME_LENGTH
state["max_stream_description_length"] = Stream.MAX_DESCRIPTION_LENGTH
state["max_topic_length"] = MAX_TOPIC_NAME_LENGTH
if want("realm_domains"):
state["realm_domains"] = get_realm_domains(realm)
@@ -415,8 +420,6 @@ def fetch_initial_state_data(
# be used when the mobile apps support logged-out
# access.
state["streams"] = get_web_public_streams(realm) # nocoverage
state["stream_name_max_length"] = Stream.MAX_NAME_LENGTH
state["stream_description_max_length"] = Stream.MAX_DESCRIPTION_LENGTH
if want("default_streams"):
if settings_user.is_guest:
# Guest users and logged-out users don't have access to