mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-26 18:20:40 -04:00
feat(labs): Update jack-in to the new sliding sync room API.
This commit is contained in:
@@ -818,6 +818,11 @@ impl SlidingSync {
|
||||
self.rooms.lock_ref().get(&room_id).cloned()
|
||||
}
|
||||
|
||||
/// Check the number of rooms.
|
||||
pub fn get_number_of_rooms(&self) -> usize {
|
||||
self.rooms.lock_ref().len()
|
||||
}
|
||||
|
||||
fn update_to_device_since(&self, since: String) {
|
||||
self.extensions
|
||||
.lock()
|
||||
@@ -869,6 +874,11 @@ impl SlidingSync {
|
||||
room_ids.map(|room_id| rooms.get(&room_id).cloned()).collect()
|
||||
}
|
||||
|
||||
/// Get all rooms.
|
||||
pub fn get_all_rooms(&self) -> Vec<SlidingSyncRoom> {
|
||||
self.rooms.lock_ref().iter().map(|(_, room)| room.clone()).collect()
|
||||
}
|
||||
|
||||
#[instrument(skip_all, fields(views = views.len()))]
|
||||
async fn handle_response(
|
||||
&self,
|
||||
|
||||
@@ -43,7 +43,7 @@ pub async fn run_client(
|
||||
let stream = syncer.stream();
|
||||
let view = syncer.view("full-sync").expect("we have the full syncer there").clone();
|
||||
let state = view.state.clone();
|
||||
let mut ssync_state = state::SlidingSyncState::new(view);
|
||||
let mut ssync_state = state::SlidingSyncState::new(syncer.clone(), view);
|
||||
tx.send(ssync_state.clone()).await?;
|
||||
|
||||
info!("starting polling");
|
||||
|
||||
@@ -10,8 +10,8 @@ use futures_signals::{
|
||||
};
|
||||
use matrix_sdk::{
|
||||
room::timeline::{Timeline, TimelineItem},
|
||||
ruma::OwnedRoomId,
|
||||
SlidingSyncState as ViewState, SlidingSyncView,
|
||||
ruma::{OwnedRoomId, RoomId},
|
||||
SlidingSync, SlidingSyncRoom, SlidingSyncState as ViewState, SlidingSyncView,
|
||||
};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
@@ -25,6 +25,7 @@ pub struct CurrentRoomSummary {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SlidingSyncState {
|
||||
started: Instant,
|
||||
syncer: SlidingSync,
|
||||
view: SlidingSyncView,
|
||||
/// the current list selector for the room
|
||||
first_render: Option<Duration>,
|
||||
@@ -37,9 +38,10 @@ pub struct SlidingSyncState {
|
||||
}
|
||||
|
||||
impl SlidingSyncState {
|
||||
pub fn new(view: SlidingSyncView) -> Self {
|
||||
pub fn new(syncer: SlidingSync, view: SlidingSyncView) -> Self {
|
||||
Self {
|
||||
started: Instant::now(),
|
||||
syncer,
|
||||
view,
|
||||
first_render: None,
|
||||
full_sync: None,
|
||||
@@ -64,9 +66,7 @@ impl SlidingSyncState {
|
||||
if let Some(c) = self.tl_handle.lock_mut().take() {
|
||||
c.abort();
|
||||
}
|
||||
if let Some(room) =
|
||||
r.as_ref().and_then(|room_id| self.view.rooms.lock_ref().get(room_id).cloned())
|
||||
{
|
||||
if let Some(room) = r.as_ref().and_then(|room_id| self.get_room(room_id)) {
|
||||
let current_timeline = self.current_timeline.clone();
|
||||
let room_timeline = self.room_timeline.clone();
|
||||
let handle = tokio::spawn(async move {
|
||||
@@ -120,7 +120,7 @@ impl SlidingSyncState {
|
||||
}
|
||||
|
||||
pub fn loaded_rooms_count(&self) -> usize {
|
||||
self.view.rooms.lock_ref().len()
|
||||
self.syncer.get_number_of_rooms()
|
||||
}
|
||||
|
||||
pub fn total_rooms_count(&self) -> Option<u32> {
|
||||
@@ -135,6 +135,14 @@ impl SlidingSyncState {
|
||||
&self.view
|
||||
}
|
||||
|
||||
pub fn get_room(&self, room_id: &RoomId) -> Option<SlidingSyncRoom> {
|
||||
self.syncer.get_room(room_id.to_owned())
|
||||
}
|
||||
|
||||
pub fn get_all_rooms(&self) -> Vec<SlidingSyncRoom> {
|
||||
self.syncer.get_all_rooms()
|
||||
}
|
||||
|
||||
pub fn set_full_sync_now(&mut self) {
|
||||
self.full_sync = Some(self.started.elapsed())
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ impl Details {
|
||||
|
||||
pub fn refresh_data(&mut self) {
|
||||
let Some(room_id) = self.sstate.selected_room.lock_ref().clone() else { return };
|
||||
let Some(room_data) = self.sstate.view().rooms.lock_ref().get(&room_id).cloned() else {
|
||||
let Some(room_data) = self.sstate.get_room(&room_id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Rooms {
|
||||
}
|
||||
|
||||
pub fn select_dir(&mut self, count: i32) {
|
||||
let rooms_count = self.sstate.view().get_rooms(None, None).len() as i32;
|
||||
let rooms_count = self.sstate.loaded_rooms_count() as i32;
|
||||
let current = self.tablestate.selected().unwrap_or_default() as i32;
|
||||
let next = {
|
||||
let next = current + count;
|
||||
@@ -63,8 +63,9 @@ impl MockComponent for Rooms {
|
||||
|
||||
let mut paras = vec![];
|
||||
|
||||
for r in self.sstate.view().get_rooms(None, None) {
|
||||
let mut cells = vec![Cell::from(r.name.unwrap_or_else(|| "unknown".to_owned()))];
|
||||
for r in self.sstate.get_all_rooms() {
|
||||
let mut cells =
|
||||
vec![Cell::from(r.name.clone().unwrap_or_else(|| "unknown".to_owned()))];
|
||||
if let Some(c) = r.unread_notifications.notification_count {
|
||||
let count: u32 = c.try_into().unwrap_or_default();
|
||||
if count > 0 {
|
||||
|
||||
Reference in New Issue
Block a user