Page MenuHomePhabricator

Enable JS to subscribe to auth metadata events
ClosedPublic

Authored by marcin on Dec 14 2023, 5:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:51 AM
Unknown Object (File)
Fri, Oct 18, 1:50 AM
Unknown Object (File)
Oct 5 2024, 5:12 PM
Subscribers

Details

Summary

This differential enables JS code on both Android and iOS to subscribe to auth metadata events.

Test Plan
  1. Apply this patch: https://gist.github.com/marcinwasowicz/8ae2a80f5f8dfd0708f9496182d861bb. It is the same as for previous diffs but this time we use Js file that is comitted in this differential.
  2. Build Android and iOs apps.
  3. In each ensure that every time you type letter in message input you can see console.log with dummy auth metadata.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

  1. Rebase to update commit message
  2. Rename JS file
native/event-emitters/csa-auth-metadata-emitter.js
13 ↗(On Diff #34635)

This is actually how react native constructs JS object from native module that exports some constants. All constants exported from getConstants method automatically become properties of the object.

native/event-emitters/csa-auth-metadata-emitter.js
20–26 ↗(On Diff #34635)

Why is it an array of objects?

21–25 ↗(On Diff #34635)

Not directly related to this diff but this type should be extracted and exist somewhere in lib/, we're starting to duplicate it in various places across codebase, e.g. type BackupAuth, type IdentityInfo.

I have a suspicion that @varun is using this one extensively too, maybe it's already done as a part of his work, cc @varun

native/event-emitters/csa-auth-metadata-emitter.js
21–25 ↗(On Diff #34635)

yeah you can find this in lib/types/identity-service-types.js now

Use IdentityServiceAuthLayer type.

native/event-emitters/csa-auth-metadata-emitter.js
20–26 ↗(On Diff #34635)

This is the beginning of JS definition of NativeEventEmitter class:

export default class NativeEventEmitter<TEventToArgsMap: {...}>
  implements IEventEmitter<TEventToArgsMap>

So it is typed by the map of event names to array of arguments that listener callbacks will take. Then addListener method takes as an argument callback function that is typed by unwinding the array passed to NatuveEventEmitter type:

addListener<TEvent: $Keys<TEventToArgsMap>>(
    eventType: TEvent,
    listener: (...args: $ElementType<TEventToArgsMap, TEvent>) => mixed,
    context?: mixed,
  )

In our case listener callback will take one argument so it is one-element array.

bartek added inline comments.
native/event-emitters/csa-auth-metadata-emitter.js
20–26 ↗(On Diff #34635)

Ahh right. Thanks for detailed explanation!

This revision is now accepted and ready to land.Dec 15 2023, 2:59 AM
  1. Refactor to remove deviceID emission.
  2. Rebase before landing.