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

Use user_ids as message destinations #1006

Merged
merged 4 commits into from
Aug 11, 2021

Conversation

prah23
Copy link
Member

@prah23 prah23 commented Apr 21, 2021

There are 4 commits to this PR:

  • The first commit refactors update_recipient_emails() to update_recipients(), also updating the recipients' user_ids now, which is a preparatory step for the third commit. A test has also been added for this method.
  • The second commit adds a test fixture for user_id_email_dict as a prep commit for the third commit.
  • The third commit migrates from using delivery emails as message destinations to using user_ids instead. Tests updated.
  • The fourth commit deprecates the emails parameter from private_box_view(). Tests updated.

The abstraction between the narrow model and the Composition API type is maintained by modifying the corresponding connections to the narrow model such that the delivery emails are still in use in the narrow model currently, making this a message-destination-only change.

This change also serves as a prelude to the larger scale narrow model refactoring, which needs Model and narrow structure abstraction.

This would accommodate the first point under #965.

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Apr 21, 2021
@prah23 prah23 force-pushed the refactor_message_destination branch from eb6f2da to 55a2920 Compare June 9, 2021 13:53
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Jun 9, 2021
@prah23 prah23 added the PR needs review PR requires feedback to proceed label Jun 9, 2021
Copy link
Member

@preetmishra preetmishra left a comment

Choose a reason for hiding this comment

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

@prah23 Thanks for taking this up. This seems to work well and the changes look good to me as well! 👍

With user_ids in place and given that we could build back recipient_emails from the user_ids, should we drop the recipient_email attribute in boxes.py?

We could potentially squash the changes pre-merge. I have left a few minor in-line comments.

tests/ui_tools/test_boxes.py Outdated Show resolved Hide resolved
tests/ui_tools/test_boxes.py Show resolved Hide resolved
@preetmishra preetmishra 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 Jun 9, 2021
@prah23 prah23 force-pushed the refactor_message_destination branch 3 times, most recently from 829d629 to ccd8ef1 Compare June 9, 2021 22:24
@prah23
Copy link
Member Author

prah23 commented Jun 9, 2021

Thanks for the review, and the educative point about the AAA pattern, @preetmishra!
I've incorporated your suggestions and have added a 4th commit deprecating the emails parameter from private_box_view.

@prah23 prah23 added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jun 9, 2021
Copy link
Member

@preetmishra preetmishra left a comment

Choose a reason for hiding this comment

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

@prah23 Thanks for the update! The last commit is a good cleanup. We could label it as a refactor:. Overall, the PR looks good to me! 👍

There are two concerns that I would like to point out:

  • When opening a saved draft with an invalid user email, the To: field renders empty.
  • When sending a PM to an invalid recipient, the footer message gets updated to "Cannot send message without specifying recipients." than "Invalid recipient(s) - ...".

This is likely because you're skipping out invalid emails while creating the user_ids from the regex grepped emails in update_recipients().

tests/ui_tools/test_boxes.py Show resolved Hide resolved
@preetmishra preetmishra 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 Jun 12, 2021
@prah23 prah23 force-pushed the refactor_message_destination branch from ccd8ef1 to 8826323 Compare June 16, 2021 20:44
@prah23 prah23 force-pushed the refactor_message_destination branch 2 times, most recently from 4ef125d to 39acc15 Compare July 5, 2021 21:15
@prah23 prah23 added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jul 5, 2021
@prah23
Copy link
Member Author

prah23 commented Jul 5, 2021

This PR is now up-to-date @preetmishra.

Thanks to #937, both of your concerns should no longer persist since we restrict the user from sending a message and saving a draft too if the recipients are invalid. Only if the recipients are valid, they will be updated in self.recipient_user_ids and self.recipient_emails and then the relevant action will proceed.

@prah23 prah23 force-pushed the refactor_message_destination branch from 39acc15 to 34ae36b Compare July 5, 2021 21:21
Copy link
Member Author

@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.

I've made a couple of changes since the #937 merge, I'm leaving my thoughts on these below, please let me know if you think they need changes.

tests/ui_tools/test_boxes.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/boxes.py Outdated Show resolved Hide resolved
@prah23 prah23 force-pushed the refactor_message_destination branch from 34ae36b to 355e526 Compare July 5, 2021 21:31
Copy link
Member

@preetmishra preetmishra left a comment

Choose a reason for hiding this comment

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

@prah23 Thanks for carrying this forward and resolving the issues that were related elsewhere! 👍 This works well locally.

@neiljp Other than the minor in-line comments, this looks good to me.

tests/ui_tools/test_boxes.py Show resolved Hide resolved
tests/ui_tools/test_boxes.py Outdated Show resolved Hide resolved
tests/helper/test_helper.py Show resolved Hide resolved
@preetmishra preetmishra 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 Jul 11, 2021
@prah23 prah23 force-pushed the refactor_message_destination branch from 355e526 to d1a7418 Compare July 13, 2021 22:13
@prah23
Copy link
Member Author

prah23 commented Jul 13, 2021

Thanks for the reviews, @preetmishra!
Updated as per review.

@prah23 prah23 added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jul 13, 2021
@prah23 prah23 force-pushed the refactor_message_destination branch from d1a7418 to 7361354 Compare July 30, 2021 14:16
@prah23 prah23 force-pushed the refactor_message_destination branch from 7361354 to 493eaf2 Compare August 6, 2021 13:06
@prah23 prah23 force-pushed the refactor_message_destination branch from 493eaf2 to 06ca8cf Compare August 6, 2021 13:13
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

prah23 added 4 commits August 10, 2021 23:27
Prior to this commit, we updated only `recipient_emails` using the
update_recipient_emails() method post changes in the private_box_view
header. This was because delivery emails were used as message
destinations and needed updating before performing a message-related
action.

This commit modifies this method to also update the recipients'
user_ids, maintaining synchrony between the recipient email and
user_id lists.

Tests added.
This is a preparatory commit that adds a fixture for model's
user_id_email_dict to facilitate using the dict in multiple tests
that need to look an email up given the user_id.
This commit migrates from using delivery emails as message destinations
to using `user_id`s instead. The abstraction between the narrow model
and the Composition API type is maintained by modifying the corresponding
connections to the narrow model such that the delivery emails are still
in use in the narrow model currently, making this a message-destination-only
change.

The commit focuses on changing the type of the `recipients` parameter of
the PrivateComposition class to List[int] instead of the previous
List[str]. `send_private_message` now expects a List of `int`s as well.

Tests updated.
Prior to this commit, everytime the private_box_view had to be initiated
with recipients, the emails of the recipients was also requested along
with their user_ids. This commit removes that parameter and hence
makes the private_box_view reliant on only the list of `user_id`s
received.

Tests updated.
@neiljp neiljp force-pushed the refactor_message_destination branch from 06ca8cf to c712469 Compare August 11, 2021 06:31
@neiljp
Copy link
Collaborator

neiljp commented Aug 11, 2021

@prah23 I made a minor test change and commit text change and am merging this now - thanks! 🎉

Other than the ongoing migration towards ids and improving the narrow structure, I expect we'll want to wrap the access to the user_id_email_dict with a method, but this refactoring is useful to have right now and we can build on this 👍

@neiljp neiljp merged commit b4c4635 into zulip:main Aug 11, 2021
@neiljp neiljp added api migrations and removed PR needs review PR requires feedback to proceed labels Aug 11, 2021
@neiljp neiljp added this to the Next Release milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants