Skip to content

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

Merged
gnprice merged 3 commits intozulip:masterfrom
chrisbobbe:pr-fix-group-pm-notif-nav
Oct 28, 2020
Merged

notifications: Correctly stringify pmUsers to fix navigation to group…#3922
gnprice merged 3 commits intozulip:masterfrom
chrisbobbe:pr-fix-group-pm-notif-nav

Conversation

@chrisbobbe
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 chrisbobbe force-pushed the pr-fix-group-pm-notif-nav branch from 03b9f22 to 8d869d5 Compare February 21, 2020 21:56
@chrisbobbe
Copy link
Copy Markdown
Contributor Author

OK, I've pushed these changes. :)

@chrisbobbe chrisbobbe force-pushed the pr-fix-group-pm-notif-nav branch from 8d869d5 to 92bee0e Compare February 21, 2020 22:00
@chrisbobbe
Copy link
Copy Markdown
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
@gnprice gnprice force-pushed the pr-fix-group-pm-notif-nav branch from 8153f84 to 4dc39d1 Compare October 28, 2020 22:01
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 force-pushed the pr-fix-group-pm-notif-nav branch from 4dc39d1 to 766dcdd Compare October 28, 2020 22:02
@gnprice gnprice merged commit 766dcdd into zulip:master Oct 28, 2020
@gnprice
Copy link
Copy Markdown
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