Skip to content

recipient [nfc]: Clean up and document how we compute unread_msgs keys.#4040

Merged
rk-for-zulip merged 6 commits intozulip:masterfrom
gnprice:pm-recipients-unread
Apr 21, 2020
Merged

recipient [nfc]: Clean up and document how we compute unread_msgs keys.#4040
rk-for-zulip merged 6 commits intozulip:masterfrom
gnprice:pm-recipients-unread

Conversation

@gnprice
Copy link
Copy Markdown
Member

@gnprice gnprice commented Apr 15, 2020

This is part of #4035, specifically the main part of it that's blocking #3535.

We have a function getRecipientsIds whose real meaning is that it computes the key to use to look up a PM conversation in our unread state-subtree, derived from the unread_msgs data structure from the server. This series gives it a more meaningful name, pmUnreadsKeyFromMessage; adds jsdoc and comments; and cleans up the interface and implementation a bit, including by switching from emails to user IDs (a case of #3764).

@rk-for-zulip
Copy link
Copy Markdown
Contributor

Tests are failing. (You may just need to rebase.)

gnprice added 5 commits April 16, 2020 10:56
Though the name of this function doesn't yet say so, it's really all
about navigating the `unread` state subtree we maintain from the
server's `unread_msgs` data structure.

Perhaps that's why it hadn't taken account of the possibility of a
self-1:1 appearing -- such a message has to be *sent* by oneself, so
it's a bit of a surprising edge case that it can be unread.  But it
can, if e.g. you send yourself a PM through the API.

Or perhaps the reason is that the code already worked in that case!
This change just makes that more explicit, rather than seeming like
an accident.
This will let us switch to passing one of these helpers a user ID
in the next commit.

Also fill in some missing pieces of data in these ill-typed tests,
without which they start failing.
@gnprice gnprice force-pushed the pm-recipients-unread branch from 4df4644 to 8998aec Compare April 16, 2020 18:20
@gnprice gnprice closed this Apr 16, 2020
@gnprice gnprice reopened this Apr 16, 2020
@gnprice
Copy link
Copy Markdown
Member Author

gnprice commented Apr 16, 2020

Thanks, fixed. The issue was some ill-typed tests that didn't have the needed bit of the Redux state tree.

(And the closing and reopening of the PR just now were because I went to click on the add-comment text box to focus it for typing... and then it jumped around as the "checks failed" box changed because I'd just pushed the branch, and the "Close pull request" button popped under my cursor instead.)

Not that we would _intentionally_ sort this lexicographically -- but
it's an easy trap to fall into with `Array.prototype.sort`, and it's
probably worth noting that we didn't.
Copy link
Copy Markdown
Contributor

@rk-for-zulip rk-for-zulip left a comment

Choose a reason for hiding this comment

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

Adverb added (in a trivial follow-on commit). Merging!

Comment thread src/utils/recipient.js Outdated
Comment on lines +95 to +96
* @param ownEmail - Required if the message could be a 1:1 PM; optional if
* it is definitely a group PM.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yuck. I think this should really be always-required, just for sanity's sake. (Which would have been trivially possible before this PR, but would be more involved afterward.)

Not that I'm saying this PR should be delayed for that – just noting it as follow-up work under #3764 (converting EventNewMessageAction's ownEmail: to ownUserId: or ownUser:).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, agreed

Comment thread src/utils/recipient.js Outdated
*/
// Specifically, this includes all user IDs for group PMs and self-PMs,
// and just the other user ID for non-self 1:1s; and in each case the list
// is sorted and encoded in ASCII-decimal, comma-separated.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Sorted" should probably specify "numerically" (as opposed to "lexicographically").

I hate that I can say that with a straight face, but it is what it is. 😞

@rk-for-zulip rk-for-zulip merged commit a111cfc into zulip:master Apr 21, 2020
@gnprice gnprice deleted the pm-recipients-unread branch April 21, 2020 22:00
@gnprice
Copy link
Copy Markdown
Member Author

gnprice commented Apr 21, 2020

Thanks for the review!

rk-for-zulip added a commit that referenced this pull request Apr 27, 2020
This reverts the following commits (which constitute PR #4040):
 * a111cfc
 * d8f4512
 * d464e33
 * 79c8671
 * 423cd19
 * 2a2a2e1

Commit 79c8671 introduced a crash bug. `getOwnUser` relies on the
presence of the user database which is provided by REALM_INIT, but
it's being called as part of the instantiation of `UnreadCards` before
REALM_INIT occurs.
@rk-for-zulip
Copy link
Copy Markdown
Contributor

rk-for-zulip commented Apr 27, 2020

... and, of course, now I see that there was a "Revert" button right there. (I swear I looked for it.)

At any rate, as noted in the commit message, this caused a crash:

getOwnUser relies on the presence of the user database which is provided by REALM_INIT, but it's being called as part of the instantiation of UnreadCards before REALM_INIT occurs.

It can be reproduced as follows:

  1. adb uninstall com.zulipmobile.debug
  2. yarn react-native run-android
  3. Try to log in to any Zulip server.

(I don't appear to have the option to reopen this PR, alas. Do you?)

@gnprice gnprice restored the pm-recipients-unread branch April 29, 2020 00:06
@gnprice gnprice deleted the pm-recipients-unread branch April 29, 2020 00:06
@gnprice
Copy link
Copy Markdown
Member Author

gnprice commented Apr 29, 2020

(I don't appear to have the option to reopen this PR, alas. Do you?)

Nope -- I tried putting the branch back (there's a button for that, even:
image
but still didn't have an option to reopen.

Not sure I can even disagree with that product choice, as it's a fact that the PR was merged, even if there's a revert commit after it. I'll make a new PR for a revised version.

gnprice added a commit that referenced this pull request Apr 29, 2020
The commit 084d726 "pms / recipient: Revert PR #4040."
reverted a series of 6 earlier commits:

  a111cfc recipient [nfc]: Add minor documentation clarification.
  d8f4512 recipient [nfc]: Simplify pmUnreadsKeyFromMessage a bit.
  d464e33 recipient [nfc]: Stop using email in pmUnreadsKeyFromMessage.
  79c8671 pm-conversations [nfc]: Get ownUser rather than just ownEmail.
  423cd19 unread [nfc]: Give getRecipientsIds a more informative name, and some jsdoc.
  2a2a2e1 unread [nfc]: Handle self-1:1 thread explicitly in getRecipientsIds.

But the bug being addressed was in specifically commit 79c8671,
so there's no need to revert the two commits that preceded it.
There's also no need to revert a111cfc, a documentation fix that
doesn't interact with the code added in 79c8671.  So, restore
those changes.
gnprice added a commit to gnprice/zulip-mobile that referenced this pull request Oct 30, 2020
I think when I originally wrote this change, I hadn't yet done most of
the investigations that led to zulip#4040 and wasn't as confident of how to
handle the many ways we represent PM conversations.  But now I have.
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