Skip to content

Conversation

@agrawal-d
Copy link
Member

Zulip server versions >= 2.0.0-rc1 require user ID arrays in the
'to' argument for the typing endpoint, whereas we currently send
email arrays.

Check the Zulip version and use the appropriate format of the
argument, i.e., for versions >= 2.0.0-rc1 or when the Zulip server
version is undetermined, use user ID arrays, otherwise, use email
arrays.

Fixes #3732.

@agrawal-d
Copy link
Member Author

@gnprice @ray-kraesig please review.

Copy link
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.

I haven't yet tested, but this looks reasonable. Some nits and notes follow.

(I assume you've tested against CZO or something close to it; but have you also tested it against any older Zulip server versions?)

@agrawal-d agrawal-d force-pushed the typing-api branch 2 times, most recently from 71ee597 to 2566429 Compare April 9, 2020 14:42
@agrawal-d
Copy link
Member Author

agrawal-d commented Apr 9, 2020

Thanks for the review, @ray-kraesig, I've pushed some changes.

I tested this in CZO, and it worked -the app sends user ID arrays, and the typing notifications work.
I tried to test this on a local server before commit 2f634f8, but the server wasn't starting up due to some configuration errors, (I have limited internet connectivity right now, and cant destroy and re-provision.) I locally changed the server version to 1.0 in the app, and we do send email arrays then, so the logic is working.

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 @agrawal-d, and @ray-kraesig for the review!

A few additional comments, mostly small.

Comment on lines 37 to 38
const activeAccount: Account | void = tryGetActiveAccount(state);
if (!activeAccount || activeAccount.zulipVersion === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

No need for the try... form -- if there's no active account then none of this can work anyway 🙂 and also it should be impossible to get to this function.

See the jsdoc:

/**
 * The account currently foregrounded in the UI, or undefined if none.
 *
 * For use in early startup, onboarding, account-switch, or other times
 * where there may be no active account.
 *
 * See `getActiveAccount` for use in the UI for an already-active account
 * (including the bulk of the app), and code intended for that UI.
 */
export const tryGetActiveAccount = (state: GlobalState): Account | void => {

That also saves us from having to worry about whether this behavior is the right one in the case of no active account.

Comment on lines 36 to 41
let useEmailArrays: boolean;
const activeAccount: Account | void = tryGetActiveAccount(state);
if (!activeAccount || activeAccount.zulipVersion === undefined) {
useEmailArrays = false;
} else {
useEmailArrays = !new ZulipVersion(activeAccount.zulipVersion).isAtLeast(
Copy link
Member

Choose a reason for hiding this comment

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

Can simplify some of this by having a const serverVersion = ... above, just getting the ZulipVersion | void that describes the server, before any of the logic specific to this API feature and the version threshold for it.

In particular then that can be factored out into a selector in accountsSelectors.js, like getServerVersion returning ZulipVersion | void.

// User ID arrays are only supported in server versions >= 2.0.0-rc1, for
// versions before this, email arrays are used. If current server version is
// undetermined, user ID arrays are optimistically used.
// Support for user ID arrays was added in zulip/zulip commit 2f634f8.
Copy link
Member

Choose a reason for hiding this comment

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

nit: use 9 hex digits for a commit ID (git config --global core.abbrev 9 helps make this easy.)

For discussion see https://github.com/zulip/zulip-mobile/blob/master/docs/style.md#mentioning-commits , which I just wrote 😛 to explain why I've done this, and recommended it, for a long time.

Comment on lines 32 to 35
// User ID arrays are only supported in server versions >= 2.0.0-rc1, for
// versions before this, email arrays are used. If current server version is
// undetermined, user ID arrays are optimistically used.
// Support for user ID arrays was added in zulip/zulip commit 2f634f8.
Copy link
Member

Choose a reason for hiding this comment

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

nit: mention the commit ID right next to the version number -- they're two ways of describing the same fact

@rk-for-zulip
Copy link
Contributor

The only thing I'll add here is –

... ha! I literally got the notification for this commit as I was typing this sentence. As Greg notes, at least 9 hex digits, both in the commit message and in source comments. (In the commit message, for cross-repository commit references, you can use something along the lines of zulip/zulip@2f634f8c06; GitHub renders this as zulip/zulip@2f634f8c06.)

I don't actually recommend the 1.5.0-547-gd9b10727fa style of reference for most purposes. If you're going to promote that comment to the commit message, I'd suggest something more like ... providing its version as early as zulip/zulip@d9b10727fa (released in 1.6.0, in 2017-06). It's more likely...

Other than that, LGTM.


I tested this in CZO, and it worked -the app sends user ID arrays, and the typing notifications work.
I tried to test this on a local server before commit 2f634f8, but the server wasn't starting up due to some configuration errors, (I have limited internet connectivity right now, and cant destroy and re-provision.) I locally changed the server version to 1.0 in the app, and we do send email arrays then, so the logic is working.

I recently attempted to do the same and failed. I'm not having internet connectivity issues, as far as I can tell; I fear that whatever cloud-side resources 1.9.x depended on may have vanished. I'll bring it up on CZO.

I don't think this needs to block on that, though. Given that sending email arrays successfully reports typing presence in 2.2-dev, I feel safe in assuming that it'll work on previous versions.

@agrawal-d
Copy link
Member Author

agrawal-d commented Apr 11, 2020

@gnprice @ray-kraesig thanks for the review. I've pushed some changes. Please take a look.

@agrawal-d
Copy link
Member Author

agrawal-d commented Apr 11, 2020

You may notice that the GitHub UI still truncates the commit hash to 7 digits in the commit message, despite me having used the recommended 9 digits.

@rk-for-zulip
Copy link
Contributor

You may notice that the GitHub UI still truncates the commit hash to 7 digits in the commit message, despite me having used the recommended 9 digits.

Unfortunately, yes. The underlying commit message still has the correct number of digits in it, though, as can be seen by hovering on the link to your commit above. (I believe GitHub's linkifier also uses all provided digits, even if it doesn't present them.)

My concerns are addressed, and it looks like Greg's have been, too – I'll give him some time to take a second look, but I'm looking forward to having this fix in. Thanks!

agrawal-d and others added 4 commits April 14, 2020 13:02
'getServerVersion' returns the Zulip server version of the active
account in the parsed form as a ZulipVersion instance, or
undefined if we do not know the server version.
Zulip server versions >= 2.0.0-rc1 (zulip/zulip@2f634f8c0) require
user ID arrays in the 'to' argument for the typing endpoint,
whereas we currently send email arrays.

Check the Zulip version and use the appropriate format of the
argument, i.e., for versions >= 2.0.0-rc1 or when the Zulip server
version is undetermined [1], use user ID arrays, otherwise, use
email arrays.

[1] The server started providing its version as early as
zulip/zulip@d9b10727fa (released in 1.6.0, in 2017-06). It's more
likely that we failed to parse a new, exotic version-string format
than that someone's actually trying to connect to a Zulip server
that doesn't provide one.

Fixes zulip#3732.
Having just one place a variable gets its value helps simplify
reading and thinking about the code.
@gnprice gnprice merged commit 2ddb444 into zulip:master Apr 14, 2020
@gnprice
Copy link
Member

gnprice commented Apr 14, 2020

Merged -- thanks again both!

I added a couple of commits on top: one a code-style fixup, and one in part a jsdoc-style fixup and in part just adding some information to the jsdoc that we hadn't quite written down yet. I also slightly adjusted the commit messages' summary lines.

@agrawal-d agrawal-d deleted the typing-api branch April 14, 2020 20:07
@chrisbobbe
Copy link
Contributor

adding some information to the jsdoc that we hadn't quite written down yet

Thanks, @gnprice!

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.

Typing notifications are mistyped, resulting in rejection (for servers < 2.0)

4 participants