Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tokio::{
sync::{mpsc::{Sender, UnboundedReceiver, UnboundedSender}, watch, Notify}, task::JoinHandle, time::error::Elapsed,
};
use url::Url;
use std::{cmp::{max, min}, future::Future, hash::{BuildHasherDefault, DefaultHasher}, iter::Peekable, ops::{Deref, Not}, path:: Path, sync::{Arc, LazyLock, Mutex}, time::Duration};
use std::{cmp::{max, min}, future::Future, iter::Peekable, ops::{Deref, Not}, path:: Path, sync::{Arc, LazyLock, Mutex}, time::Duration};
use std::io;
use hashbrown::{HashMap, HashSet};
use crate::{
Expand Down Expand Up @@ -1929,12 +1929,9 @@ impl Drop for JoinedRoomDetails {
}


/// A const-compatible hasher, used for `static` items containing `HashMap`s or `HashSet`s.
type ConstHasher = BuildHasherDefault<DefaultHasher>;

/// Information about all joined rooms that our client currently know about.
/// We use a `HashMap` for O(1) lookups, as this is accessed frequently (e.g. every timeline update).
static ALL_JOINED_ROOMS: Mutex<HashMap<OwnedRoomId, JoinedRoomDetails, ConstHasher>> = Mutex::new(HashMap::with_hasher(BuildHasherDefault::new()));
static ALL_JOINED_ROOMS: LazyLock<Mutex<HashMap<OwnedRoomId, JoinedRoomDetails>>> = LazyLock::new(|| Mutex::new(HashMap::new()));

/// The logged-in Matrix client, which can be freely and cheaply cloned.
static CLIENT: Mutex<Option<Client>> = Mutex::new(None);
Expand Down Expand Up @@ -1962,10 +1959,10 @@ pub fn get_sync_service() -> Option<Arc<SyncService>> {
/// The list of users that the current user has chosen to ignore.
/// Ideally we shouldn't have to maintain this list ourselves,
/// but the Matrix SDK doesn't currently properly maintain the list of ignored users.
static IGNORED_USERS: Mutex<HashSet<OwnedUserId, ConstHasher>> = Mutex::new(HashSet::with_hasher(BuildHasherDefault::new()));
static IGNORED_USERS: LazyLock<Mutex<HashSet<OwnedUserId>>> = LazyLock::new(|| Mutex::new(HashSet::new()));

/// Returns a deep clone of the current list of ignored users.
pub fn get_ignored_users() -> HashSet<OwnedUserId, ConstHasher> {
pub fn get_ignored_users() -> HashSet<OwnedUserId> {
IGNORED_USERS.lock().unwrap().clone()
}

Expand Down Expand Up @@ -2952,7 +2949,7 @@ fn handle_ignore_user_list_subscriber(client: Client) {
let ignored_users_new = ignore_list
.into_iter()
.filter_map(|u| OwnedUserId::try_from(u).ok())
.collect::<HashSet<_, ConstHasher>>();
.collect::<HashSet<_>>();

// TODO: when we support persistent state, don't forget to update `IGNORED_USERS` upon app boot.
let mut ignored_users_old = IGNORED_USERS.lock().unwrap();
Expand Down