-
-
Notifications
You must be signed in to change notification settings - Fork 278
Handle internal PM links #883
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
base: main
Are you sure you want to change the base?
Conversation
Hello @Ezio-Sarthak, it seems like you have referenced #764 in your pull request description, but you have not referenced them in your commit message description(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged. Please run An example of a correctly-formatted commit:
Thank you for your contributions to Zulip! |
e1aa68c
to
bb4d15a
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.
@Ezio-Sarthak I've given this a quick look-over, initially since it was button-related and I moved some tests around. I've not run it yet.
The 'link to this message' code does seem to generate the code you have, but narrow URLs are more flexible than this in general, and other formats may be present in messages due to that. In the webapp itself there are more URL types generated; we may want to check with the server what values to expect. A few others I've come across:
<id>-<bot-name>
(eg. 2414-shiny-bot)<id>-user<id>
(eg. 2406-user2406)
The latter seems like a strange choice (ending with email prefix?), but it's definitely widespread; it's unclear to me why these formats exist in addition to a simple eg. 2406/2414-pm/group. Other than the server source we might search czo for reasons.
tests/ui_tools/test_buttons.py
Outdated
@@ -96,6 +96,20 @@ def test__decode_stream_data(self, stream_data, expected_response): | |||
|
|||
assert return_value == expected_response | |||
|
|||
@pytest.mark.parametrize('pm_data, expected_response', [ | |||
('1,2-pm', dict(recipient_ids=[1, 2], type='pm')), | |||
('1,2-group', dict(recipient_ids=[1, 2], type='group')), |
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 a 1-size group OK? Is pm a synonym for group?
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.
Oops, that needs correction. Thanks for pointing out.
To clarify:
pm
is for 2 people private conversationgroup
is for more than 2 people private conversation
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.
In principle that sounds likely - but pm and group appear to work in both cases on czo!
bb4d15a
to
d9896cb
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.
@Ezio-Sarthak There are some conflicts to be resolved and the TypedDict issue, but otherwise this needs to be broadened to include both non-near and near forms.
With the basic structure in place, we can consider the other forms as a follow-up since we haven't had feedback about this.
d9896cb
to
f838f12
Compare
f838f12
to
3dc6001
Compare
6453d26
to
89afed5
Compare
zulipterminal/ui_tools/buttons.py
Outdated
|
||
# Currently webapp uses `pm` and `group` suffix interchangeably. | ||
# Treat more-than-2 pms to group pms to avoid confusion. | ||
pm_type = 'pm' if len(recipient_ids_list) < 3 else 'group' |
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.
Are we defining pm
and group
properly here?
The URL doesn't include the current-user's user_id
. So, if the length of recipient_ids_list
is 1
the number of persons involved would be 2
(i.e. current-user and another user). This should be called pm
, right?
Similarly, if the length of recipient_ids_list
is >= 2
, then number of persons involved would be 1 + len(recipient_ids_list)
, and this should be called group
?
Correct me if I am wrong, please. :)
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.
You're right! To clarify, the currently exposed formats of url may or may not contain the current user's user_id (manually tested this locally).
I'll add a conditional check to confirm if recipient_ids contain user id, and then calculate length accordingly. That should clear that edge case.
Thanks for poiting that out :)
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.
I think the URL will contain the current user's user_id
only if the user is conversing with himself?
Or, were you able to discover some other edge-case for this while testing?
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.
The Zuilp server has exposed many URL narrow formats as of now (maybe a potential caveat :) ). Try narrowing to a PM by adding your id to the list, you'd still end up narrowing. I discovered that and some more easter eggs during manual testing ;)
7b03b4a
to
7b23aa3
Compare
@Ezio-Sarthak This seems like it would be a fairly straightforward PR to get in, though:
|
c766f8a
to
126ab37
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.
@Ezio-Sarthak Thanks for following up on the internal links work. This works well locally and the changes look good too. 👍 I have left a few minor in-line comments.
zulipterminal/ui_tools/buttons.py
Outdated
recipient_ids_list = list(map(int, recipient_ids.split(","))) | ||
|
||
no_of_recipients = len(recipient_ids_list) | ||
# Bump no. of recipients tp include current user_id if not already |
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.
to*
zulipterminal/ui_tools/buttons.py
Outdated
no_of_recipients = len(recipient_ids_list) | ||
# Bump no. of recipients tp include current user_id if not already | ||
# present | ||
if user_id not in recipient_ids_list: |
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.
What are the cases in which user_id
is included/not included?
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.
Well, the server has some (strange exposed) URL formats, that includes only the id(s) of the recipient(s) other than the current user, e.g.:
- narrow/pm-with/1-user1
- narrow/pm-with/1-bot-name
Those are the ones I'm aware of as of now
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.
The above ones are those that don't have user_id
included. Below are ones that have user_id
included:
- narrow/pm-with/1,2-pm
- narrow/pm-with/1,2-group
- narrow/pm-with/1,2,3-pm
- narrow/pm-with/1,2,3-group
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.
I'll add a note here to refer to the URL formats below in any case 👍
zulipterminal/ui_tools/buttons.py
Outdated
Returns a dict with PM type and IDs of PM recipients. | ||
""" | ||
# Recipient ids (seperated by `,`) are of prime interest. | ||
recipient_ids, *_ = encoded_pm_data.split("-") |
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.
Perhaps recipient_data
or something similar? This way the latter could be recipient_ids
.
126ab37
to
0704275
Compare
0704275
to
e5c9387
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.
@Ezio-Sarthak I am not sure whether your commits were pushed properly. You seem to have reacted positively to my previous comments but the changes aren't present. That said, this continues to work well. I have left some more in-line comments. 👍
"pm_with_bot_exposed_format_1_ordinary", | ||
"pm_with_bot_exposed_format_1_ambigous", | ||
], | ||
) |
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.
There are too many params here in the parametrization. Perhaps a good time to use from pytest import param as case
as used elsewhere in the source, so that it is easier to correlate ids with test cases. :)
tests/ui_tools/test_buttons.py
Outdated
@@ -464,7 +521,7 @@ def test__decode_message_id(self, message_id, expected_return_value): | |||
], | |||
) | |||
def test__parse_narrow_link(self, link, expected_parsed_link): | |||
return_value = MessageLinkButton._parse_narrow_link(link) | |||
return_value = MessageLinkButton._parse_narrow_link(link, 1) |
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.
It is not apparent what 1 is. Perhaps we should mandate keyword args with *
.
@@ -561,13 +574,29 @@ def _switch_narrow_to(self, parsed_link: ParsedNarrowLink) -> None: | |||
topic_name=parsed_link["topic_name"], | |||
contextual_message_id=parsed_link["message_id"], | |||
) | |||
elif "pm-with:near" == narrow: |
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.
We should validate whether the PM links are correct like we do for streams.
zulipterminal/ui_tools/buttons.py
Outdated
@@ -561,13 +574,29 @@ def _switch_narrow_to(self, parsed_link: ParsedNarrowLink) -> None: | |||
topic_name=parsed_link["topic_name"], | |||
contextual_message_id=parsed_link["message_id"], | |||
) | |||
elif "pm-with:near" == narrow: | |||
emails = list( |
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.
It would be cleaner to only keep the narrowing part in the method like other conditionals.
e370475
to
b5e39d8
Compare
031f42e
to
0080312
Compare
This commit adds the helpers: - `_patch_narrow_link` as a general method to patch validated data. This way, explicit patching of stream/pm data is ensured. - `_validate_stream_data` to validate stream data separately in the general `_validate_narrow_link`. Tests added.
This commit adds a static method that decodes necessary information from a PM narrow message link, i.e., the list of PM recipient ids. TypedDict `DecodedPM` is added to return the required structured format of PM data. Currently, there are a bunch of exposed url formats supported by the Zulip server, such as (some seem ambigous too?): narrow/pm-with/1,2-pm narrow/pm-with/1,2-group narrow/pm-with/1,2,3-pm narrow/pm-with/1,2,3-group narrow/pm-with/1-user1 narrow/pm-with/1-bot-name (near parameter supported for each) Tests added.
This commit adds conditional checks in `_parse_narrow_link` to detect PM narrow links. On successful detection, the narrow is switched to the respective PM message via `_switch_narrow_to`. NOTE: A PM narrow can be either "all PMs" (not near) or a "specific PM conversation" (near). Tests added and amended.
0080312
to
6c7719b
Compare
This commit adds validation helper for PM data, in an attempt to avoid and handle any potential exceptions before starting to switch to the PM narrow. The validation checks if all the recipients IDs are valid or not. Tests added and amended.
6c7719b
to
b8fb00f
Compare
[ | ||
case( | ||
"1001,12-pm", | ||
dict(type=None, recipient_ids=[1001, 12], recipient_emails=None), |
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.
Since you type these expected_response
cases as DecodedPM
in the test parameters below, it would be more appropriate to have these as DecodedPM
instances rather than dict
instances (similar to how we have ParsedNarrowLink
instances as parameter cases in the other tests in this file).
Heads up @Ezio-Sarthak, 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 |
This is a follow-up PR from #708. It adds support for handling internal PM links.
I highly appreciate the work of @preetmishra in #708, by which it became simpler and cleaner to work with the helper functions in general :)
Partially fixes #764.