Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
80e3344
model/api_types: Add data structures to support non-subscribed streams.
theViz343 May 31, 2023
82ed222
model: Add stream id accessor methods.
theViz343 Jun 6, 2023
d1a8eb7
refactor: model: Use get_stream_name instead of stream_dict.
theViz343 Jun 6, 2023
b51eae4
refactor: model/views: Use get_stream_subscribers instead of stream_d…
theViz343 Jun 6, 2023
80e0d5a
refactor: model: Use stream_date_created (get/set)ter methods.
theViz343 Jun 6, 2023
b6ab397
refactor: model: Use is_stream_web_public instead of stream_dict.
theViz343 Jun 6, 2023
55d8560
refactor: model: Use stream_message_retention_days (get/set)ter methods.
theViz343 Jun 6, 2023
023ea38
refactor: model: Use is_stream_invite_only instead of stream_dict.
theViz343 Jun 6, 2023
6282150
refactor: model/views: Use get_stream_post_policy accessor method.
theViz343 Jun 10, 2023
71d5bd0
refactor: model/views: Use is_stream_announcement_only accessor method.
theViz343 Jun 10, 2023
6a67577
refactor: model/views: Use is_stream_history_public_to_subscribers me…
theViz343 Jun 10, 2023
f451244
refactor: model/views: Use get_stream_weekly_traffic method.
theViz343 Jun 10, 2023
8d6e057
refactor: model/views: Use get_stream_rendered_description method.
theViz343 Jun 10, 2023
5e5bd20
model: Add get_all_subscription_ids accessor method.
theViz343 Jun 6, 2023
dee7e2b
refactor: model: Use get_subscription_color instead of stream_dict.
theViz343 Jun 6, 2023
e39bbe3
refactor: model/views: Use get_subscription_email instead of stream_d…
theViz343 Jun 10, 2023
5ca5ee6
refactor: model: Improve stream_dict typing.
theViz343 Jun 15, 2023
308fa13
refactor: model: Rename stream_dict to _subscribed_streams.
theViz343 Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,46 @@ def test_is_stream_invite_only(
assert model.is_stream_invite_only(stream_id) == expected_value
model._get_stream_from_id.assert_called_once()

@pytest.mark.parametrize(
"stream_id, to_vary, expected_value",
[
case(
1000,
{},
None,
),
case(
3,
{
"stream_post_policy": 1,
},
1,
),
case(
5,
{
"stream_post_policy": 3,
},
3,
),
],
)
def test_get_stream_post_policy(
self,
model,
mocker,
get_stream_from_id_fixture,
stream_id,
to_vary,
expected_value,
):
get_stream_from_id_fixture.update(to_vary)
mocker.patch(
MODEL + "._get_stream_from_id", return_value=get_stream_from_id_fixture
)
assert model.get_stream_post_policy(stream_id) == expected_value
model._get_stream_from_id.assert_called_once()

@pytest.mark.parametrize("muted", powerset([99, 1000]))
@pytest.mark.parametrize("visual_notification_enabled", powerset([99, 1000]))
def test__subscribe_to_streams(
Expand Down
6 changes: 6 additions & 0 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,9 @@ def mock_external_classes(
self.controller.model.cached_retention_text = {self.stream_id: "10"}

self.controller.model.stream_dict = {self.stream_id: general_stream}
self.controller.model.get_stream_post_policy.return_value = general_stream.get(
"stream_post_policy"
)
self.controller.model.stream_access_type.return_value = "public"
self.controller.model.get_stream_subscribers.return_value = general_stream[
"subscribers"
Expand Down Expand Up @@ -1300,6 +1303,9 @@ def test_popup_height(
model.get_stream_date_created.return_value = to_vary_in_stream_data[
"date_created"
]
model.get_stream_post_policy.return_value = to_vary_in_stream_data.get(
"stream_post_policy"
)
model.cached_retention_text = {stream_id: cached_message_retention_text}
model.server_feature_level = server_feature_level

Expand Down
3 changes: 3 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,9 @@ def set_stream_message_retention_days(
def is_stream_invite_only(self, stream_id: int) -> bool:
return self._get_stream_from_id(stream_id)["invite_only"]

def get_stream_post_policy(self, stream_id: int) -> Optional[int]:
return self._get_stream_from_id(stream_id).get("stream_post_policy")

def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
def make_reduced_stream_data(stream: Subscription) -> StreamData:
# stream_id has been changed to id.
Expand Down
6 changes: 4 additions & 2 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,10 @@ def __init__(self, controller: Any, stream_id: int) -> None:
)
]

if "stream_post_policy" in stream:
stream_policy = STREAM_POST_POLICY[stream["stream_post_policy"]]
if controller.model.get_stream_post_policy(self.stream_id):
stream_policy = STREAM_POST_POLICY[
controller.model.get_stream_post_policy(self.stream_id)
]
else:
if stream.get("is_announcement_only"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This existing UI code incorporates implicit checking of the server version, which would be better wrapped into the model under get_stream_post_policy, rather than the two functions introduced in this commit and the next.

stream_policy = STREAM_POST_POLICY[2]
Expand Down