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.

stream/docs: Add date_created to Stream.API_FIELDS.

Sumanth V Rao9b6de63afea2
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 114de6b0456..a0bbe2bb03f 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -4879,8 +4879,6 @@ def gather_subscriptions_helper(user_profile: UserProfile,
all_streams = get_active_streams(user_profile.realm).select_related(
"realm").values(
*Stream.API_FIELDS,
- # date_created is used as an input for the stream_weekly_traffic computed field.
- "date_created",
# The realm_id and recipient_id are generally not needed in the API.
"realm_id",
"recipient_id",
@@ -4934,6 +4932,9 @@ def gather_subscriptions_helper(user_profile: UserProfile,
if field_name == "id":
stream_dict['stream_id'] = stream["id"]
continue
+ elif field_name == "date_created":
+ stream_dict['date_created'] = datetime_to_timestamp(stream[field_name])
+ continue
stream_dict[field_name] = stream[field_name]
# Copy Subscription.API_FIELDS except for "active", which is
@@ -4991,6 +4992,9 @@ def gather_subscriptions_helper(user_profile: UserProfile,
if field_name == "id":
stream_dict['stream_id'] = stream["id"]
continue
+ elif field_name == "date_created":
+ stream_dict['date_created'] = datetime_to_timestamp(stream[field_name])
+ continue
stream_dict[field_name] = stream[field_name]
stream_dict['stream_weekly_traffic'] = get_average_weekly_stream_traffic(
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index 04c849f9e7a..96e684811ce 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -38,6 +38,7 @@ basic_stream_fields = [
("rendered_description", check_string),
("stream_id", check_int),
("stream_post_policy", check_int),
+ ("date_created", check_int),
]
subscription_fields: Sequence[Tuple[str, Validator[object]]] = [
diff --git a/zerver/models.py b/zerver/models.py
index 08f55c0556d..29be12c39bf 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -1554,8 +1554,6 @@ class Stream(models.Model):
# * is_in_zephyr_realm is a backend-only optimization.
# * "deactivated" streams are filtered from the API entirely.
# * "realm" and "recipient" are not exposed to clients via the API.
- # * "date_created" should probably be added here, as it's useful information
- # to subscribers.
API_FIELDS = [
"name",
"id",
@@ -1566,7 +1564,8 @@ class Stream(models.Model):
"stream_post_policy",
"history_public_to_subscribers",
"first_message_id",
- "message_retention_days"
+ "message_retention_days",
+ "date_created",
]
@staticmethod
@@ -1580,6 +1579,9 @@ class Stream(models.Model):
if field_name == "id":
result['stream_id'] = self.id
continue
+ elif field_name == "date_created":
+ result['date_created'] = datetime_to_timestamp(self.date_created)
+ continue
result[field_name] = getattr(self, field_name)
result['is_announcement_only'] = self.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS
return result
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 9a636911c3b..455a8360373 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -4122,6 +4122,10 @@ components:
The short description of the stream in text/markdown format,
intended to be used to prepopulate UI for editing a stream's
description.
+ date_created:
+ type: integer
+ description: |
+ The UNIX timestamp for when the stream was created, in UTC seconds.
invite_only:
type: boolean
description: |
@@ -4223,6 +4227,10 @@ components:
work correctly. And any client-side security logic for
user-generated message content should be applied when displaying
this HTML as though it were the body of a Zulip message.
+ date_created:
+ type: integer
+ description: |
+ The UNIX timestamp for when the stream was created, in UTC seconds.
invite_only:
type: boolean
description: |