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

[WIP] Handle typing events from multiple users in a PM narrow #1291

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

Conversation

Subhasish-Behera
Copy link
Contributor

@Subhasish-Behera Subhasish-Behera commented Feb 7, 2023

What does this PR do?

Fixes #992

Tested?

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

Commit flow

Notes & Questions

Basically now the controller.active_conversation_info is a set which adds a sender if the event is "start" and removes if the event is "stop".
Reasons for change :-

  1. There seems to be no requirement for Dict as It had only one key -"sender"
  2. in dict , discarding/removing by element name is not possible (but possible in set)

Interactions

Visual changes

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Feb 7, 2023
@zulipbot
Copy link
Member

zulipbot commented Feb 7, 2023

Hello @Subhasish-Behera, it seems like you have referenced #992 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 git commit --amend in your command line client to amend your commit message description with Fixes #992..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

To learn how to write a great commit message, please refer to our guide.

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.

@Subhasish-Behera Thanks for working on this 👍

I've left a little feedback, but I'll follow up in the stream regarding the datastructure point (dict vs set).

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/core.py Outdated Show resolved Hide resolved
zulipterminal/core.py Outdated Show resolved Hide resolved
zulipterminal/core.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 Feb 9, 2023
@Subhasish-Behera Subhasish-Behera changed the title Handle typing events from multiple users in a PM narrow [WIP] Handle typing events from multiple users in a PM narrow Mar 16, 2023
Copy link
Collaborator

@mounilKshah mounilKshah left a comment

Choose a reason for hiding this comment

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

I tried running this PR on my local machine, and it worked well for PMs having 3 users and 2 typing simultaneously.
I had one query. All the tests currently present seem to have only one other user in the pm_with narrow, so test cases for multiple users typing simultaneously are yet to be implemented right?

@Subhasish-Behera
Copy link
Contributor Author

Subhasish-Behera commented Mar 24, 2023

Thanks, for your review and time @mounilKshah. Yep, I haven't committed the new tests.
(currently working on adjusting the tests after the index by user_id refactor as well as the new test.Should be complete soon)

@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Mar 26, 2023
@Subhasish-Behera
Copy link
Contributor Author

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Mar 26, 2023
@neiljp neiljp added missing feature: user A missing feature for all users, present in another Zulip client and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Mar 29, 2023
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.

@Subhasish-Behera This looks to be working fine from a manual test 👍

I left feedback inline. My main thought at this point, having not looked at the topic recently until again now just now, is that the logic would certainly be simpler if we tracked user ids instead of emails. We then have user_name_from_id to avoid diving into the internal model data, which should minimize some of the mocking.

This PR also currently has the commit text directly under the title as you had before, but that should be straightforward since you fixed other PRs already.

sender_name = self.active_conversation_info["sender_name"]
active_conversation_info = ", ".join(
self.model.user_dict[x]["full_name"]
for x in self.active_conversation_info
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should avoid single letter variable names except in extreme situations.

@@ -1381,7 +1381,7 @@ def _handle_typing_event(self, event: Event) -> None:
if (
len(narrow) == 1
and narrow[0][0] == "pm_with"
and sender_email in narrow[0][1].split(",")
and sender_email in list(narrow[0][1].split(", "))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was going to merge this change, since it's a good bugfix for >=3 people in a DM, and the rest of the PR seems to need rebasing. However, I noticed there is no accompanying test yet, so to put it differently: what (new) test case would fail without this code? We should add that to this commit.

Do we need the additional list()?

Since this is a bugfix, you can prepend that to commit title.

Comment on lines 583 to 588
mocker.call(
[
("footer_contrast", "hamlet "),
("footer", " is typing"),
]
),
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 a bit confused why this reformatting was necessary? If you drop the comma after the second list element, does black shrink it back again?

zulipterminal/core.py Show resolved Hide resolved
@@ -1392,7 +1392,8 @@ def _handle_typing_event(self, event: Event) -> None:
controller.show_typing_notification()

elif event["op"] == "stop":
controller.active_conversation_info = {}
sender_email = self.user_dict[sender_email]["email"]
active_conversation_info.discard(sender_email)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This commit doesn't yet add tests for this case, or the output the user sees.

Does the model change along show reasonable improvements? If so, you could add a test change for the model in this commit, and move the core changes into the next commit with the test you added.

),
]
)
elif length < 4:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This conditional should not be present in the test. Instead add a different parameter to the test for what you expect in each case.

{"claudius@zulip.com", "hamlet@zulip.com"},
{"claudius@zulip.com", "hamlet@zulip.com"},
False,
id="in_group_pm_narrow,usertyping:stop_" "while animation in progress",
Copy link
Collaborator

Choose a reason for hiding this comment

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

