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

model: Improve reporting upon moving/splitting topic. #1178

Conversation

srdeotarse
Copy link
Collaborator

@srdeotarse srdeotarse commented Mar 24, 2022

What does this PR do?
This PR improves reporting upon moving a message by editing it's topic.

Partial fix for #1172

Tested?

  • Manually
  • Existing tests (adapted, if necessary)
  • New tests added (for any new behavior)
  • Passed linting & tests (each commit)

Commit flow

Notes & Questions

Interactions

Visual changes

model.py.-.zulip-terminal.WSL_.Ubuntu.-.Visual.Studio.Code.2022-03-23.21-44-36.mp4

@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from 4d493b5 to a616169 Compare March 24, 2022 13:37
@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Mar 24, 2022
@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from a616169 to a448fab Compare March 24, 2022 13:44
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.

@srdeotarse Thanks for looking at this, including giving the tests a go 👍

This doesn't appear to pass tests (CI), which is not what you have in the PR description.

Since the re-indexing occurs outside the current method where the message occurs, it's possible we may need to do that elsewhere.

if old_topic != new_topic:
self.controller.report_success("You changed a message's topic.")
self.controller.report_success(
f"You changed {no_of_messages} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if we have a standard way to do this using report_success, but this may be clearer if we can provide a highlight style to group the stream+topic in each case.

This may require changes to existing code, so that could be a follow-up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After fixing the format for reporting message upon moving topics, we can look into highlighting as well.

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
@neiljp neiljp added the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Mar 26, 2022
@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from a448fab to f16fbaf Compare March 30, 2022 10:27
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Mar 30, 2022
@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from f16fbaf to 9d1610d Compare March 30, 2022 10:47
@srdeotarse srdeotarse closed this Mar 31, 2022
@srdeotarse srdeotarse deleted the issue-1172-improve-reporting-moving/spliting-topic branch March 31, 2022 17:26
@srdeotarse srdeotarse restored the issue-1172-improve-reporting-moving/spliting-topic branch March 31, 2022 17:29
@srdeotarse srdeotarse deleted the issue-1172-improve-reporting-moving/spliting-topic branch March 31, 2022 17:34
@srdeotarse srdeotarse reopened this Mar 31, 2022
@srdeotarse srdeotarse closed this Mar 31, 2022
@srdeotarse srdeotarse restored the issue-1172-improve-reporting-moving/spliting-topic branch March 31, 2022 18:18
@srdeotarse
Copy link
Collaborator Author

Rebased with current main branch and updated mypy. Still showing error below @neiljp -

Successfully installed autoflake-1.4 autopep8-1.6.0 flake8-4.0.1 isort-5.10.1 jedi-0.18.1 lxml-stubs-0.4.0 mypy-0.942 parso-0.8.3 pudb-2022.1.1 pycodestyle-2.8.0 pyflakes-2.4.0 pytz-2022.1 snakeviz-2.1.1 types-docutils-0.18.0 types-pygments-2.9.17 types-setuptools-57.4.11 zulip-term-0.6.0+git
(zt_venv) srdeotarse@LAPTOP-VC2MC73M:~/zulip-terminal$ make check
================================================================================
Import order (isort)
--------------------------------------------------------------------------------
All files have imports sorted according to rules.
================================================================================
Type consistency (mypy)
--------------------------------------------------------------------------------
Running mypy for `zulipterminal`.
zulipterminal/model.py:584: error: Invalid index type "Optional[int]" for "Dict[int, Set[int]]"; expected type "int"
Found 1 error in 1 file (checked 37 source files)
Running mypy for `tests`.
Success: no issues found in 15 source files
================================================================================
LINTING FAILED
make: *** [makefile:22: lint] Error 1

@srdeotarse srdeotarse reopened this Mar 31, 2022
@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch 2 times, most recently from 4b5095e to 94a3afe Compare April 2, 2022 06:13
@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: XL [Automatic label added by zulipbot] labels Apr 2, 2022
@neiljp
Copy link
Collaborator

neiljp commented Apr 2, 2022

@srdeotarse Was there a reason you closed/reopened this? Generally there's no need to do so.

self.controller.report_success("You changed a message's topic.")
if recent_moved_msgs == "one":
self.controller.report_success(
f"You changed {recent_moved_msgs} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is identical except for the apostrophe placement? If so, it'll be simpler to integrate the difference into the variable, and avoid the need for a conditional here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This was what I referred to by simplifying the code in the next review.

tests/model/test_model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
@@ -888,24 +907,54 @@ def test_update_private_message(
"topic": "party",
},
"lets_party",
"party",
"stream",
"change_all",
True,
),
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the longer test here now, it would be useful to also add inline test ids.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See my followup comment in the next review.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, so you have the case around each set of test parameters; for the ids see other tests which use a named parameter to case (ie. pytest.param), ie. id=some_description).

You might try running this test as it is with -v and using -k to filter this test only, then see what happens when you add an id. What you see there is useful, in addition to it looking a little like a comment for that test parametrization.

