Page MenuHomePhabricator

[keyserver] Include stateVersion when converting notifications
ClosedPublic

Authored by michal on Aug 3 2023, 7:41 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jun 25, 4:36 PM
Unknown Object (File)
Tue, Jun 25, 3:54 AM
Unknown Object (File)
Mon, Jun 24, 3:31 PM
Unknown Object (File)
Mon, Jun 24, 10:09 AM
Unknown Object (File)
Sat, Jun 22, 5:47 AM
Unknown Object (File)
Thu, Jun 20, 10:21 AM
Unknown Object (File)
Wed, Jun 19, 8:39 AM
Unknown Object (File)
Wed, Jun 12, 2:50 PM
Subscribers

Details

Summary

ENG-4579

ID conversion is based on the stateVersion. Unfortunately the notif code only handled the codeVersion and passed a new platformDetails object that didn't contain the stateVersion so this diff improves that.

This wasn't noticed earlier because previously conversion was based on codeVersion so it was working properly. Additionaly created ENG-4850 to refactor this code to handle the platformDetails together in the future.

Test Plan
  • Tested sending notification on iOS, macOS, Android, Web and Windows.
    • On clients with stateVersion < 43 the ids weren't converted
    • On clients with stateVersion >= 43 the ids were converted

On mobile clients, the IDs were tested in the JS (not native code.)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

keyserver/src/push/send.js
211 ↗(On Diff #29508)

It felt weird creating another function that would only split this key up, that's very tightly coupled with getDevicesByPlatform. But I can do that if it's better

keyserver/src/push/send.js
211 ↗(On Diff #29508)

It may look obvious for you but it makes it hard for new developer working on this code to understand what is going on. Additionally any change in getDevicesByPlatform will require you to change all places where it is used. It is a flaw of JavaScript that we can't define custom hash functions so that any object can a used as a key inside map. What I suggest that we do here is that:

  1. Introduce type (not necessarily exported) that covers codeVersion and stateVersion.
  2. Function that converts it to key according to your idea with "${}|${}".
  3. Function that converts string back to codeVersion and stateVersion pair and uses regex with invariant to ensure we can't pass anything there.

Alternatively - It looks like the output of getDevicesByPlatform is never actually used as a random-access hash map. It is always iterated on. I think we could easily and safely refactor it to return

Array<{
    +codeVersion: ?number,
    +stateVersion: ?number,
    +devices: $ReadOnlyArray<NotificationTargetDevice>?

}>

We can use still the trick with merging to a string and splitting it back to ensure uniqueness but it will be used only inside its implementation and won't hurt code quality in other places in this file.

Tested on Android, iOS, macOS and web that the received notification contained converted ids. I will be able to test windows in the evening and will amend this test plan.

Could you be more specific on how are you going to test it? Where converted ids are expected to appear? In JS layer or in the native layer? Additionally does this test plan cover both old (in terms of codeVersion and stateVersion pair) and new clients?

tomek added 1 blocking reviewer(s): marcin.

Agree with @marcin that introducing some utils encoding the contract is a good idea.

Added util functions for encoding the version key. Amended the test plan.

This revision is now accepted and ready to land.Aug 4 2023, 6:54 AM