feat(sdk): Introduce the new LatestEvents
API
#5298
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is the first part of the new
LatestEvents
API. It containsthe “framework”, i.e. the structure, tasks, logic to make it work, but
no latest events are computed for the moment.
The Latest Events API provides a lazy, reactive and efficient way to
compute the latest event for a room or a thread.
The latest event represents the last displayable and relevant event
a room or a thread has been received. It is usually displayed in a
summary, e.g. below the room title in a room list.
The entry point is
LatestEvents
. It is preferable to get a referenceto it from
Client::latest_events
, which already plugs everything tobuild it.
LatestEvents
is using theEventCache
and theSendQueue
to respectively get known remote events (i.e. synced from the server),
or local events (i.e. ones being sent).
Laziness
LatestEvents
is lazy, it means that, despitesLatestEvents
is listening to all
EventCache
orSendQueue
updates, it willonly do something if one is expected to get the latest event for a
particular room or a particular thread. Concretely, it means that
until
LatestEvents::for_room
is called for a particular room, nolatest event will ever be computed for that room (and similarly with
LatestEvents::for_thread
).If one is no longer interested to get the latest event for a
particular room or thread, the
LatestEvents::forget_room
andLatestEvents::forget_thread
methods must be used.Reactive
LatestEvents
is designed to be reactive. Once one has fetched aLatestEvent
, it is recommended to immediately subscribe to its updateswith
LatestEvent::subscribe
.