Commit bd52ba78 authored by Julian Sparber's avatar Julian Sparber
Browse files

bump matrix-sdk to commit bdaed6237e104b738b5ad25c063675373d9fa60d

This also bumps tokio to 1.1.0 since the matrix-sdk depends on it.
parent 5ed6b586
Pipeline #253498 passed with stages
in 47 minutes and 10 seconds
This diff is collapsed.
......@@ -70,8 +70,8 @@ version = "0.9.0"
features = ["v2_56"]
[dependencies.tokio]
version = "0.2.22"
features = ["rt-threaded", "time"]
version = "1.1.1"
features = ["rt-multi-thread", "time", "fs"]
[dependencies.url]
version = "2.1.1"
......@@ -79,5 +79,5 @@ features = ["serde"]
[dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk.git"
rev = "0422bae92485b033d4f9b56f2331909653655609"
rev = "bdaed6237e104b738b5ad25c063675373d9fa60d"
features = ["unstable-synapse-quirks", "socks"]
......@@ -48,9 +48,7 @@ impl AppOp {
identity_url,
});
let _ = RUNTIME
.handle()
.block_on(matrix_client.restore_login(Session {
let _ = RUNTIME.block_on(matrix_client.restore_login(Session {
access_token: access_token.to_string(),
user_id: uid,
device_id,
......
......@@ -9,9 +9,7 @@ use crate::model::{
room::{Room, RoomMembership, RoomTag},
};
use crate::util::i18n::i18n;
use log::warn;
use matrix_sdk::api::r0::sync::sync_events::JoinedRoom;
use matrix_sdk::api::r0::sync::sync_events::Response as SyncResponse;
use matrix_sdk::deserialized_responses::{JoinedRoom, SyncResponse};
use matrix_sdk::events::AnyEphemeralRoomEventContent;
use matrix_sdk::events::AnySyncMessageEvent;
use matrix_sdk::events::AnySyncRoomEvent;
......@@ -61,14 +59,8 @@ impl AppOp {
for (room_id, unread_notifications) in updates.room_notifications {
let r = room_id;
let n: u64 = unread_notifications
.notification_count
.map(Into::into)
.unwrap_or_default();
let h: u64 = unread_notifications
.highlight_count
.map(Into::into)
.unwrap_or_default();
let n: u64 = unread_notifications.notification_count;
let h: u64 = unread_notifications.highlight_count;
APPOP!(set_room_notifications, (r, n, h));
}
......@@ -160,11 +152,6 @@ fn get_sync_updates(join: &BTreeMap<RoomId, JoinedRoom>, user_id: &UserId) -> Sy
.map(|(k, room)| {
let typing: Vec<Member> = room.ephemeral.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| if let Err(err) = result_ev {
warn!("Bad event: {}", err);
})
.filter_map(Result::ok)
.filter_map(|event| match event.content() {
AnyEphemeralRoomEventContent::Typing(content) => {
Some(content.user_ids)
......@@ -194,30 +181,24 @@ fn get_sync_updates(join: &BTreeMap<RoomId, JoinedRoom>, user_id: &UserId) -> Sy
room.timeline
.events
.iter()
.map(move |ev| Ok((room_id.clone(), ev.deserialize()?)))
})
.inspect(|result_ev: &Result<_, serde_json::Error>| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
.map(move |ev| (room_id.clone(), ev))
})
.filter_map(Result::ok)
.filter_map(|(room_id, event)| match event {
AnySyncRoomEvent::State(AnySyncStateEvent::RoomName(ev)) => {
let name = ev.content.name().map(Into::into).unwrap_or_default();
Some(RoomElement::Name(room_id, name))
}
AnySyncRoomEvent::State(AnySyncStateEvent::RoomTopic(ev)) => {
Some(RoomElement::Topic(room_id, ev.content.topic))
Some(RoomElement::Topic(room_id, ev.content.topic.clone()))
}
AnySyncRoomEvent::State(AnySyncStateEvent::RoomAvatar(_)) => {
Some(RoomElement::NewAvatar(room_id))
}
AnySyncRoomEvent::State(AnySyncStateEvent::RoomMember(ev)) => {
Some(RoomElement::MemberEvent(ev.into_full_event(room_id)))
}
AnySyncRoomEvent::State(AnySyncStateEvent::RoomMember(ev)) => Some(
RoomElement::MemberEvent(ev.clone().into_full_event(room_id)),
),
AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomRedaction(ev)) => {
Some(RoomElement::RemoveMessage(room_id, ev.redacts))
Some(RoomElement::RemoveMessage(room_id, ev.redacts.clone()))
}
_ => None,
})
......
......@@ -972,7 +972,7 @@ pub async fn set_pushrules(
],
};
let request = SetRoomRulesRequest::new("global", RuleKind::Room, room_id.as_str(), actions);
let request = SetRoomRulesRequest::new("global", RuleKind::Room, room_id.as_str(), &actions);
session_client.send(request).await?;
......
......@@ -7,9 +7,9 @@ use matrix_sdk::api::r0::filter::LazyLoadOptions;
use matrix_sdk::api::r0::filter::RoomEventFilter;
use matrix_sdk::api::r0::filter::RoomFilter;
use matrix_sdk::api::r0::sync::sync_events::Filter;
use matrix_sdk::api::r0::sync::sync_events::Response;
use matrix_sdk::api::r0::sync::sync_events::UnreadNotificationsCount;
use matrix_sdk::assign;
use matrix_sdk::deserialized_responses::SyncResponse;
use matrix_sdk::deserialized_responses::UnreadNotificationsCount;
use matrix_sdk::events::room::member::MemberEventContent;
use matrix_sdk::events::StateEvent;
use matrix_sdk::identifiers::{EventId, RoomId};
......@@ -63,7 +63,7 @@ pub async fn sync(
session_client: MatrixClient,
since: Option<String>,
number_tries: u32,
) -> Result<Response, SyncError> {
) -> Result<SyncResponse, SyncError> {
let initial = since.is_none();
let timeline_not_types = [String::from("m.call.*")];
let timeline_types = [String::from("m.room.message"), String::from("m.sticker")];
......@@ -118,7 +118,7 @@ pub async fn sync(
"Sync Error, waiting {} seconds to respond for the next sync",
waiting_time.as_secs()
);
tokio::time::delay_for(waiting_time).await;
tokio::time::sleep(waiting_time).await;
Err(SyncError(err, number_tries))
}
......
......@@ -145,17 +145,23 @@ impl From<MessageEvent<MessageEventContent>> for Message {
Relation::Reply { in_reply_to } => (Some(in_reply_to.event_id), None),
_ => (None, None),
});
let (body, formatted, in_reply_to) = content.new_content.map_or(
(content.body, content.formatted, in_reply_to),
|nc| {
let (body, formatted, in_reply_to) = content
.new_content
.and_then(|nc| {
// FIXME: this could go wrong if a text message wasn't replaced with a text
// message.
if let MessageEventContent::Text(nc) = *nc {
let in_reply_to = nc.relates_to.and_then(|r| match r {
Relation::Reply { in_reply_to } => Some(in_reply_to.event_id),
_ => None,
});
(nc.body, nc.formatted, in_reply_to)
},
);
Some((nc.body, nc.formatted, in_reply_to))
} else {
None
}
})
.unwrap_or((content.body, content.formatted, in_reply_to));
let (formatted_body, format) = formatted.map_or(Default::default(), |f| {
(Some(f.body), Some(f.format.as_str().into()))
});
......@@ -195,17 +201,23 @@ impl From<MessageEvent<MessageEventContent>> for Message {
Relation::Reply { in_reply_to } => (Some(in_reply_to.event_id), None),
_ => (None, None),
});
let (body, formatted, in_reply_to) = content.new_content.map_or(
(content.body, content.formatted, in_reply_to),
|nc| {
let (body, formatted, in_reply_to) = content
.new_content
.and_then(|nc| {
// FIXME: this could go wrong if a notice message wasn't replaced with a
// notice message.
if let MessageEventContent::Notice(nc) = *nc {
let in_reply_to = nc.relates_to.and_then(|r| match r {
Relation::Reply { in_reply_to } => Some(in_reply_to.event_id),
_ => None,
});
(nc.body, nc.formatted, in_reply_to)
},
);
Some((nc.body, nc.formatted, in_reply_to))
} else {
None
}
})
.unwrap_or((content.body, content.formatted, in_reply_to));
let (formatted_body, format) = formatted.map_or(Default::default(), |f| {
(Some(f.body), Some(f.format.as_str().into()))
});
......
......@@ -5,17 +5,17 @@ use anyhow::anyhow;
use chrono::DateTime;
use chrono::Utc;
use either::Either;
use log::{debug, info, warn};
use matrix_sdk::api::r0::sync::sync_events::Response as SyncResponse;
use log::{debug, info};
use matrix_sdk::deserialized_responses::SyncResponse;
use matrix_sdk::directory::PublicRoomsChunk;
use matrix_sdk::events::{
room::member::{MemberEventContent, MembershipState},
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent,
SyncStateEvent,
AnyBasicEvent, AnyBasicEventContent, AnyMessageEventContent, AnyStrippedStateEvent,
AnySyncEphemeralRoomEvent, AnySyncRoomEvent, AnySyncStateEvent, SyncStateEvent,
};
use matrix_sdk::identifiers::{EventId, RoomAliasId, RoomId, UserId};
use matrix_sdk::Raw;
use serde::{Deserialize, Serialize};
use serde_json::value::Value;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::{TryFrom, TryInto};
use url::{ParseError as UrlError, Url};
......@@ -163,53 +163,23 @@ impl Room {
pub fn from_sync_response(response: &SyncResponse, user_id: UserId) -> Vec<Self> {
// getting the list of direct rooms
let direct: HashSet<RoomId> = response.account_data.events
.iter()
.cloned()
// Synapse sometimes sends an object with the key "[object Object]"
// instead of a user ID. Since we don't need the key, we use our own
// event type so it accepts that.
// There's always at most one object of this type.
.find_map(|ev| {
Raw::<CustomDirectEvent>::from_json(ev.into_json())
.deserialize()
.ok()
})
.map_or(Default::default(), |direct_event| {
direct_event.content.values().flatten().cloned().collect()
});
/*
response.rooms.join.iter().for_each(|(_, room)| {
room.state.events.iter().for_each(|ev| log::info!("stevents: {}", ev.json().get()));
});
*/
let joined_rooms = response.rooms.join.iter().map(|(k, room)| {
let stevents: Vec<_> = room
.state
.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
})
.filter_map(Result::ok)
.collect();
let dataevs: Vec<_> = room
let direct: HashSet<RoomId> = response
.account_data
.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
.filter_map(|event| {
if let AnyBasicEventContent::Direct(content) = event.content() {
Some(content.values().flatten().cloned().collect::<Vec<RoomId>>())
} else {
None
}
})
.filter_map(Result::ok)
.flatten()
.collect();
let joined_rooms = response.rooms.join.iter().map(|(k, room)| {
let stevents: Vec<_> = room.state.events.iter().collect();
let dataevs: Vec<_> = room.account_data.events.iter().collect();
let room_tag = dataevs
.iter()
.find_map(|event| match event {
......@@ -274,28 +244,14 @@ impl Room {
_ => None,
}),
direct: direct.contains(&k),
notifications: room
.unread_notifications
.notification_count
.map(Into::into)
.unwrap_or_default(),
highlight: room
.unread_notifications
.highlight_count
.map(Into::into)
.unwrap_or_default(),
notifications: room.unread_notifications.notification_count,
highlight: room.unread_notifications.highlight_count,
prev_batch: room.timeline.prev_batch.clone(),
messages: room
.timeline
.events
.iter()
.map(|ev| Ok((k.clone(), ev.deserialize()?)))
.inspect(|result_ev: &Result<_, serde_json::Error>| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
})
.filter_map(|k_ev| k_ev.ok()?.try_into().ok())
.filter_map(|event| (k.clone(), event.clone()).try_into().ok())
.collect(),
admins: stevents
.iter()
......@@ -335,15 +291,8 @@ impl Room {
.ephemeral
.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
})
.filter_map(Result::ok)
.filter_map(|event| match event {
AnySyncEphemeralRoomEvent::Receipt(ev) => Some(ev.content.0),
AnySyncEphemeralRoomEvent::Receipt(ev) => Some(ev.content.0.clone()),
_ => None,
})
.take(1)
......@@ -387,22 +336,10 @@ impl Room {
})
.for_each(|(msg, receipt)| msg.set_receipt(receipt));
if let Some(event_id) = room
.ephemeral
.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
})
.filter_map(Result::ok)
.find_map(|event| match event {
AnySyncEphemeralRoomEvent::FullyRead(ev) => Some(ev.content.event_id),
if let Some(event_id) = room.ephemeral.events.iter().find_map(|event| match event {
AnySyncEphemeralRoomEvent::FullyRead(ev) => Some(ev.content.event_id.clone()),
_ => None,
})
{
}) {
let event_id = Some(event_id);
r.messages
......@@ -416,31 +353,21 @@ impl Room {
r
});
let left_rooms =
response.rooms.leave.iter().map(|(k, room)| {
let left_rooms = response.rooms.leave.iter().map(|(k, room)| {
// TODO: The spec doesn't explain where to get the reason
// for the kicking from, so matrix-sdk doesn't support
// that.
if let Some(last_event) = room.timeline.events.last().and_then(|ev| {
match serde_json::to_value(ev.json()) {
Ok(event) => Some(event),
Err(err) => {
warn!("Bad event: {}", err);
None
if let Some(last_event) = room.timeline.events.last() {
if let AnySyncRoomEvent::Message(message) = last_event {
let kicker = message.sender().clone();
if kicker != user_id {
if let AnyMessageEventContent::Custom(message) = message.content() {
if let Value::String(kick_reason) = &message.json["reason"] {
let reason = Reason::Kicked(kick_reason.clone(), kicker);
return Self::new(k.clone(), RoomMembership::Left(reason));
}
}
}
}) {
if let Some(kicker) =
UserId::try_from(last_event["sender"].as_str().unwrap_or_default())
.ok()
.filter(|leave_uid| *leave_uid != user_id)
{
let kick_reason = &last_event["content"]["reason"];
let reason = Reason::Kicked(
String::from(kick_reason.as_str().unwrap_or_default()),
kicker,
);
return Self::new(k.clone(), RoomMembership::Left(reason));
}
};
......@@ -448,18 +375,7 @@ impl Room {
});
let invited_rooms = response.rooms.invite.iter().filter_map(|(k, room)| {
let stevents: Vec<_> = room
.invite_state
.events
.iter()
.map(|ev| ev.deserialize())
.inspect(|result_ev| {
if let Err(err) = result_ev {
warn!("Bad event: {}", err);
}
})
.filter_map(Result::ok)
.collect();
let stevents: Vec<_> = room.invite_state.events.iter().collect();
let inv_sender = stevents
.iter()
.find_map(|event| match event {
......
......@@ -181,7 +181,7 @@ impl<'a> Address<'a> {
match action {
Some(AddressAction::Delete) => {
if let Some(address) = address.clone() {
RUNTIME.handle().block_on(delete_address(
RUNTIME.block_on(delete_address(
medium,
address,
session_client.homeserver().clone(),
......
......@@ -98,7 +98,7 @@ impl LoginWidget {
};
let query = get_well_known(homeserver_url.clone());
let (homeserver_url, idserver) = RUNTIME.handle().block_on(query)
let (homeserver_url, idserver) = RUNTIME.block_on(query)
.and_then(|response| {
let hs_url = Url::parse(&response.homeserver.base_url)?;
let ids = response
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment