change(matrix_sdk::Room): Return the used EncryptionInfo when sending MessageLike and RawMessageLike events
This commit is contained in:
committed by
Damir Jelić
parent
b7d22da9f0
commit
8bd401b003
@@ -286,7 +286,7 @@ impl UserIdentity {
|
||||
self.client.create_dm(i.user_id()).await?
|
||||
};
|
||||
|
||||
let response = room.send(RoomMessageEventContent::new(content)).await?;
|
||||
let (response, _) = room.send(RoomMessageEventContent::new(content)).await?;
|
||||
|
||||
let verification =
|
||||
i.request_verification(room.room_id(), &response.event_id, methods);
|
||||
|
||||
@@ -617,6 +617,7 @@ impl Client {
|
||||
.send(*content)
|
||||
.with_transaction_id(txn_id)
|
||||
.await
|
||||
.map(|(response, _)| response)
|
||||
}
|
||||
|
||||
pub(crate) async fn send_to_device(
|
||||
|
||||
@@ -21,6 +21,7 @@ use std::borrow::Borrow;
|
||||
use std::future::IntoFuture;
|
||||
|
||||
use eyeball::SharedObservable;
|
||||
use matrix_sdk_base::deserialized_responses::EncryptionInfo;
|
||||
use matrix_sdk_common::boxed_into_future;
|
||||
use mime::Mime;
|
||||
#[cfg(doc)]
|
||||
@@ -95,7 +96,7 @@ impl<'a> SendMessageLikeEvent<'a> {
|
||||
}
|
||||
|
||||
impl<'a> IntoFuture for SendMessageLikeEvent<'a> {
|
||||
type Output = Result<send_message_event::v3::Response>;
|
||||
type Output = Result<(send_message_event::v3::Response, Option<EncryptionInfo>)>;
|
||||
boxed_into_future!(extra_bounds: 'a);
|
||||
|
||||
fn into_future(self) -> Self::IntoFuture {
|
||||
@@ -163,7 +164,7 @@ impl<'a> SendRawMessageLikeEvent<'a> {
|
||||
}
|
||||
|
||||
impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> {
|
||||
type Output = Result<send_message_event::v3::Response>;
|
||||
type Output = Result<(send_message_event::v3::Response, Option<EncryptionInfo>)>;
|
||||
boxed_into_future!(extra_bounds: 'a);
|
||||
|
||||
fn into_future(self) -> Self::IntoFuture {
|
||||
@@ -186,6 +187,11 @@ impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> {
|
||||
#[cfg(not(feature = "e2e-encryption"))]
|
||||
trace!("Sending plaintext event to room because we don't have encryption support.");
|
||||
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
let mut encryption_info: Option<EncryptionInfo> = None;
|
||||
#[cfg(not(feature = "e2e-encryption"))]
|
||||
let encryption_info: Option<EncryptionInfo> = None;
|
||||
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
if room.latest_encryption_state().await?.is_encrypted() {
|
||||
Span::current().record("is_room_encrypted", true);
|
||||
@@ -207,6 +213,7 @@ impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> {
|
||||
let result =
|
||||
olm.encrypt_room_event_raw(room.room_id(), event_type, &content).await?;
|
||||
content = result.content.cast();
|
||||
encryption_info = Some(result.encryption_info);
|
||||
event_type = "m.room.encrypted";
|
||||
}
|
||||
} else {
|
||||
@@ -226,7 +233,7 @@ impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> {
|
||||
Span::current().record("event_id", tracing::field::debug(&response.event_id));
|
||||
info!("Sent event in room");
|
||||
|
||||
Ok(response)
|
||||
Ok((response, encryption_info))
|
||||
};
|
||||
|
||||
Box::pin(fut.instrument(tracing_span))
|
||||
|
||||
@@ -2643,7 +2643,8 @@ impl Room {
|
||||
if let Some(txn_id) = txn_id {
|
||||
fut = fut.with_transaction_id(txn_id);
|
||||
}
|
||||
fut.await
|
||||
|
||||
fut.await.map(|(response, _)| response)
|
||||
}
|
||||
|
||||
/// Creates the inner [`MessageType`] for an already-uploaded media file
|
||||
@@ -3829,7 +3830,7 @@ impl Room {
|
||||
|
||||
if beacon_info_event.content.is_live() {
|
||||
let content = BeaconEventContent::new(beacon_info_event.event_id, geo_uri, None);
|
||||
Ok(self.send(content).await?)
|
||||
Ok(self.send(content).await?.0)
|
||||
} else {
|
||||
Err(BeaconError::NotLive)
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ impl MatrixDriver {
|
||||
|
||||
Ok(match (state_key, delayed_event_parameters) {
|
||||
(None, None) => SendEventResponse::from_event_id(
|
||||
self.room.send_raw(&type_str, content).await?.event_id,
|
||||
self.room.send_raw(&type_str, content).await?.0.event_id,
|
||||
),
|
||||
|
||||
(Some(key), None) => SendEventResponse::from_event_id(
|
||||
|
||||
@@ -85,6 +85,7 @@ async fn test_shared_history_out_of_order() {
|
||||
.send(RoomMessageEventContent::text_plain("It's a secret to everybody"))
|
||||
.await
|
||||
.expect("We should be able to send an initial message")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
matrix_mock_server
|
||||
|
||||
@@ -734,7 +734,7 @@ async fn test_room_message_send() {
|
||||
|
||||
let content = RoomMessageEventContent::text_plain("Hello world");
|
||||
let txn_id = TransactionId::new();
|
||||
let response = room.send(content).with_transaction_id(txn_id).await.unwrap();
|
||||
let response = room.send(content).with_transaction_id(txn_id).await.unwrap().0;
|
||||
|
||||
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id)
|
||||
}
|
||||
|
||||
@@ -398,7 +398,8 @@ async fn test_nothing_sent_when_disabled() {
|
||||
mock.mock_room_state_encryption().plain().mount().await;
|
||||
mock.mock_room_send().ok(event_id).expect(1).mount().await;
|
||||
|
||||
let response = room.send(RoomMessageEventContent::text_plain("Hello, World!")).await.unwrap();
|
||||
let (response, _) =
|
||||
room.send(RoomMessageEventContent::text_plain("Hello, World!")).await.unwrap();
|
||||
assert_eq!(response.event_id, event_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -938,7 +938,8 @@ async fn test_secret_gossip_after_interactive_verification() -> Result<()> {
|
||||
|
||||
let response = room_first_client
|
||||
.send(RoomMessageEventContent::text_plain("It's a secret to everybody"))
|
||||
.await?;
|
||||
.await?
|
||||
.0;
|
||||
|
||||
let event_id = response.event_id;
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ async fn test_history_share_on_invite_helper(exclude_insecure_devices: bool) ->
|
||||
.send(RoomMessageEventContent::text_plain("Hello Bob"))
|
||||
.await
|
||||
.expect("We should be able to send a message to the room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
let bundle_stream = bob
|
||||
@@ -271,6 +272,7 @@ async fn test_history_share_on_invite_pin_violation() -> Result<()> {
|
||||
.send(RoomMessageEventContent::text_plain("Hello Bob"))
|
||||
.await
|
||||
.expect("We should be able to send a message to the room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
// Let us create some streams to get notified about a received bundle and a
|
||||
@@ -451,6 +453,7 @@ async fn test_transitive_history_share_with_withhelds() -> Result<()> {
|
||||
.instrument(bob_span.clone())
|
||||
.await
|
||||
.expect("We should be able to send a message to the room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
alice
|
||||
@@ -606,6 +609,7 @@ async fn test_history_sharing_session_merging() -> Result<()> {
|
||||
.instrument(bob_span.clone())
|
||||
.await
|
||||
.expect("We should be able to send a message to the room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
alice
|
||||
|
||||
@@ -250,6 +250,7 @@ impl ClientWrapper {
|
||||
room.send(RoomMessageEventContent::text_plain(message.to_owned()))
|
||||
.await
|
||||
.expect("Sending message failed")
|
||||
.0
|
||||
.event_id,
|
||||
message.to_owned(),
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ async fn test_event_with_context() -> Result<()> {
|
||||
alice_room.send(RoomMessageEventContent::text_plain(i.to_string())).await?;
|
||||
}
|
||||
|
||||
let send_event_response =
|
||||
let (send_event_response, _) =
|
||||
alice_room.send(RoomMessageEventContent::text_plain("hello there!")).await?;
|
||||
let event_id = send_event_response.event_id;
|
||||
|
||||
|
||||
@@ -409,6 +409,7 @@ async fn test_enabling_backups_retries_decryption() {
|
||||
.send(RoomMessageEventContent::text_plain("It's a secret to everybody!"))
|
||||
.await
|
||||
.expect("We should be able to send a message to our new room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
alice
|
||||
@@ -619,6 +620,7 @@ async fn test_room_keys_received_on_notification_client_trigger_redecryption() {
|
||||
.send(RoomMessageEventContent::text_plain("It's a secret to everybody!"))
|
||||
.await
|
||||
.expect("We should be able to send a message to our new room")
|
||||
.0
|
||||
.event_id;
|
||||
|
||||
// We don't need Alice anymore.
|
||||
@@ -725,6 +727,7 @@ async fn test_new_users_first_messages_dont_warn_about_insecure_device_if_it_is_
|
||||
room.send(RoomMessageEventContent::text_plain(message))
|
||||
.await
|
||||
.expect("We should be able to send a message to our new room")
|
||||
.0
|
||||
.event_id
|
||||
}
|
||||
|
||||
@@ -942,7 +945,7 @@ async fn test_thread_focused_timeline() -> TestResult {
|
||||
};
|
||||
|
||||
// Bob sends messages in a thread.
|
||||
let resp = bob_room.send(RoomMessageEventContent::text_plain("Root message")).await?;
|
||||
let (resp, _) = bob_room.send(RoomMessageEventContent::text_plain("Root message")).await?;
|
||||
let thread_root = resp.event_id;
|
||||
|
||||
let thread_reply_event_content = bob_room
|
||||
@@ -955,7 +958,7 @@ async fn test_thread_focused_timeline() -> TestResult {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let thread_reply_event_id = bob_room.send(thread_reply_event_content).await?.event_id;
|
||||
let thread_reply_event_id = bob_room.send(thread_reply_event_content).await?.0.event_id;
|
||||
|
||||
// Alice creates a timeline focused on the in-thread event, so this will use
|
||||
// /context, and the thread root will be part of the response.
|
||||
|
||||
Reference in New Issue
Block a user