mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 02:55:47 -04:00
Map MSC3488 fields for UniFFI (#2187)
* Update ruma * Refactor send_location * Add timeline parser * Fix code format * Add zoom_level * Update ruma * Map zoom_level * Format code * Cleanup * Refactor LocationContent * Apply suggestion * Fix format issue
This commit is contained in:
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -4204,7 +4204,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
@@ -4219,7 +4219,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.8.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
@@ -4230,7 +4230,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.16.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"bytes",
|
||||
@@ -4247,7 +4247,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.11.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"base64 0.21.2",
|
||||
"bytes",
|
||||
@@ -4280,7 +4280,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
@@ -4291,7 +4291,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.9.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror",
|
||||
@@ -4300,7 +4300,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.11.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro-crate",
|
||||
@@ -4315,7 +4315,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.7.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cf32036df4c9daca736dcd7f0d9d65debcf9897f#cf32036df4c9daca736dcd7f0d9d65debcf9897f"
|
||||
source = "git+https://github.com/ruma/ruma?rev=5fde57460aaa71e16ac68f79376843089f9c3dfc#5fde57460aaa71e16ac68f79376843089f9c3dfc"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
|
||||
@@ -36,8 +36,8 @@ futures-executor = "0.3.21"
|
||||
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
|
||||
http = "0.2.6"
|
||||
itertools = "0.10.5"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "cf32036df4c9daca736dcd7f0d9d65debcf9897f", features = ["client-api-c", "compat-user-id"] }
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "cf32036df4c9daca736dcd7f0d9d65debcf9897f" }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "5fde57460aaa71e16ac68f79376843089f9c3dfc", features = ["client-api-c", "compat-user-id"] }
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "5fde57460aaa71e16ac68f79376843089f9c3dfc" }
|
||||
once_cell = "1.16.0"
|
||||
serde = "1.0.151"
|
||||
serde_html_form = "0.2.0"
|
||||
|
||||
@@ -36,7 +36,7 @@ mime = "0.3.16"
|
||||
once_cell = { workspace = true }
|
||||
opentelemetry = { version = "0.19.0", features = ["rt-tokio"] }
|
||||
opentelemetry-otlp = { version = "0.12.0", features = ["tokio", "reqwest-client", "http-proto"] }
|
||||
ruma = { workspace = true, features = ["unstable-sanitize", "unstable-unspecified"] }
|
||||
ruma = { workspace = true, features = ["unstable-sanitize", "unstable-unspecified", "unstable-msc3488"] }
|
||||
sanitize-filename-reader-friendly = "2.2.1"
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
@@ -11,6 +11,7 @@ use matrix_sdk::{
|
||||
ruma::{
|
||||
api::client::{receipt::create_receipt::v3::ReceiptType, room::report_content},
|
||||
events::{
|
||||
location::{AssetType as RumaAssetType, LocationContent, ZoomLevel},
|
||||
receipt::ReceiptThread,
|
||||
relation::{Annotation, Replacement},
|
||||
room::message::{
|
||||
@@ -806,8 +807,28 @@ impl Room {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_location(&self, body: String, geo_uri: String, txn_id: Option<String>) {
|
||||
let location_event_message_content = LocationMessageEventContent::new(body, geo_uri);
|
||||
pub fn send_location(
|
||||
&self,
|
||||
body: String,
|
||||
geo_uri: String,
|
||||
description: Option<String>,
|
||||
zoom_level: Option<u8>,
|
||||
asset_type: Option<AssetType>,
|
||||
txn_id: Option<String>,
|
||||
) {
|
||||
let mut location_event_message_content =
|
||||
LocationMessageEventContent::new(body, geo_uri.clone());
|
||||
|
||||
if let Some(asset_type) = asset_type {
|
||||
location_event_message_content =
|
||||
location_event_message_content.with_asset_type(RumaAssetType::from(asset_type));
|
||||
}
|
||||
|
||||
let mut location_content = LocationContent::new(geo_uri);
|
||||
location_content.description = description;
|
||||
location_content.zoom_level = zoom_level.and_then(ZoomLevel::new);
|
||||
location_event_message_content.location = Some(location_content);
|
||||
|
||||
let room_message_event_content =
|
||||
RoomMessageEventContent::new(MessageType::Location(location_event_message_content));
|
||||
self.send(Arc::new(room_message_event_content), txn_id)
|
||||
@@ -967,3 +988,18 @@ impl From<PaginationOptions> for matrix_sdk_ui::timeline::PaginationOptions<'sta
|
||||
opts
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, uniffi::Enum)]
|
||||
pub enum AssetType {
|
||||
Sender,
|
||||
Pin,
|
||||
}
|
||||
|
||||
impl From<AssetType> for RumaAssetType {
|
||||
fn from(value: AssetType) -> Self {
|
||||
match value {
|
||||
AssetType::Sender => Self::Self_,
|
||||
AssetType::Pin => Self::Pin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,25 @@ use extension_trait::extension_trait;
|
||||
use eyeball_im::VectorDiff;
|
||||
use matrix_sdk::{
|
||||
attachment::{BaseAudioInfo, BaseFileInfo, BaseImageInfo, BaseThumbnailInfo, BaseVideoInfo},
|
||||
ruma::events::room::{
|
||||
message::{
|
||||
AudioInfo as RumaAudioInfo, AudioMessageEventContent as RumaAudioMessageEventContent,
|
||||
EmoteMessageEventContent as RumaEmoteMessageEventContent, FileInfo as RumaFileInfo,
|
||||
FileMessageEventContent as RumaFileMessageEventContent,
|
||||
FormattedBody as RumaFormattedBody,
|
||||
ImageMessageEventContent as RumaImageMessageEventContent,
|
||||
LocationMessageEventContent as RumaLocationMessageEventContent,
|
||||
MessageType as RumaMessageType,
|
||||
NoticeMessageEventContent as RumaNoticeMessageEventContent, RoomMessageEventContent,
|
||||
TextMessageEventContent as RumaTextMessageEventContent, VideoInfo as RumaVideoInfo,
|
||||
VideoMessageEventContent as RumaVideoMessageEventContent,
|
||||
ruma::events::{
|
||||
location::AssetType as RumaAssetType,
|
||||
room::{
|
||||
message::{
|
||||
AudioInfo as RumaAudioInfo,
|
||||
AudioMessageEventContent as RumaAudioMessageEventContent,
|
||||
EmoteMessageEventContent as RumaEmoteMessageEventContent, FileInfo as RumaFileInfo,
|
||||
FileMessageEventContent as RumaFileMessageEventContent,
|
||||
FormattedBody as RumaFormattedBody,
|
||||
ImageMessageEventContent as RumaImageMessageEventContent,
|
||||
LocationMessageEventContent as RumaLocationMessageEventContent,
|
||||
MessageType as RumaMessageType,
|
||||
NoticeMessageEventContent as RumaNoticeMessageEventContent,
|
||||
RoomMessageEventContent, TextMessageEventContent as RumaTextMessageEventContent,
|
||||
VideoInfo as RumaVideoInfo,
|
||||
VideoMessageEventContent as RumaVideoMessageEventContent,
|
||||
},
|
||||
ImageInfo as RumaImageInfo, MediaSource, ThumbnailInfo as RumaThumbnailInfo,
|
||||
},
|
||||
ImageInfo as RumaImageInfo, MediaSource, ThumbnailInfo as RumaThumbnailInfo,
|
||||
},
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{Profile, TimelineDetails};
|
||||
@@ -28,6 +33,7 @@ use tracing::warn;
|
||||
use crate::{
|
||||
error::{ClientError, TimelineError},
|
||||
helpers::unwrap_or_clone_arc,
|
||||
room::AssetType,
|
||||
};
|
||||
|
||||
#[uniffi::export]
|
||||
@@ -621,9 +627,23 @@ impl TryFrom<RumaMessageType> for MessageType {
|
||||
formatted: c.formatted.as_ref().map(Into::into),
|
||||
},
|
||||
},
|
||||
RumaMessageType::Location(c) => MessageType::Location {
|
||||
content: LocationContent { body: c.body, geo_uri: c.geo_uri },
|
||||
},
|
||||
RumaMessageType::Location(c) => {
|
||||
let (description, zoom_level) =
|
||||
c.location.map(|loc| (loc.description, loc.zoom_level)).unwrap_or((None, None));
|
||||
MessageType::Location {
|
||||
content: LocationContent {
|
||||
body: c.body,
|
||||
geo_uri: c.geo_uri,
|
||||
description,
|
||||
zoom_level: zoom_level.and_then(|z| z.get().try_into().ok()),
|
||||
asset: c.asset.and_then(|a| match a.type_ {
|
||||
RumaAssetType::Self_ => Some(AssetType::Sender),
|
||||
RumaAssetType::Pin => Some(AssetType::Pin),
|
||||
_ => None,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
_ => bail!("Unsupported type"),
|
||||
};
|
||||
Ok(message_type)
|
||||
@@ -870,6 +890,9 @@ pub struct TextMessageContent {
|
||||
pub struct LocationContent {
|
||||
pub body: String,
|
||||
pub geo_uri: String,
|
||||
pub description: Option<String>,
|
||||
pub zoom_level: Option<u8>,
|
||||
pub asset: Option<AssetType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, uniffi::Record)]
|
||||
|
||||
Reference in New Issue
Block a user