These ids look confusing.

],
)
def test_show_typing_notification(
self,
mocker: MockerFixture,
controller: Controller,
active_conversation_info: Dict[str, str],
active_conversation_info: Set[Any],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check the types across commits - whether we settle on Set[str] as now or Set[int] for user ids, we shouldn't need to use Any now.

@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 May 13, 2023
Copy link
Member

@prah23 prah23 left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @Subhasish-Behera!

My feedback would be to let active_conversation_info remain a Dict with emails as the keys and full names as the values. This way, the lookup for names in the controller's show_typing_notifications can be pushed to the model and can be performed in place of the line I marked in the comment below.

zulipterminal/model.py Outdated Show resolved Hide resolved
The strict section now matches entries and ordering from mypy --strict.

Other general checking options are extracted into their own sections
according to the order in the mypy --help page, except for those already
in the strict section.

Where the main command-line flag loosens the type-checking, these
options are treated as mypy defaults, and commented in each section.

This commit also starts enforcing the following, which require no
changes to code:
- strict_concatenate [strict]
- truthy-iterable [error-code]
- ignore-without-code [error-code]
- unused-awaitable [error-code]
supascooopa and others added 25 commits October 27, 2023 19:19
The previous commit added a prefix marker for headers of stream
messages; this commit does the same for headers of direct messages.

No symbol was previously defined for direct messages, so one is added,
and applied in a similar way as with stream messages.

Tests updated.
This commit adds a stream_topic_from_message_id method which returns the
topic of the currently focused message. This is done in preparation of
the change in algorithm of the get_next_unread_topic function.

Tests added.
This commit changes the behavior of the get_next_unread_topic method to
use the current message state (ie. the current topic) in calculating the
next unread topic to be cycled to.

If there is no current message available, ie. an empty narrow with no
focus, the logic attempts to use the current narrow to determine the
best course of action.

This replaces the previous approach of using a _last_unread_topic stored
in the model.

Tests updated.
This commit renames the "get_next_unread_topic" function to
"next_unread_topic_from_message_id". This makes the function name
clearer by indicating that the function argument is the context from
which we get the next unread topic.

Tests updated to rename the function.
The next_unread_topic_from_message_id function returns the next topic
to be narrowed to. If the topic remains same, there is no need to call
narrow to the same topic again. This commit fixes this, without any
change in user-facing behavior.

Test case updated.
This commit aims to introduce in-stream wrap-around behavior to the
next_unread_topic_from_message_id function if there are unread messages
still present in the current stream.

Test case added.
This commit shifts test IDs for test__parse_narrow_link() to be inline
with the test cases, and extracts SERVER_URL into the test function
body.
This commit provides support for narrow links in message content
containing 'subject' instead of 'topic', which may be present in
messages before server version 2.1.0.

Test cases added.

Fixes zulip#1422.
Minor change to reduce confusion between values of different ids in test
cases and ensure they are kept distinct for testing purposes.
This picks out O_WRONLY as a misspelling, but this version of typos
allows configuration in pyproject.toml, so exclude it there.
This is achieved through a new method associate_stream_with_topic in the
View, which saves to a new internal dict.

This will support later restoring the topic position in the UI.

Since the topic list may be reordered between saving and restoring the
state, the current index in the topic list is insufficient; the name of
the topic is used intead.
Information regarding the previous position in the topic list for the
matching stream is retrieved from the View and used to set the initial
focus.

A new accessor in the View, saved_topic_in_stream_id, returns the most
recent (saved) topic name. In the absence of a previous value this
returns None.

A new internal TopicsView helper method returns the focus (index) which
corresponds to the saved topic name for the related stream. If there is
no saved state or no matching topic name, it returns the top index (0),
which was the previous behavior. This is isolated as a method to
facilitate testing.

Combined, this restores any previous topic-name state by assigning to
the focus position.

Test added for the internal helper method
_focus_position_for_topic_name.
This commit introduces the sort_unread_topics function to the
next_unread_topic_from_message_id method to sort unread_topics
instead of sorting it in the model.

This replaces the use of bisect since the sorting behavior
changes due to the change in the sort_unread_topics function.
The caveat for this replacement is that the sort is performed
again.

This commit serves as a preparatory commit for the change in
sorting behavior in the next commit.

Test added.
This commit changes the sort_unread_topics method in helper.py
to use the left stream panel ordering to sort the unread data
instead of implicitly using the stream id as key.

Tests updated & extended.
The 'Mentioned messages' and 'Starred messages' symbols are set to ASCII
characters, similar to those in the Zulip web app.

The selected 'All messages' symbol is the closest match found after some
testing, and appears to be available fairly widely. An appropriate
descriptive comment is added, as with other non-ASCII symbols, for later
reference.
This commit adds prefix symbols to the main buttons in the top left
corner of the UI. This aims to make the main buttons stand out more and
approximate the designs used in the web app.

This change also leads to a cleaner design, since these top buttons are
now indented and aligned similarly to the panels beneath them, eg. the
list of streams.

The symbol used as a prefix in headers of direct messages is reused for
the 'Direct messages' button, with other buttons using symbols added in
the previous commit.

The left part of the UI is increased in width to accommodate the new
additions.

Note that the "title" style is used to make the icons bolder, though
this should be decoupled in future.
Pygments 2.16.0 introduced a style to support a combination of bold and
italic styling in pygments/pygments#2444. Both of our gruvbox themes and
the light native theme gain a 'bold strong' style via pygments as a
result, which urwid fails to parse and blocks the application from
loading.

Longer-term we should improve the pygments to urwid translation logic to
allow these styles to work and an upgrade to later pygments versions,
but for now this allows these themes to continue working as before.

Fixes zulip#1431.
The active_converstation_information is a Dict where id of the users is
the key and the full_name of the user is the value.
Previously the indexing was done by name which is changed
to id now because of the possibility of non-unique names
present in the active_conversation_info.
In core.py active_conversation_info gets the full_names of the emails
 present in self.active_conversation_info's values.
Add a single user and remove a single user on typing event.
Previously removing means emptying the dict as dict would contain
a single user.But now removing means discarding a specfic id.
In core.py diffrent cases of footer are made depending on no of active
user.
In test_core, the test now has it's own user_dict which is
used to extract name for footer notifcation out of emails
present in active_conversation_info.
In test_model,added a new parameter of current active_conversation_info.
Add diffrernt cases of footer notification.Earlier
just one test was presnt as not much scenarios were
possible.
@zulipbot
Copy link
Member

zulipbot commented Nov 6, 2023

Heads up @Subhasish-Behera, we just merged some commits that conflict with the changes you 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
area: typing notifications has conflicts missing feature: user A missing feature for all users, present in another Zulip client PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle typing events from multiple users in a PM narrow
9 participants