Alias for on.
Ensures up to date keys for a list of users are stored in the session store, downloading and storing them if they're not (or if forceDownload is true).
The users to fetch.
Always download the keys even if cached.
A promise which resolves to a map userId->deviceId->DeviceInfo.
Synchronously calls each of the listeners registered for the event named
event
, in the order they were registered, passing the supplied arguments
to each.
The name of the event to emit
Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Synchronously calls each of the listeners registered for the event named
event
, in the order they were registered, passing the supplied arguments
to each.
The name of the event to emit
Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Similar to emit
but calls all listeners within a Promise.all
and returns the promise chain
The name of the event to emit
Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Similar to emit
but calls all listeners within a Promise.all
and returns the promise chain
The name of the event to emit
Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Find a device by curve25519 identity key
encryption algorithm
curve25519 key to match
Get the stored keys for a single device
device, or undefined if we don't know about this device
Get the stored device keys for a user id
the user to list keys for.
list of devices, or null if we haven't managed to get a list of devices for this user yet.
Mark the cached device list for the given user outdated.
If we are not tracking this user's devices, we'll do nothing. Otherwise we flag the user as needing an update.
This doesn't actually set off an update, so that several users can be batched together. Call refreshOutdatedDeviceLists() for that.
Returns the number of listeners listening to the event named event
.
The name of the event being listened for
Returns a copy of the array of listeners for the event named event
.
Alias for removeListener
Adds the listener
function to the end of the listeners array for the
event named event
.
No checks are made to see if the listener
has already been added. Multiple calls
passing the same combination of event
and listener
will result in the listener
being added, and called, multiple times.
By default, event listeners are invoked in the order they are added. The prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds a one-time listener
function for the event named event
. The
next time event
is triggered, this listener is removed and then invoked.
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The prependOnceListener method can be used as an alternative to add the event listener to the beginning of the listeners array.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds the listener
function to the beginning of the listeners array for the
event named event
.
No checks are made to see if the listener
has already been added. Multiple calls
passing the same combination of event
and listener
will result in the listener
being added, and called, multiple times.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds a one-timelistener
function for the event named event
to the beginning of the listeners array.
The next time event
is triggered, this listener is removed, and then invoked.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
Removes all listeners, or those of the specified event
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Optional
event: EventEmitterEvents | EmittedEventsThe name of the event. If undefined, all listeners everywhere are removed.
a reference to the EventEmitter
, so that calls can be chained.
Removes the specified listener
from the listener array for the event named event
.
a reference to the EventEmitter
, so that calls can be chained.
Save the device tracking state to storage, if any changes are pending other than updating the sync token
The actual save will be delayed by a short amount of time to aggregate multiple writes to the database.
Time in ms before which the save actually happens. By default, the save is delayed for a short period in order to batch multiple writes, but this behaviour can be disabled by passing 0.
true if the data was saved, false if it was not (eg. because no changes were pending). The promise will only resolve once the data is saved, so may take some time to resolve.
Sets the sync token that the app will pass as the 'since' to the /sync endpoint next time it syncs. The sync token must always be set after any changes made as a result of data in that sync since setting the sync token to a newer one will mean those changed will not be synced from the server if a new client starts up with that data.
The sync token
flag the given user for device-list tracking, if they are not already.
This will mean that a subsequent call to refreshOutdatedDeviceLists() will download the device list for the user, and that subsequent calls to invalidateUserDeviceList will trigger more updates.
Mark the given user as no longer being tracked for device-list updates.
This won't affect any in-progress downloads, which will still go on to complete; it will just mean that we don't think that we have an up-to-date list for future calls to downloadKeys.
Typed Event Emitter class which can act as a Base Model for all our model and communication events. This makes it much easier for us to distinguish between events, as we now need to properly type this, so that our events are not stringly-based and prone to silly typos.
Type parameters:
Events
- List of all events emitted by thisTypedEventEmitter
. Normally an enum type.Arguments
- A ListenerMap type providing mappings from event names to listener types.SuperclassArguments
- TODO: not really sure. Alternative listener mappings, I think? But only honoured for.emit
?