Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ffi): Bye bye Sliding Sync bindings! #2222

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 0 additions & 14 deletions bindings/matrix-sdk-ffi/src/api.udl
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
namespace matrix_sdk_ffi {};

enum SlidingSyncListLoadingState {
/// Sliding Sync has not started to load anything yet.
"NotLoaded",
/// Sliding Sync has been preloaded, i.e. restored from a cache for example.
"Preloaded",
/// We are trying to load all remaining rooms, might be in batches
/// Updates are received from the loaded rooms, and new rooms are being fetched
/// in background
"PartiallyLoaded",
/// Updates are received for all the loaded rooms, and all rooms have been
/// loaded!
"FullyLoaded",
};

dictionary CreateRoomParameters {
string? name;
string? topic = null;
Expand Down
23 changes: 2 additions & 21 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::sync::{Arc, RwLock};

use anyhow::{anyhow, Context};
use eyeball::SharedObservable;
use matrix_sdk::{
media::{MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequest, MediaThumbnailSize},
room::Room as SdkRoom,
ruma::{
api::client::{
account::whoami,
error::ErrorKind,
media::get_content_thumbnail::v3::Method,
push::{EmailPusherData, PusherIds, PusherInit, PusherKind as RumaPusherKind},
room::{create_room, Visibility},
Expand All @@ -24,15 +22,15 @@ use matrix_sdk::{
serde::Raw,
EventEncryptionAlgorithm, TransactionId, UInt, UserId,
},
Client as MatrixClient, Error, LoopCtrl,
Client as MatrixClient,
};
use ruma::{
push::{HttpPusherData as RumaHttpPusherData, PushFormat as RumaPushFormat},
RoomId,
};
use serde_json::Value;
use tokio::sync::broadcast::error::RecvError;
use tracing::{debug, error, warn};
use tracing::{debug, error};
use url::Url;

use super::{room::Room, session_verification::SessionVerificationController, RUNTIME};
Expand Down Expand Up @@ -135,7 +133,6 @@ pub struct Client {
notification_delegate: Arc<RwLock<Option<Box<dyn NotificationDelegate>>>>,
session_verification_controller:
Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>,
pub(crate) sliding_sync_reset_broadcast_tx: Arc<SharedObservable<()>>,
}

impl Client {
Expand All @@ -161,7 +158,6 @@ impl Client {
delegate: Arc::new(RwLock::new(None)),
notification_delegate: Arc::new(RwLock::new(None)),
session_verification_controller,
sliding_sync_reset_broadcast_tx: Default::default(),
};

let mut unknown_token_error_receiver = client.inner.subscribe_to_unknown_token_errors();
Expand Down Expand Up @@ -674,21 +670,6 @@ impl From<&search_users::v3::User> for UserProfile {
}

impl Client {
/// Process a sync error and return loop control accordingly
pub(crate) fn process_sync_error(&self, sync_error: Error) -> LoopCtrl {
let client_api_error_kind = sync_error.client_api_error_kind();
match client_api_error_kind {
Some(ErrorKind::UnknownPos) => {
self.sliding_sync_reset_broadcast_tx.set(());
LoopCtrl::Continue
}
_ => {
warn!("Ignoring sync error: {sync_error:?}");
LoopCtrl::Continue
}
}
}

fn process_unknown_token_error(&self, unknown_token: matrix_sdk::UnknownToken) {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_receive_auth_error(unknown_token.soft_logout);
Expand Down
6 changes: 1 addition & 5 deletions bindings/matrix-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ mod room;
mod room_list;
mod room_member;
mod session_verification;
mod sliding_sync;
mod task_handle;
mod timeline;
mod tracing;

use async_compat::TOKIO1 as RUNTIME;
use matrix_sdk::{
ruma::events::room::{message::RoomMessageEventContent, MediaSource},
SlidingSyncListLoadingState,
};
use matrix_sdk::ruma::events::room::{message::RoomMessageEventContent, MediaSource};
use matrix_sdk_ui::timeline::EventItemOrigin;

use self::{
Expand Down
101 changes: 93 additions & 8 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ use std::{fmt::Debug, sync::Arc};

use eyeball_im::VectorDiff;
use futures_util::{pin_mut, StreamExt};
use ruma::RoomId;
use matrix_sdk::{
ruma::{
api::client::sync::sync_events::{
v4::RoomSubscription as RumaRoomSubscription,
UnreadNotificationsCount as RumaUnreadNotificationsCount,
},
assign, RoomId,
},
RoomListEntry as MatrixRoomListEntry,
};
use tokio::sync::RwLock;

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

#[uniffi::export]
impl Client {
Expand Down Expand Up @@ -384,3 +387,85 @@ impl RoomListItem {
Arc::new(self.inner.unread_notifications().into())
}
}

#[derive(Clone, Debug, uniffi::Enum)]
pub enum RoomListEntry {
Empty,
Invalidated { room_id: String },
Filled { room_id: String },
}

impl From<MatrixRoomListEntry> for RoomListEntry {
fn from(value: MatrixRoomListEntry) -> Self {
(&value).into()
}
}

impl From<&MatrixRoomListEntry> for RoomListEntry {
fn from(value: &MatrixRoomListEntry) -> Self {
match value {
MatrixRoomListEntry::Empty => Self::Empty,
MatrixRoomListEntry::Filled(room_id) => Self::Filled { room_id: room_id.to_string() },
MatrixRoomListEntry::Invalidated(room_id) => {
Self::Invalidated { room_id: room_id.to_string() }
}
}
}
}

#[derive(uniffi::Record)]
pub struct RequiredState {
pub key: String,
pub value: String,
}

#[derive(uniffi::Record)]
pub struct RoomSubscription {
pub required_state: Option<Vec<RequiredState>>,
pub timeline_limit: Option<u32>,
}

impl From<RoomSubscription> for RumaRoomSubscription {
fn from(val: RoomSubscription) -> Self {
assign!(RumaRoomSubscription::default(), {
required_state: val.required_state.map(|r|
r.into_iter().map(|s| (s.key.into(), s.value)).collect()
).unwrap_or_default(),
timeline_limit: val.timeline_limit.map(|u| u.into())
})
}
}

#[derive(uniffi::Object)]
pub struct UnreadNotificationsCount {
highlight_count: u32,
notification_count: u32,
}

#[uniffi::export]
impl UnreadNotificationsCount {
pub fn highlight_count(&self) -> u32 {
self.highlight_count
}
pub fn notification_count(&self) -> u32 {
self.notification_count
}
pub fn has_notifications(&self) -> bool {
self.notification_count != 0 || self.highlight_count != 0
}
}

impl From<RumaUnreadNotificationsCount> for UnreadNotificationsCount {
fn from(inner: RumaUnreadNotificationsCount) -> Self {
UnreadNotificationsCount {
highlight_count: inner
.highlight_count
.and_then(|x| x.try_into().ok())
.unwrap_or_default(),
notification_count: inner
.notification_count
.and_then(|x| x.try_into().ok())
.unwrap_or_default(),
}
}
}
Loading
Loading