Skip to content
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

streams: Handle adding/removing stream events. #851

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Abhirup-99
Copy link
Contributor

@Abhirup-99 Abhirup-99 commented Dec 15, 2020

Fixes #816

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Abhirup-99 Thanks for giving this a go 👍

There are a few issues with the PR as it stands - how have you tested this? I tried subscribing to a stream in the webapp and the list of streams in ZT doesn't update.

I would recommend checking what the existing code does for subscriptions when they are loaded at startup, ie. any translation of the data, as well as how the stream list is updated and re-rendered in other cases.

Regarding your question in the stream, adding remove events would be good to include in the same PR.

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
@Abhirup-99 Abhirup-99 changed the title streams: Handle adding new stream events. streams: Handle adding/removing new stream events. Dec 17, 2020
@Abhirup-99 Abhirup-99 changed the title streams: Handle adding/removing new stream events. streams: Handle adding/removing stream events. Dec 17, 2020
@Abhirup-99
Copy link
Contributor Author

@neiljp
Sorry, the pr became a bit longer than I had anticipated it to be. This happened because of the addition of the tests, the incoming events from add_stream event is quite large so that primarily contributed to it, also handling of some race around conditions when the user is removed from a stream but is that stream is on view. I disabled some of the keypress events when that condition occurs. Any other thoughts/suggestions would be helpful.

@neiljp neiljp added the PR needs review PR requires feedback to proceed label Dec 19, 2020
@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Dec 19, 2020
@Abhirup-99 Abhirup-99 force-pushed the add_streams_event branch 2 times, most recently from fa2224d to 74e7449 Compare December 19, 2020 12:32
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Abhirup-99 This looks more detailed than the previous version and I can see that it does add and remove streams from the list 👍

The issues I raised earlier are still present however, but I hope my comments will make the color/sorting issues clearer re the addition of streams. We should also ensure other data in the model is updated appropriately, eg. at least muted streams and stream_dict (that I noted so far in this review).

Once you understand the above, you might notice some common duplicated code. It would likely be useful to make a refactoring, extracting the current processing of initial subscriptions (including colors, storing muting state) into an internal method that can process additional streams later too - and would centralize the processing of the data. Possibly we could do another which would handle the StreamData updates, including eg. the sorting. That would likely be better as a preparatory commit (or two) retaining the current behavior but generating methods you can use in the add/remove commits.

It's good to see you covering the removal of streams, but I'd suggest we split the UI warnings into a separate commit; this is important work, but the behavior needs clarifying. For example, while we should limit unnecessary server calls if they're going to fail in any case, I'm not entirely sure if posting/editing to an unsubscribed stream is limited - and maybe other similar aspects too.

tests/model/test_model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Dec 19, 2020
@Abhirup-99 Abhirup-99 force-pushed the add_streams_event branch 3 times, most recently from 7676d3c to 66f45c5 Compare December 22, 2020 14:32
@Abhirup-99
Copy link
Contributor Author

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Jan 1, 2021
@neiljp neiljp removed the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jan 7, 2021
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Abhirup-99 This still works well and the data is updated much more cleanly for the most part 👍

Event handling can often expose challenges with the data model, and this PR shows how we can improve it further. So, we could tidy up what you have a little (updating for at least the muted removal and stream_dict vs StreamData issue), or use some of the new code you have as a basis for quite some refactoring where we combine the generation of the model data from initial_data with how it is updated in these events. Let me know how you want to proceed.

On the basis of the latter being the case, I wanted to get some comments back to you, and have focused mainly on the first commit. Other than one function, you've got some new functions in that commit, but also some that are duplicated from elsewhere, I think? To avoid that duplication it would be great to see commits where when you add those methods for use in the new code, that you remove them from the other place(s) and call the new method. In such 'refactors' we move code around (or otherwise adjust it) so that it can be adapted or reused more easily in a later commit - and when tests don't break after a refactor commit, we hopefully know things are still good too!

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Jan 11, 2021
@neiljp
Copy link
Collaborator

neiljp commented Jan 12, 2021

@Abhirup-99 You replied to some points, but do you want to do some big refactoring first, or go for a simpler version? I know what I'd like to do for the refactoring, but we could get this fixed first.

@Abhirup-99 Abhirup-99 force-pushed the add_streams_event branch 3 times, most recently from 3416297 to 6ab6a7d Compare January 14, 2021 13:54
@Abhirup-99
Copy link
Contributor Author

@zulipbot add "PR needs review".

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Jan 15, 2021
@neiljp neiljp added this to the Release after next milestone Jan 28, 2021
@Abhirup-99 Abhirup-99 force-pushed the add_streams_event branch 8 times, most recently from 6459ef7 to 75a3e75 Compare March 16, 2021 08:02
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@Abhirup-99 I've pushed a slight adjustment of the first refactor commit since it's definitely a solid improvement and foundation for the other work.

There should be less to resolve here now after the few cherry-picks, and while a visual/functional change is maybe not yet evident, I hope you can see the code foundation shifting to make this easier. The challenge is often uncovering the data-structures underneath which need updating first!

zulipterminal/api_types.py Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/core.py Outdated Show resolved Hide resolved
The commit makes _get_stream_by_id class and
make_reduced_stream_data class scoped.
make_reduced_stream_data would be used while
later to initialise data recieved from conftest.py.
This lays the foundation to remove streams without
having to look into pinned and unpinned streams, and
a interface to add/remove streams from ZT.
@zulipbot
Copy link
Member

Heads up @Abhirup-99, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding new stream throws an Keyerror
4 participants