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:
Sahil Batra
2023-07-27 20:12:21 +05:30
committed by Tim Abbott
parent 261fca11ec
commit ae72151ec1
15 changed files with 176 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
from typing import List, Set
from zerver.lib.types import APIStreamDict
from zerver.lib.types import DefaultStreamDict
from zerver.models import DefaultStream, Stream
@@ -22,7 +22,7 @@ def get_default_stream_ids_for_realm(realm_id: int) -> Set[int]:
return set(DefaultStream.objects.filter(realm_id=realm_id).values_list("stream_id", flat=True))
def get_default_streams_for_realm_as_dicts(realm_id: int) -> List[APIStreamDict]:
def get_default_streams_for_realm_as_dicts(realm_id: int) -> List[DefaultStreamDict]:
"""
Return all the default streams for a realm using a list of dictionaries sorted
by stream name.