mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
streams: Pass stream_weekly_traffic field in stream objects.
This commit adds code to pass stream traffic data using the "stream_weekly_traffic" field in stream objects. We already include the traffic data in Subscription objects, but the traffic data does not depend on the user to stream relationship and is stream-only information, so it's better to include it in Stream objects. We may remove the traffic data and other stream information fields for Subscription objects in future. This will help clients to correctly display the stream traffic data in case where client receives a stream creation event and no subscription event, for an already existing stream which the user did not have access to before.
This commit is contained in:
@@ -58,6 +58,7 @@ from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_partial_success, json_success
|
||||
from zerver.lib.retention import STREAM_MESSAGE_BATCH_SIZE as RETENTION_STREAM_MESSAGE_BATCH_SIZE
|
||||
from zerver.lib.retention import parse_message_retention_days
|
||||
from zerver.lib.stream_traffic import get_streams_traffic
|
||||
from zerver.lib.streams import (
|
||||
StreamDict,
|
||||
access_default_stream_group_by_id,
|
||||
@@ -874,7 +875,12 @@ def get_stream_backend(
|
||||
stream_id: int,
|
||||
) -> HttpResponse:
|
||||
(stream, sub) = access_stream_by_id(user_profile, stream_id, allow_realm_admin=True)
|
||||
return json_success(request, data={"stream": stream_to_dict(stream)})
|
||||
|
||||
recent_traffic = None
|
||||
if not user_profile.realm.is_zephyr_mirror_realm:
|
||||
# We do not need stream traffic data in zephyr mirroring realm.
|
||||
recent_traffic = get_streams_traffic({stream.id})
|
||||
return json_success(request, data={"stream": stream_to_dict(stream, recent_traffic)})
|
||||
|
||||
|
||||
@has_request_variables
|
||||
|
||||
Reference in New Issue
Block a user