@srdeotarse
Copy link
Collaborator Author

@neiljp I was trying to rebase with main to solve mypy error for Optional[int] and accidentally deleted my local branch.

@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from 94a3afe to 5137a37 Compare April 2, 2022 07:11
@srdeotarse srdeotarse changed the title model: Improve reporting upon moving/spliting topic. model: Improve reporting upon moving/splitting topic. Apr 3, 2022
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.

@srdeotarse Thanks for the update 👍

Other than the comments inline, I think we could simplify the code for readability, though it is functional as it is :)

One aspect this brings up is the short time given until the message disappears in the footer. For a simple solution, we could tune this manually with an optional parameter to pass through, which might be warranted as a preparatory commit before the one you have.

I've thought previously we could try to handle this automatically based on word length and reading speed, with some minimum, but that may need more tuning than a simple prep commit.

@@ -834,78 +834,130 @@ def test_update_private_message(
],
)
@pytest.mark.parametrize(
"req, old_topic, footer_updated",
"test_id, req, old_topic, new_topic, stream_name, propagate_mode, footer_updated",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding test ids, I was referring to using pytest.param, which we've been importing as case. This makes description of each parametrized element easier.

zulipterminal/model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from 5137a37 to 42863b0 Compare April 4, 2022 13:04
@neiljp neiljp added enhancement New feature or request area: UI General user interface update area: message rendering labels Apr 6, 2022
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.

@srdeotarse I've mainly focused on the tests here, since once they're well-defined then refactoring the code to give the same behavior should be enforced - and good test-writing technique is a useful skill.

The first commit is good to have separate, but as per my inline comment I'd suggest you keep it very simple to simply allow passing a custom duration in the main commit, with a default of the current 3 as now. The version with a formula is worthy of it's own PR since the implementation is worthy of a separate discussion and this can be merged in the meantime.

tests/model/test_model.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
@@ -888,24 +907,54 @@ def test_update_private_message(
"topic": "party",
},
"lets_party",
"party",
"stream",
"change_all",
True,
),
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, so you have the case around each set of test parameters; for the ids see other tests which use a named parameter to case (ie. pytest.param), ie. id=some_description).

You might try running this test as it is with -v and using -k to filter this test only, then see what happens when you add an id. What you see there is useful, in addition to it looking a little like a comment for that test parametrization.

self.client.update_message.assert_called_once_with(req)
assert result == return_value
self.display_error_if_present.assert_called_once_with(response, self.controller)
report_success = model.controller.report_success
if result and footer_updated:
report_success.assert_called_once_with("You changed a message's topic.")
report_success.assert_called_once_with(expected_report_success)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope you can see how much cleaner this is 👍
The simpler test logic is, the fewer bugs can be in the tests themselves - other than also making them easier to read.
You didn't write this original test, but even so imagine that you looked for this test first, and changed it to specify new behavior first, then updated the code to make it pass (see TDD - test driven development - if you've not come across it). We're wanting to make a specification for the behavior, not write test code that parallels the behavior.

Comment on lines 450 to 452
self.view.set_footer_text(
text, "task:success", float(len(text.split()) * 6 / 13)
) # Average reading speed = 130 wpm
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to see more discussion and explanation of this logic when we do implement this, and we should more broadly apply it to the other report_* methods too. This appears to work for now, but here I'd prefer to go for simpler optional pass-through of a duration to this method for now, which we can iterate on later - ie. an additional named parameter with a default value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're discussing this in the stream now 👍

@srdeotarse srdeotarse force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from 42863b0 to 705c14b Compare April 7, 2022 11:40
@zulipbot zulipbot added size: S [Automatic label added by zulipbot] size: L [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] size: S [Automatic label added by zulipbot] labels Apr 7, 2022
This is useful to ensure there is enough time for long/complex text to
be read before the footer resets.
@neiljp neiljp force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from 11a63fe to a4a882c Compare April 9, 2022 23:50
@neiljp neiljp added this to the Next Release milestone Apr 9, 2022
@neiljp neiljp added PR ready to be merged PR has been reviewed & is ready to be merged and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Apr 9, 2022
@neiljp neiljp force-pushed the issue-1172-improve-reporting-moving/spliting-topic branch from a4a882c to 7196234 Compare April 10, 2022 00:03
@neiljp neiljp merged commit 8db80e8 into zulip:main Apr 10, 2022
neiljp added a commit that referenced this pull request Apr 10, 2022
This slipped out of being included in #1178.

Test updated.
@neiljp
Copy link
Collaborator

neiljp commented Apr 10, 2022

@srdeotarse Thanks for the contribution 👍 I made a few minor textual adjustments which you might be able to identify manually, or find using git diff or git range-diff, I but merged otherwise as-is 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: message rendering area: UI General user interface update enhancement New feature or request PR ready to be merged PR has been reviewed & is ready to be merged size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants