sdk: add PinnedEventCache to Client.

This ensures the cache keeps the events even when the associated `Room` is dropped, which is what we want when using it to cache the pinned events for rooms in the client.

Add `fn Client::pinned_event_cached()` to get a reference to it.
This commit is contained in:
Jorge Martín
2024-08-02 13:17:04 +02:00
committed by Jorge Martin Espinosa
parent d1fe27c969
commit f1b20a8ea5
2 changed files with 13 additions and 0 deletions

View File

@@ -88,6 +88,7 @@ use crate::{
http_client::HttpClient,
matrix_auth::MatrixAuth,
notification_settings::NotificationSettings,
pinned_events_cache::PinnedEventCache,
room_preview::RoomPreview,
send_queue::SendQueueData,
sync::{RoomUpdate, SyncResponse},
@@ -286,6 +287,9 @@ pub(crate) struct ClientInner {
/// It becomes active when [`EventCache::subscribe`] is called.
pub(crate) event_cache: OnceCell<EventCache>,
/// A central cache for pinned events.
pub(crate) pinned_event_cache: PinnedEventCache,
/// End-to-end encryption related state.
#[cfg(feature = "e2e-encryption")]
pub(crate) e2ee: EncryptionData,
@@ -341,6 +345,7 @@ impl ClientInner {
respect_login_well_known,
sync_beat: event_listener::Event::new(),
event_cache,
pinned_event_cache: PinnedEventCache::new(),
send_queue_data: send_queue,
#[cfg(feature = "e2e-encryption")]
e2ee: EncryptionData::new(encryption_settings),
@@ -2229,6 +2234,11 @@ impl Client {
// SAFETY: always initialized in the `Client` ctor.
self.inner.event_cache.get().unwrap()
}
/// The [`PinnedEventCache`] instance for this [`Client`].
pub fn pinned_event_cache(&self) -> &PinnedEventCache {
&self.inner.pinned_event_cache
}
}
/// A weak reference to the inner client, useful when trying to get a handle

View File

@@ -96,5 +96,8 @@ uniffi::setup_scaffolding!();
#[cfg(any(test, feature = "testing"))]
pub mod test_utils;
/// Contains the pinned events cache implementation.
pub mod pinned_events_cache;
#[cfg(test)]
matrix_sdk_test::init_tracing_for_tests!();