-
-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for all streams (more general accessor methods) #1419
base: main
Are you sure you want to change the base?
Conversation
Hello @theViz343, it seems like you have referenced #816 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage. Please run An example of a correctly-formatted commit:
To learn how to write a great commit message, please refer to our guide. |
b6b236a
to
c444254
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theViz343 This has the potential to be simpler than the other PR, though I'm a little concerned over if you may end up with typing issues?
@@ -244,6 +233,21 @@ class Subscription(TypedDict): | |||
# in_home_view: bool # Replaced by is_muted in Zulip 2.1; still present in updates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the other PR, note that this is the successor to is_muted
, so should move too.
@@ -243,21 +244,26 @@ def general_stream() -> Dict[str, Any]: | |||
"audible_notifications": False, | |||
"description": "General Stream", | |||
"rendered_description": "General Stream", | |||
"is_old_stream": True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting why these removals are safe in the commit message.
controller.model.stream_dict = { | ||
stream_id: { | ||
stream_id: general_stream, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change strictly required/enforced by the new typing of stream_dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the new typing makes it so that each item in the stream_dict has to be of the Subscription Typeddict type.
205: general_stream, | ||
} | ||
controller.model.stream_dict[205].update( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a reasonable commit to use a fixed index via a variable, as in the other tests?
tests/conftest.py
Outdated
@@ -1453,7 +1509,7 @@ def user_id(logged_on_user: Dict[str, Any]) -> int: | |||
|
|||
|
|||
@pytest.fixture | |||
def stream_dict(streams_fixture: List[Subscription]) -> Dict[int, Subscription]: | |||
def stream_dict(streams_fixture: List[Dict[str, Any]]) -> Dict[int, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidental revert?
def stream_property( | ||
self, stream_id: int, property: STREAM_KEYS | ||
) -> Optional[Union[int, str, bool, List[int]]]: | ||
return self._get_stream_from_id(stream_id)[property] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How well does this approach work in practice? Does this lead to typing errors, since somehow one has to map the result types to the property names?
c444254
to
d0068ff
Compare
This commit creates data structures, similar to stream_dict, to support unsubscribed and never-subscribed streams. These streams are available in the fetched initial data which is used to populate the new data structures using the _register_non_subscribed_streams function.
This commit updates the `date_created` and `role` fields present in the Stream and Subscription typeddicts respectively. For `date_created`, since servers with ZFL<30 do not include the field, but ZT does add it with a value of None to ensure consistency, the type is changed to `NotRequired[Optional[int]]`. For `role`, the field has been removed in Zulip 6.0 (ZFL 133), so it has been removed from the Subscriptions typeddict.
With the revamp of the Subscription TypedDict in an earlier commit, we use it to improve the typing of stream_dict in this commit. Tests and fixtures updated to support the new typing.
This commit adds two helper methods - _get_stream_from_id and _get_all_stream_ids. These two helper methods help in preparation for adding stream and subscription property accessor methods in the next commit. Tests added.
This commit adds stream and subscription property accessor functions to limit the mutability of stream/subscription properties where it is not needed.
This commit replaces the direct use of stream_dict to access the 'name' property, with the stream accessor function introduced in the earlier commit. Since the new stream accessor function accesses subscribed streams, was subscribed streams and never-subscribed stream, the keyerror issue described in issue zulip#816 is resolved.
d0068ff
to
aa051b3
Compare
What does this PR do, and why?
This PR adds support for unsubscribed streams and never_subscribed streams in ZT. It creates new data structures and general accessor methods to access them. This PR is needed for further work on reducing stream related issues and adding support for stream (un)subscription.
This PR is based heavily on the initial commits of #1408 with some slight changes and the generalization of the accessor methods.
Outstanding aspect(s)
External discussion & connections
Adding streams throws key error
How did you test this?
Self-review checklist for each commit
Visual changes