Commit 1aff564e authored by Kévin Commaille's avatar Kévin Commaille Committed by Julian Sparber
Browse files

bump matrix-sdk to ebcb2024d14614b8c984c5b95de5df04eec7933b

Get an updated ruma to handle push rules.
parent bde79fcc
Pipeline #274872 passed with stages
in 58 minutes and 40 seconds
This diff is collapsed.
......@@ -79,5 +79,5 @@ features = ["serde"]
[dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk.git"
rev = "e437aea01213338d7f11787411a025b6133efcff"
rev = "ebcb2024d14614b8c984c5b95de5df04eec7933b"
features = ["unstable-synapse-quirks", "socks"]
......@@ -12,7 +12,6 @@ use matrix_sdk::{
},
identifiers::{RoomId, UserId},
};
use url::Url;
#[derive(Debug, Clone, Copy)]
pub enum SearchType {
......@@ -47,11 +46,7 @@ impl AppOp {
}
MembershipState::Join => {
let m = Member {
avatar: ev
.content
.avatar_url
.and_then(|u| Url::parse(&u).ok())
.map(Either::Left),
avatar: ev.content.avatar_url.map(Either::Left),
alias: ev.content.displayname,
uid: sender,
};
......
......@@ -616,7 +616,7 @@ async fn attach_file(session_client: MatrixClient, mut msg: Message) -> Result<(
let thumb_url = extra_content.clone().and_then(|c| c.info.thumbnail_url);
match (msg.url.clone(), msg.local_path.as_ref(), thumb_url) {
(Some(url), _, Some(thumb)) if url.scheme() == "mxc" && thumb.scheme() == "mxc" => {
(Some(_), _, Some(_)) => {
send_msg_and_manage(session_client, msg).await;
Ok(())
......@@ -625,7 +625,7 @@ async fn attach_file(session_client: MatrixClient, mut msg: Message) -> Result<(
if let Some(ref local_path_thumb) = msg.local_path_thumb {
let response = room::upload_file(session_client.clone(), local_path_thumb)
.await
.and_then(|response| Url::parse(&response.content_uri).map_err(Into::into));
.map(|response| response.content_uri);
match response {
Ok(thumb_uri) => {
......@@ -648,7 +648,7 @@ async fn attach_file(session_client: MatrixClient, mut msg: Message) -> Result<(
let query = room::upload_file(session_client.clone(), &local_path)
.await
.and_then(|response| {
msg.url = Some(Url::parse(&response.content_uri)?);
msg.url = Some(response.content_uri);
RUNTIME.spawn(send_msg_and_manage(session_client, msg.clone()));
Ok(msg)
......
use crate::backend::room;
use crate::util::i18n::{i18n, i18n_k, ni18n_f};
use log::{error, warn};
use matrix_sdk::events::EventType;
use matrix_sdk::identifiers::RoomId;
use matrix_sdk::{events::EventType, identifiers::MxcUri};
use std::convert::TryInto;
use std::fs::remove_file;
use std::os::unix::fs;
use url::Url;
use gtk::prelude::*;
......@@ -442,7 +441,7 @@ impl AppOp {
}
}
pub fn set_room_avatar(&mut self, room_id: RoomId, avatar: Option<Url>) {
pub fn set_room_avatar(&mut self, room_id: RoomId, avatar: Option<MxcUri>) {
let login_data = unwrap_or_unit_return!(self.login_data.clone());
if avatar.is_none() {
if let Ok(dest) = cache_dir_path(None, &room_id.to_string()) {
......
use matrix_sdk::identifiers::{Error as IdentifierError, ServerName};
use matrix_sdk::Client as MatrixClient;
use matrix_sdk::Error as MatrixError;
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;
use url::ParseError as UrlError;
use crate::globals;
......@@ -112,8 +112,8 @@ pub async fn room_search(
let rooms = response
.chunk
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<Room>, UrlError>>()?;
.map(Into::into)
.collect::<Vec<Room>>();
for room in &rooms {
if let Some(avatar) = room.avatar.as_ref() {
......
use super::MediaError;
use crate::globals;
use matrix_sdk::identifiers::{EventId, RoomId};
use matrix_sdk::identifiers::{EventId, MxcUri, RoomId};
use matrix_sdk::{Client as MatrixClient, Error as MatrixError};
use std::convert::TryInto;
use std::path::PathBuf;
use url::Url;
use crate::model::message::Message;
use matrix_sdk::api::r0::filter::{RoomEventFilter, UrlFilter};
......@@ -16,7 +15,7 @@ use super::{dw_media, get_prev_batch_from, ContentType};
pub type MediaResult = Result<PathBuf, MediaError>;
pub type MediaList = (Vec<Message>, String);
pub async fn get_thumb(session_client: MatrixClient, media: &Url) -> MediaResult {
pub async fn get_thumb(session_client: MatrixClient, media: &MxcUri) -> MediaResult {
dw_media(
session_client,
media,
......@@ -26,7 +25,7 @@ pub async fn get_thumb(session_client: MatrixClient, media: &Url) -> MediaResult
.await
}
pub async fn get_media(session_client: MatrixClient, media: &Url) -> MediaResult {
pub async fn get_media(session_client: MatrixClient, media: &MxcUri) -> MediaResult {
dw_media(session_client, media, ContentType::Download, None).await
}
......@@ -74,7 +73,11 @@ async fn get_room_media_list(
})),
});
let response = session_client.room_messages(request).await?;
let room = unwrap_or_notfound_return!(
session_client.get_room(room_id),
format!("Could not find room: {}", room_id)
);
let response = room.messages(request).await?;
let prev_batch = response.end.unwrap_or_default();
......
use lazy_static::lazy_static;
use log::error;
use matrix_sdk::identifiers::{EventId, RoomId, ServerName};
use matrix_sdk::identifiers::{Error as IdentifierError, EventId, MxcUri, RoomId};
use matrix_sdk::{
api::{error::ErrorKind as RumaErrorKind, Error as RumaClientError},
Client as MatrixClient, Error as MatrixError, FromHttpResponseError, HttpError, ServerError,
};
use regex::Regex;
use std::convert::TryFrom;
use std::fmt::Debug;
use std::io::Error as IoError;
use std::path::PathBuf;
use url::Url;
use crate::client::Client;
use crate::util::cache_dir_path;
......@@ -68,7 +66,6 @@ pub async fn get_prev_batch_from(
#[derive(Debug)]
pub enum MediaError {
MalformedMxcUrl,
Io(IoError),
Matrix(MatrixError),
}
......@@ -89,38 +86,21 @@ impl HandleError for MediaError {}
pub async fn dw_media(
session_client: MatrixClient,
mxc: &Url,
mxc: &MxcUri,
media_type: ContentType,
dest: Option<PathBuf>,
) -> Result<PathBuf, MediaError> {
if mxc.scheme() != "mxc" {
return Err(MediaError::MalformedMxcUrl);
if !mxc.is_valid() {
return Err(MatrixError::from(IdentifierError::InvalidMxcUri).into());
}
let server_name = mxc
.host()
.as_ref()
.map(ToString::to_string)
.and_then(|host| {
<&ServerName>::try_from(host.as_str())
.map(ToOwned::to_owned)
.ok()
})
.ok_or(MediaError::MalformedMxcUrl)?;
let media_id = mxc
.path_segments()
.and_then(|mut ps| ps.next())
.filter(|s| !s.is_empty())
.ok_or(MediaError::MalformedMxcUrl)?;
let default_fname = || {
let dir = if media_type.is_thumbnail() {
"thumbs"
} else {
"medias"
};
cache_dir_path(Some(dir), &media_id)
cache_dir_path(Some(dir), mxc.media_id().unwrap())
};
let fname = dest.clone().map_or_else(default_fname, Ok)?;
......@@ -137,18 +117,17 @@ pub async fn dw_media(
}
let media = if let ContentType::Thumbnail(width, height) = media_type {
let request = assign!(GetContentThumbnailRequest::new(
&media_id,
&server_name,
let request = assign!(GetContentThumbnailRequest::from_url(
mxc,
width.into(),
height.into(),
), {
).unwrap(), {
method: Some(Method::Crop),
});
session_client.send(request, None).await?.file
} else {
let request = GetContentRequest::new(&media_id, &server_name);
let request = GetContentRequest::from_url(mxc).unwrap();
session_client.send(request, None).await?.file
};
......
......@@ -3,16 +3,15 @@ use serde_json::json;
use matrix_sdk::{
api::error::ErrorKind as RumaErrorKind,
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
identifiers::{EventId, MxcUri, RoomId, RoomIdOrAliasId, UserId},
Client as MatrixClient, Error as MatrixError, FromHttpResponseError, HttpError, ServerError,
};
use serde::Serialize;
use std::io::Error as IoError;
use std::path::Path;
use url::{ParseError as UrlError, Url};
use url::ParseError as UrlError;
use std::convert::{TryFrom, TryInto};
use std::time::Duration;
use crate::globals;
......@@ -42,10 +41,9 @@ use matrix_sdk::api::r0::room::create_room::Request as CreateRoomRequest;
use matrix_sdk::api::r0::room::create_room::RoomPreset;
use matrix_sdk::api::r0::room::Visibility;
use matrix_sdk::api::r0::state::get_state_events_for_key::Request as GetStateEventForKeyRequest;
use matrix_sdk::api::r0::state::send_state_event_for_key::Request as SendStateEventForKeyRequest;
use matrix_sdk::api::r0::state::send_state_event::Request as SendStateEventForKeyRequest;
use matrix_sdk::api::r0::tag::create_tag::Request as CreateTagRequest;
use matrix_sdk::api::r0::tag::delete_tag::Request as DeleteTagRequest;
use matrix_sdk::api::r0::typing::create_typing_event::Typing;
use matrix_sdk::assign;
use matrix_sdk::events::room::avatar::AvatarEventContent;
use matrix_sdk::events::room::history_visibility::HistoryVisibility;
......@@ -154,7 +152,7 @@ impl HandleError for RoomAvatarError {}
pub async fn get_room_avatar(
session_client: MatrixClient,
room_id: RoomId,
) -> Result<(RoomId, Option<Url>), RoomAvatarError> {
) -> Result<(RoomId, Option<MxcUri>), RoomAvatarError> {
let request = GetStateEventForKeyRequest::new(&room_id, EventType::RoomAvatar, "");
let response = match session_client.send(request, None).await {
......@@ -166,7 +164,7 @@ pub async fn get_room_avatar(
let avatar = if let Some(res) = response {
serde_json::to_value(&res.content)?["url"]
.as_str()
.and_then(|s| Url::parse(s).ok())
.and_then(|s| MxcUri::try_from(s).ok())
} else {
None
};
......@@ -213,11 +211,7 @@ pub async fn get_room_members(
let request = JoinedMembersRequest::new(&room_id);
let response = session_client.send(request, None).await?;
let ms = response
.joined
.into_iter()
.map(Member::try_from)
.collect::<Result<_, UrlError>>()?;
let ms = response.joined.into_iter().map(Into::into).collect();
Ok((room_id, ms))
}
......@@ -254,7 +248,11 @@ pub async fn get_room_messages(
})),
});
let response = session_client.room_messages(request).await?;
let room = unwrap_or_notfound_return!(
session_client.get_room(&room_id),
format!("Could not find room: {}", room_id)
);
let response = room.messages(request).await?;
let prev_batch = response.end;
let list: Vec<Message> = response
......@@ -365,9 +363,9 @@ pub async fn send_msg(session_client: MatrixClient, msg: Message) -> Result<Even
#[derive(Debug)]
pub struct SendTypingError(MatrixError);
impl From<MatrixError> for SendTypingError {
fn from(err: MatrixError) -> Self {
Self(err)
impl<T: Into<MatrixError>> From<T> for SendTypingError {
fn from(err: T) -> Self {
Self(err.into())
}
}
......@@ -377,9 +375,11 @@ pub async fn send_typing(
session_client: MatrixClient,
room_id: &RoomId,
) -> Result<(), SendTypingError> {
session_client
.typing_notice(room_id, Typing::Yes(Duration::from_secs(4)))
.await?;
let room = unwrap_or_notfound_return!(
session_client.get_joined_room(room_id),
format!("Could not find room: {}", room_id)
);
room.typing_notice(true).await?;
Ok(())
}
......@@ -459,9 +459,9 @@ pub async fn join_room(
#[derive(Debug)]
pub struct LeaveRoomError(MatrixError);
impl From<MatrixError> for LeaveRoomError {
fn from(err: MatrixError) -> Self {
Self(err)
impl<T: Into<MatrixError>> From<T> for LeaveRoomError {
fn from(err: T) -> Self {
Self(err.into())
}
}
......@@ -471,7 +471,11 @@ pub async fn leave_room(
session_client: MatrixClient,
room_id: &RoomId,
) -> Result<(), LeaveRoomError> {
session_client.leave_room(room_id).await?;
let room = unwrap_or_notfound_return!(
session_client.get_joined_room(room_id),
format!("Could not find room: {}", room_id)
);
room.leave().await?;
Ok(())
}
......@@ -479,9 +483,9 @@ pub async fn leave_room(
#[derive(Debug)]
pub struct MarkedAsReadError(MatrixError);
impl From<MatrixError> for MarkedAsReadError {
fn from(err: MatrixError) -> Self {
Self(err)
impl<T: Into<MatrixError>> From<T> for MarkedAsReadError {
fn from(err: T) -> Self {
Self(err.into())
}
}
......@@ -492,9 +496,11 @@ pub async fn mark_as_read(
room_id: RoomId,
event_id: EventId,
) -> Result<(RoomId, EventId), MarkedAsReadError> {
session_client
.read_marker(&room_id, &event_id, Some(&event_id))
.await?;
let room = unwrap_or_notfound_return!(
session_client.get_joined_room(&room_id),
format!("Could not find room: {}", room_id)
);
room.read_marker(&event_id, Some(&event_id)).await?;
Ok((room_id, event_id))
}
......@@ -841,9 +847,9 @@ pub async fn add_to_fav(
#[derive(Debug)]
pub struct InviteError(MatrixError);
impl From<MatrixError> for InviteError {
fn from(err: MatrixError) -> Self {
Self(err)
impl<T: Into<MatrixError>> From<T> for InviteError {
fn from(err: T) -> Self {
Self(err.into())
}
}
......@@ -854,7 +860,11 @@ pub async fn invite(
room_id: &RoomId,
user_id: &UserId,
) -> Result<(), InviteError> {
session_client.invite_user_by_id(room_id, user_id).await?;
let room = unwrap_or_notfound_return!(
session_client.get_joined_room(room_id),
format!("Could not find room: {}", room_id)
);
room.invite_user_by_id(user_id).await?;
Ok(())
}
......
......@@ -11,7 +11,6 @@ use crate::appop::UserInfoCache;
use crate::backend::HTTP_CLIENT;
use crate::util::cache_dir_path;
use log::error;
use std::convert::TryInto;
use std::path::PathBuf;
use super::room::AttachedFileError;
......@@ -496,12 +495,7 @@ pub async fn search(
let request = UserDirectoryRequest::new(search_term);
let response = session_client.send(request, None).await?;
response
.results
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, UrlError>>()
.map_err(Into::into)
Ok(response.results.into_iter().map(Into::into).collect())
}
#[derive(Debug)]
......@@ -538,16 +532,12 @@ pub async fn get_user_avatar(
let request = GetProfileRequest::new(user_id);
let response = session_client.send(request, None).await?;
let img = match response
.avatar_url
.map(|url| Url::parse(&url))
.transpose()?
.map(|url| {
(
url,
cache_dir_path(None, user_id.as_str()).map_err(MediaError::from),
)
}) {
let img = match response.avatar_url.map(|url| {
(
url,
cache_dir_path(None, user_id.as_str()).map_err(MediaError::from),
)
}) {
Some((url, Ok(dest))) => {
dw_media(
session_client,
......
......@@ -5,13 +5,12 @@ use async_trait::async_trait;
use gio::prelude::*;
use matrix_sdk::{
reqwest, Client as MatrixClient, ClientConfig as MatrixClientConfig, Error as MatrixSdkError,
HttpError, HttpSend,
HttpError, HttpSend, RequestConfig,
};
use url::Url;
use std::convert::TryInto;
use std::sync::{Arc, Mutex};
use std::time::Duration;
// Special URI used by gio to indicate no proxy
const PROXY_DIRECT_URI: &str = "direct://";
......@@ -133,9 +132,9 @@ impl HttpSend for Client {
async fn send_request(
&self,
req: http::Request<Vec<u8>>,
duration: Option<Duration>,
config: RequestConfig,
) -> Result<http::Response<Vec<u8>>, HttpError> {
self.get_client().send_request(req, duration).await
self.get_client().send_request(req, config).await
}
}
......
......@@ -2,15 +2,15 @@
#[macro_use]
extern crate glib;
#[macro_use]
mod util;
mod api;
mod backend;
mod cache;
mod client;
mod config;
mod error;
mod globals;
#[macro_use]
mod util;
mod cache;
mod model;
mod passwd;
mod ui;
......
use matrix_sdk::identifiers::MxcUri;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use url::Url;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Info {
pub thumbnail_url: Option<Url>,
pub thumbnail_url: Option<MxcUri>,
pub thumbnail_info: Option<JsonValue>,
pub w: Option<u32>,
pub h: Option<u32>,
......
use either::Either;
use matrix_sdk::api::r0::membership::joined_members::RoomMember;
use matrix_sdk::api::r0::user_directory::search_users::User;
use matrix_sdk::identifiers::UserId;
use matrix_sdk::{api::r0::membership::joined_members::RoomMember, identifiers::MxcUri};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::path::PathBuf;
use url::{ParseError as UrlError, Url};
#[derive(Debug, Clone)]
pub struct Member {
pub uid: UserId,
pub alias: Option<String>,
pub avatar: Option<Either<Url, PathBuf>>,
pub avatar: Option<Either<MxcUri, PathBuf>>,
}
impl Member {
......@@ -31,37 +29,23 @@ impl PartialEq for Member {
}
}
impl TryFrom<User> for Member {
type Error = UrlError;
fn try_from(user: User) -> Result<Self, Self::Error> {
Ok(Self {
impl From<User> for Member {
fn from(user: User) -> Self {
Self {
uid: user.user_id,
alias: user.display_name,
avatar: user
.avatar_url
.filter(|a| !a.is_empty())
.map(|url| Url::parse(&url))
.transpose()?
.map(Either::Left),
})
avatar: user.avatar_url.map(Either::Left),
}
}
}
impl TryFrom<(UserId, RoomMember)> for Member {
type Error = UrlError;
fn try_from((uid, roommember): (UserId, RoomMember)) -> Result<Self, Self::Error> {
Ok(Member {
impl From<(UserId, RoomMember)> for Member {
fn from((uid, roommember): (UserId, RoomMember)) -> Self {
Self {
uid,
alias: roommember.display_name,
avatar: roommember
.avatar_url
.filter(|url| !url.is_empty())
.map(|url| Url::parse(&url))
.transpose()?
.map(Either::Left),
})
avatar: roommember.avatar_url.map(Either::Left),
}
}
}
......
......@@ -2,19 +2,18 @@ use chrono::prelude::*;
use chrono::DateTime;
use matrix_sdk::{
events::{
room::message::{MessageEventContent, RedactedMessageEventContent, Relation},
room::message::{MessageEventContent, MessageType, RedactedMessageEventContent, Relation},
sticker::{RedactedStickerEventContent, StickerEventContent},
AnyMessageEvent, AnyRedactedMessageEvent, AnyRedactedSyncMessageEvent, AnyRoomEvent,
AnySyncMessageEvent, AnySyncRoomEvent, EventContent, MessageEvent, RedactedMessageEvent,
},
identifiers::{EventId, RoomId, UserId},
identifiers::{EventId, MxcUri, RoomId, UserId},
};
use serde_json::Value as JsonValue;