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

Adding user groups to PM recipients typeahead #9978

Closed
wants to merge 2 commits into from

Conversation

synicalsyntax
Copy link
Member

@synicalsyntax synicalsyntax commented Jul 19, 2018

Image from Gyazo

This PR has a series of commits refactoring the compose box typeahead to support user groups in the PM recipient typeahead.

One possible followup is excluding already inserted user groups from the compose box typeahead. Not sure how this would be accomplished though, given we don't insert actual groups but members of the user groups instead, but measures have been taken to exclude inserted users.

Fixes #9971.

@zulipbot
Copy link
Member

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

@@ -97,6 +97,14 @@ function query_matches_user_group_or_stream(query, user_group_or_stream) {
return query_matches_source_attrs(query, user_group_or_stream, ["name", "description"], " ");
}

function query_matches_person_or_data(query, item) {

Choose a reason for hiding this comment

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

Why not name it query_matches_person_or_user_group?

},
updater: function (item) {
compose_pm_pill.set_from_typeahead(item);
if (user_groups.is_user_group(item)) {
item.members.keys().forEach(function (user_id) {

Choose a reason for hiding this comment

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

This can be changed to

item.members.keys()
    .map(toUser)
    .filter(notCurrentUser)
    .forEach(set_from_typeahead)

@synicalsyntax
Copy link
Member Author

@gioragutt Thanks for your feedback! I've updated the PR accordingly.

@synicalsyntax synicalsyntax force-pushed the user-groups-pms branch 2 times, most recently from 99b79eb to 55a66e7 Compare July 19, 2018 19:09
@showell
Copy link
Contributor

showell commented Jul 19, 2018

I tested this pretty thoroughly and it works great!

I'm not sure if all the commits here are completely atomic; we might want to squash them when we push.

I'm also not sure if we prefer lst.forEach(....) to _.each(lst, ...) these days. Most of our code uses _.each, but some of that is a legacy of really old browsers having strange behavior with forEach.

@synicalsyntax
Copy link
Member Author

synicalsyntax commented Jul 19, 2018

@showell Would you prefer that I squish them all into one commit, or are there specific commits that you'd like squashed together?

EDIT: I've went ahead and squished them all into one commit. If there's specific changes you'd like to be separate, let me know please!

appended_names.push(item.full_name);
};

var cleared = false;

Choose a reason for hiding this comment

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

@synicalsyntax

The CI fails due to the cleared variable never been used.
If the cleared value is really not to be used, replace clear_text below with function(){}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching this (don't know why I forgot to commit that line), tests are now passing

@synicalsyntax synicalsyntax force-pushed the user-groups-pms branch 2 times, most recently from 47e289e to 6cd743d Compare July 23, 2018 19:51
@timabbott
Copy link
Sponsor Member

@synicalsyntax this is a nice feature, but the commit history needs some cleanup. Can you split the commits to have a series of preparatory refactoring commits (e.g. extracting the functions to typeahead_helper without changes to the code should be 1 commit per function)? If you do that, then the rest of the PR will be way more readable, since it'll just be the changes implementing the feature.

I think we will want to do the deduplication, as well, but we can talk about strategy for that a bit later, after we merge the preparatory refactors.

@synicalsyntax
Copy link
Member Author

@timabbott I used to have 5 commits for this PR before Steve asked me to squish my commits. Is it possible to restore a previous version of a pull request?

@timabbott
Copy link
Sponsor Member

You should be able to find it locally with git reflog. Read the help for that feature to get a feel for how to use it.

I think Steve's comment was that the 5 commits were not split up properly, which would be an important issue (since reviewing PRs with a commit structure that's kinda broken takes a lot more time to review).

@synicalsyntax synicalsyntax force-pushed the user-groups-pms branch 2 times, most recently from 8a06642 to 1bab817 Compare July 26, 2018 00:06
We use these new functions in the message compose typeahead so that they
can also be used in a PM recipients typeahead with both people and user
groups.
When a user group is selected, we add PM pills for each user in the
group instead of creating a PM pill for the user group.

Fixes zulip#9971.
@showell
Copy link
Contributor

showell commented Jul 26, 2018

@synicalsyntax

Sorry, I did say "squash" although there was a "might" in there, in my defense. I could have been a bit more clear, hope you're able to resurrect stuff without too much trouble.

@timabbott
Copy link
Sponsor Member

Merged, thanks @synicalsyntax! This new commit structure was great.

As a quick follow-up, I think it might be worth having a test for the specific corner case of already having one user in a group in the typeahead and adding a second; I feel like that's one of the more important corner cases here, and I don't see an obvious place where we're testing that.

@timabbott timabbott closed this Jul 26, 2018
@gioragutt
Copy link

@synicalsyntax, or anyone else here for that matter, if you have any git related question, I'm more than willing to answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants