Merge branch 'update-ruma'

This commit is contained in:
Damir Jelić 2020-11-20 21:21:24 +01:00
commit dedb1eb745
5 changed files with 13 additions and 104 deletions

View file

@ -1402,10 +1402,10 @@ impl Client {
sync_settings: SyncSettings<'_>,
) -> Result<sync_events::Response> {
let request = assign!(sync_events::Request::new(), {
filter: sync_settings.filter,
filter: sync_settings.filter.as_ref(),
since: sync_settings.token.as_deref(),
full_state: sync_settings.full_state,
set_presence: PresenceState::Online,
set_presence: &PresenceState::Online,
timeout: sync_settings.timeout,
});
@ -1496,13 +1496,11 @@ impl Client {
#[instrument(skip(callback))]
pub async fn sync_with_callback<C>(
&self,
sync_settings: SyncSettings<'_>,
mut sync_settings: SyncSettings<'_>,
callback: impl Fn(sync_events::Response) -> C,
) where
C: Future<Output = LoopCtrl>,
{
let mut sync_settings = sync_settings;
let filter = sync_settings.filter;
let mut last_sync_time: Option<Instant> = None;
if sync_settings.token.is_none() {
@ -1510,6 +1508,7 @@ impl Client {
}
loop {
let filter = sync_settings.filter.clone();
let response = self.sync_once(sync_settings.clone()).await;
let response = match response {
@ -1577,8 +1576,8 @@ impl Client {
.await
.expect("No sync token found after initial sync"),
);
if let Some(f) = filter.as_ref() {
sync_settings = sync_settings.filter(*f);
if let Some(f) = filter {
sync_settings = sync_settings.filter(f);
}
}
}

View file

@ -2387,97 +2387,6 @@ mod test {
assert!(passed.load(Ordering::SeqCst))
}
#[async_test]
async fn test_unrecognized_custom_event() {
use super::*;
use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::{api::r0::sync::sync_events, locks::RwLock};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
struct EE(Arc<AtomicBool>);
#[async_trait]
impl EventEmitter for EE {
async fn on_custom_event(&self, room: SyncRoom, event: &CustomEvent<'_>) {
if let SyncRoom::Joined(_) = room {
if let CustomEvent::Message(custom) = event {
if custom.content.event_type == "m.reaction"
&& custom.content.json.get("m.relates_to").is_some()
{
self.0.swap(true, Ordering::SeqCst);
}
}
}
}
}
let room_id = get_room_id();
let passed = Arc::new(AtomicBool::default());
let emitter = EE(Arc::clone(&passed));
let mut client = get_client().await;
client.event_emitter = Arc::new(RwLock::new(Some(Box::new(emitter))));
// This is needed other wise the `EventBuilder` goes through a de/ser cycle and the `prev_content` is lost.
let event: &serde_json::Value = &test_json::REACTION;
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
let joined_room = serde_json::json!({
"summary": {},
"account_data": {
"events": [],
},
"ephemeral": {
"events": [],
},
"state": {
"events": [],
},
"timeline": {
"events": vec![ event ],
"limited": true,
"prev_batch": "t392-516_47314_0_7_1_1_1_11444_1"
},
"unread_notifications": {
"highlight_count": 0,
"notification_count": 11
}
});
joined_rooms.insert(room_id, joined_room);
let empty_room: HashMap<RoomId, serde_json::Value> = HashMap::new();
let body = serde_json::json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
"device_lists": {
"changed": [],
"left": []
},
"rooms": {
"invite": empty_room,
"join": joined_rooms,
"leave": empty_room,
},
"to_device": {
"events": []
},
"presence": {
"events": []
}
});
let response = http::Response::builder()
.body(serde_json::to_vec(&body).unwrap())
.unwrap();
let mut sync = sync_events::Response::try_from(response).unwrap();
client.receive_sync_response(&mut sync).await.unwrap();
assert!(passed.load(Ordering::SeqCst))
}
#[cfg(feature = "messages")]
#[async_test]
async fn message_queue_redaction_event_store_deser() {

View file

@ -934,7 +934,7 @@ impl Room {
member.currently_active = *currently_active;
member.display_name = displayname.clone();
member.last_active_ago = *last_active_ago;
member.presence = Some(*presence);
member.presence = Some(presence.clone());
member.status_msg = status_msg.clone();
true

View file

@ -21,7 +21,7 @@ js_int = "0.1.9"
[dependencies.ruma]
version = "0.0.1"
git = "https://github.com/ruma/ruma"
rev = "50eb700571480d1440e15a387d10f98be8abab59"
rev = "d16fd4b2c1be1b06fd9be99373a3e77d74fadff3"
default-features = false
features = ["client-api", "unstable-pre-spec", "unstable-synapse-quirks"]

View file

@ -298,7 +298,7 @@ impl KeyRequestMachine {
&self,
event: &ToDeviceEvent<RoomKeyRequestEventContent>,
) -> OlmResult<()> {
let key_info = match event.content.action {
let key_info = match &event.content.action {
Action::Request => {
if let Some(info) = &event.content.body {
info
@ -313,9 +313,10 @@ impl KeyRequestMachine {
}
// We ignore cancellations here since there's nothing to serve.
Action::CancelRequest => return Ok(()),
// There is no other action defined, but ruma makes all enums
// non-exhaustive.
_ => return Ok(()),
action => {
warn!("Unknown room key request action: {:?}", action);
return Ok(());
}
};
let session = self