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

notifications: Correctly stringify pmUsers to fix navigation to group… #3922

Merged
merged 3 commits into from
Oct 28, 2020

Conversation

chrisbobbe
Copy link
Contributor

… PMs.

Navigation to a group PM on pressing a notification was broken
because pmUsers was incorrectly stringified in
GroupPm.getPmUsersString. Fix, and add a test for it.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks @chrisbobbe for spotting this! Will be glad to get this bug fixed. 🙂

Looking again at the output, I'd like to take one further step to tighten up the format; see below.

@Test
fun `GroupPm#getPmUsersString gives the correct string`() {
expect.that(Recipient.GroupPm(pmUsers = setOf(123, 234, 345)).getPmUsersString())
.isEqualTo("123, 234, 345")
Copy link
Member

Choose a reason for hiding this comment

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

Let's eliminate the spaces too.

If this already is enough that the JS code understands it, that's good :) -- but the format used elsewhere is purely comma-separated, so may as well make it consistent.

Comment on lines 62 to 65
fun `GroupPm#getPmUsersString correctly reorders user ids`() {
expect.that(Recipient.GroupPm(pmUsers = setOf(234, 123, 345)).getPmUsersString())
.isEqualTo("123, 234, 345")
}
Copy link
Member

Choose a reason for hiding this comment

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

This test can be made a bit stronger by testing that e.g. 123 sorts after 23 -- i.e. the sorting is of the numbers, and not a lexicographic sort of their ASCII representations.

@chrisbobbe
Copy link
Contributor Author

OK, I've pushed these changes. :)

@chrisbobbe
Copy link
Contributor Author

I'm resolving merge conflicts and clarifying a commit message for this now. ("Incorrectly stringified" is vague; I'm tracking down what exactly the output was, which I should have done in the first place.)

@chrisbobbe chrisbobbe force-pushed the pr-fix-group-pm-notif-nav branch 2 times, most recently from 9093d0d to 8153f84 Compare March 9, 2020 23:21
Chris Bobbe added 3 commits October 28, 2020 15:01
… PMs.

Navigation to a group PM on pressing a notification was broken because
pmUsers was incorrectly stringified in GroupPm.getPmUsersString.

E.g., for a group PM among user IDs 13313, 13434, and 13657, it would
stringify to (newline added for readability):

"GroupPm(pmUsers=[13313, 13434, 13657]), GroupPm(pmUsers=[13313,
 13434, 13657]), GroupPm(pmUsers=[13313, 13434, 13657])"

It should instead stringify to "13313, 13434, 13657". (Later in this
series of commits, we remove the space.)

Fix and add a test.
To be reverted in the next commit.

In the previous commit, we changed the return value of
GroupPm.getPmUsersString in our Kotlin code from garbage separated
by ', ' to numbers separated by ', '. This commit aims to prove that
', '-separated numbers will be handled correctly, at least as far as
our tests can tell.

But we really want it to be ','-separated (no space), which we do in
the next commit.
', ' would have been handled correctly, but seemingly by accident;
in getNarrowFromNotificationData, pm_users was split on ',' to give
['1', ' 2', ' 3'] (note the spaces), then each element of that array
was converted to a number.

Also, replace the confusing + syntax, as in +idStrs[i], with parseInt.
@gnprice gnprice merged commit 766dcdd into zulip:master Oct 28, 2020
@gnprice
Copy link
Member

gnprice commented Oct 28, 2020

Merged! Thanks again. Just made small tweaks to the commit messages.

Evidently I dropped this PR back in March, oops. >_> Looks like it probably got lost in the chaos of all suddenly switching to work from home, early in the pandemic. I ran across the bug today, it looked familiar, and I found this PR again.

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.

2 participants