pub struct EventCache { /* private fields */ }Expand description
An event cache, providing lots of useful functionality for clients.
Cloning is shallow, and thus is cheap to do.
See also the module-level comment.
Implementations§
Source§impl EventCache
impl EventCache
Sourcepub fn request_decryption(&self, request: DecryptionRetryRequest)
Available on crate feature e2e-encryption only.
pub fn request_decryption(&self, request: DecryptionRetryRequest)
e2e-encryption only.Explicitly request the redecryption of a set of events.
The redecryption logic in the event cache might sometimes miss that a room key has become available and that a certain set of events has become decryptable.
This might happen because some room keys might arrive in a separate process handling push notifications or if a room key arrives but the process shuts down before we could have decrypted the events.
For this reason it is useful to tell the event cache explicitly that some events should be retried to be redecrypted.
This method allows you to do so. The events that get decrypted, if any,
will be advertised over the usual event cache subscription mechanism
which can be accessed using the RoomEventCache::subscribe()
method.
§Examples
let event_cache = client.event_cache();
let room_id = owned_room_id!("!my_room:localhost");
let request = DecryptionRetryRequest {
room_id,
utd_session_ids: BTreeSet::from(["session_id".into()]),
refresh_info_session_ids: BTreeSet::new(),
};
event_cache.request_decryption(request);Sourcepub fn subscribe_to_decryption_reports(
&self,
) -> impl Stream<Item = Result<RedecryptorReport, BroadcastStreamRecvError>>
Available on crate feature e2e-encryption only.
pub fn subscribe_to_decryption_reports( &self, ) -> impl Stream<Item = Result<RedecryptorReport, BroadcastStreamRecvError>>
e2e-encryption only.Subscribe to reports that the redecryptor generates.
The redecryption logic in the event cache might sometimes miss that a room key has become available and that a certain set of events has become decryptable.
This might happen because some room keys might arrive in a separate process handling push notifications or if room keys arrive faster than we can handle them.
This stream can be used to get notified about such situations as well as a general channel where the event cache reports which events got successfully redecrypted.
§Examples
let event_cache = client.event_cache();
let mut stream = event_cache.subscribe_to_decryption_reports();
while let Some(Ok(report)) = stream.next().await {
match report {
RedecryptorReport::Lagging => {
// The event cache might have missed to redecrypt some events. We should tell
// it which events we care about, i.e. which events we're displaying to the
// user, and let it redecrypt things with an explicit request.
}
RedecryptorReport::ResolvedUtds { .. } => {
// This may be interesting for statistical reasons or in case we'd like to
// fetch and inspect these events in some manner.
}
}
}Source§impl EventCache
impl EventCache
Sourcepub fn subscribe(&self) -> Result<()>
pub fn subscribe(&self) -> Result<()>
Starts subscribing the EventCache to sync responses, if not done
before.
Re-running this has no effect if we already subscribed before, and is cheap.
Sourcepub fn has_subscribed(&self) -> bool
pub fn has_subscribed(&self) -> bool
Check whether EventCache::subscribe has been called.
Sourcepub async fn clear_all_rooms(&self) -> Result<()>
pub async fn clear_all_rooms(&self) -> Result<()>
Cleanly clear all the rooms’ event caches.
This will notify any live observers that the room has been cleared.
Sourcepub fn subscribe_to_room_generic_updates(
&self,
) -> Receiver<RoomEventCacheGenericUpdate>
pub fn subscribe_to_room_generic_updates( &self, ) -> Receiver<RoomEventCacheGenericUpdate>
Subscribe to room generic updates.
If one wants to listen what has changed in a specific room, the
RoomEventCache::subscribe is recommended. However, the
RoomEventCacheSubscriber type triggers side-effects.
If one wants to get a high-overview, generic, updates for rooms, and without side-effects, this method is recommended. Also, dropping the receiver of this channel will not trigger any side-effect.
Trait Implementations§
Source§impl Clone for EventCache
impl Clone for EventCache
Source§fn clone(&self) -> EventCache
fn clone(&self) -> EventCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EventCache
impl !RefUnwindSafe for EventCache
impl Send for EventCache
impl Sync for EventCache
impl Unpin for EventCache
impl !UnwindSafe for EventCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more