Skip to content

Commit

Permalink
ffi: Remove sliding sync things from UDL
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jun 15, 2023
1 parent 867b366 commit 899c0d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 65 deletions.
53 changes: 0 additions & 53 deletions bindings/matrix-sdk-ffi/src/api.udl
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ dictionary NotificationItem {

interface TimelineEvent {};

dictionary UpdateSummary {
sequence<string> lists;
sequence<string> rooms;
};

callback interface SlidingSyncObserver {
void did_receive_sync_update(UpdateSummary summary);
};

enum SlidingSyncState {
/// Sliding Sync has not started to load anything yet.
"NotLoaded",
Expand All @@ -46,50 +37,6 @@ enum SlidingSyncState {
"FullyLoaded",
};

callback interface SlidingSyncListStateObserver {
void did_receive_update(SlidingSyncState new_state);
};

// Used by `SlidingSync` _and_ `RoomList`. Be careful.
[Enum]
interface RoomListEntry {
Empty();
Invalidated(string room_id);
Filled(string room_id);
};

[Enum]
interface SlidingSyncListRoomsListDiff {
Append(sequence<RoomListEntry> values);
Insert(u32 index, RoomListEntry value);
Set(u32 index, RoomListEntry value);
Remove(u32 index);
PushBack(RoomListEntry value);
PushFront(RoomListEntry value);
PopBack();
PopFront();
Clear();
Reset(sequence<RoomListEntry> values);
};

callback interface SlidingSyncListRoomListObserver {
void did_receive_update(SlidingSyncListRoomsListDiff diff);
};

callback interface SlidingSyncListRoomsCountObserver {
void did_receive_update(u32 count);
};

callback interface SlidingSyncListRoomItemsObserver {
void did_receive_update();
};

interface SlidingSyncList {};

callback interface SlidingSyncListOnceBuilt {
SlidingSyncList update_list(SlidingSyncList list);
};

dictionary CreateRoomParameters {
string? name;
string? topic = null;
Expand Down
7 changes: 5 additions & 2 deletions bindings/matrix-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ mod timeline;
mod tracing;

use async_compat::TOKIO1 as RUNTIME;
use matrix_sdk::ruma::events::room::{message::RoomMessageEventContent, MediaSource};
use matrix_sdk::{
ruma::events::room::{message::RoomMessageEventContent, MediaSource},
SlidingSyncState,
};

use self::{
client::*, error::ClientError, event::*, notification::*, platform::*, session_verification::*,
sliding_sync::*, task_handle::TaskHandle, timeline::MediaSourceExt,
task_handle::TaskHandle, timeline::MediaSourceExt,
};

uniffi::include_scaffolding!("api");
Expand Down
6 changes: 4 additions & 2 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use futures_util::{pin_mut, StreamExt};
use ruma::RoomId;

use crate::{
room::Room, timeline::EventTimelineItem, Client, RoomListEntry, RoomSubscription, TaskHandle,
UnreadNotificationsCount, RUNTIME,
room::Room,
sliding_sync::{RoomListEntry, RoomSubscription, UnreadNotificationsCount},
timeline::EventTimelineItem,
Client, TaskHandle, RUNTIME,
};

#[uniffi::export]
Expand Down
22 changes: 14 additions & 8 deletions bindings/matrix-sdk-ffi/src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ use std::sync::{Arc, RwLock};
use anyhow::Context;
use eyeball_im::VectorDiff;
use futures_util::{future::join3, pin_mut, StreamExt};
pub use matrix_sdk::{
ruma::api::client::sync::sync_events::v4::SyncRequestListFilters, Client as MatrixClient,
LoopCtrl, RoomListEntry as MatrixRoomEntry, SlidingSyncBuilder as MatrixSlidingSyncBuilder,
SlidingSyncMode, SlidingSyncState,
};
use matrix_sdk::{
ruma::{
api::client::sync::sync_events::{
v4::RoomSubscription as RumaRoomSubscription,
v4::{RoomSubscription as RumaRoomSubscription, SyncRequestListFilters},
UnreadNotificationsCount as RumaUnreadNotificationsCount,
},
assign, IdParseError, OwnedRoomId, RoomId,
},
sliding_sync::SlidingSyncSelectiveModeBuilder as MatrixSlidingSyncSelectiveModeBuilder,
LoopCtrl, RoomListEntry as MatrixRoomEntry, SlidingSyncBuilder as MatrixSlidingSyncBuilder,
SlidingSyncMode, SlidingSyncState,
};
use matrix_sdk_ui::timeline::SlidingSyncRoomExt;
use tracing::{error, warn};
Expand Down Expand Up @@ -250,6 +247,7 @@ pub struct SlidingSyncAddTimelineListenerResult {
pub task_handle: Arc<TaskHandle>,
}

#[derive(uniffi::Record)]
pub struct UpdateSummary {
/// The lists (according to their name), which have seen an update
pub lists: Vec<String>,
Expand Down Expand Up @@ -288,6 +286,7 @@ impl From<matrix_sdk::UpdateSummary> for UpdateSummary {
}
}

#[derive(uniffi::Enum)]
pub enum SlidingSyncListRoomsListDiff {
Append { values: Vec<RoomListEntry> },
Insert { index: u32, value: RoomListEntry },
Expand Down Expand Up @@ -327,7 +326,8 @@ impl From<VectorDiff<MatrixRoomEntry>> for SlidingSyncListRoomsListDiff {
}
}

#[derive(Clone, Debug)]
// Used by `SlidingSync` _and_ `RoomList`. Be careful.
#[derive(Clone, Debug, uniffi::Enum)]
pub enum RoomListEntry {
Empty,
Invalidated { room_id: String },
Expand All @@ -352,18 +352,22 @@ impl From<&MatrixRoomEntry> for RoomListEntry {
}
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncListRoomItemsObserver: Sync + Send {
fn did_receive_update(&self);
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncListRoomListObserver: Sync + Send {
fn did_receive_update(&self, diff: SlidingSyncListRoomsListDiff);
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncListRoomsCountObserver: Sync + Send {
fn did_receive_update(&self, new_count: u32);
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncListStateObserver: Sync + Send {
fn did_receive_update(&self, new_state: SlidingSyncState);
}
Expand Down Expand Up @@ -533,11 +537,12 @@ impl SlidingSyncListBuilder {
}
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncListOnceBuilt: Sync + Send {
fn update_list(&self, list: Arc<SlidingSyncList>) -> Arc<SlidingSyncList>;
}

#[derive(Clone)]
#[derive(Clone, uniffi::Object)]
pub struct SlidingSyncList {
inner: matrix_sdk::SlidingSyncList,
}
Expand Down Expand Up @@ -628,6 +633,7 @@ impl SlidingSyncList {
}
}

#[uniffi::export(callback_interface)]
pub trait SlidingSyncObserver: Sync + Send {
fn did_receive_sync_update(&self, summary: UpdateSummary);
}
Expand Down

0 comments on commit 899c0d5

Please sign in to comment.