Skip to content

Commit

Permalink
chore: Update to latest Ruma version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jan 14, 2025
1 parent 5828561 commit c8a3d71
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 154 deletions.
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/machine/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,8 @@ async fn test_unsigned_decryption() {

// Encrypt a second message, an edit.
let second_message_text = "This is the ~~original~~ edited message";
let second_message_content = RoomMessageEventContent::text_plain(second_message_text)
.make_replacement(first_message, None);
let second_message_content =
RoomMessageEventContent::text_plain(second_message_text).make_replacement(first_message);
let second_message_encrypted_content =
alice.encrypt_room_event(room_id, second_message_content).await.unwrap();

Expand Down
10 changes: 0 additions & 10 deletions crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,6 @@ impl Message {
self.mentions.as_ref()
}

pub(in crate::timeline) fn to_content(&self) -> RoomMessageEventContent {
// Like the `impl From<Message> for RoomMessageEventContent` below, but
// takes &self and only copies what's needed.
let relates_to = make_relates_to(
self.thread_root.clone(),
self.in_reply_to.as_ref().map(|details| details.event_id.clone()),
);
assign!(RoomMessageEventContent::new(self.msgtype.clone()), { relates_to })
}

pub(in crate::timeline) fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
Self { in_reply_to: Some(in_reply_to), ..self.clone() }
}
Expand Down
1 change: 0 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/event_item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ impl EventTimelineItem {
Ok(RepliedToInfo {
event_id: event_id.to_owned(),
sender: self.sender().to_owned(),
timestamp: self.timestamp(),
content: reply_content,
})
}
Expand Down
49 changes: 18 additions & 31 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ use ruma::{
events::{
poll::unstable_start::{NewUnstablePollStartEventContent, UnstablePollStartEventContent},
receipt::{Receipt, ReceiptThread},
relation::Thread,
room::{
message::{
AddMentions, ForwardThread, OriginalRoomMessageEvent,
RoomMessageEventContentWithoutRelation,
AddMentions, ForwardThread, ReplyMetadata, RoomMessageEventContentWithoutRelation,
},
pinned_events::RoomPinnedEventsEventContent,
},
AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnySyncTimelineEvent,
SyncMessageLikeEvent,
},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomVersionId, UserId,
EventId, OwnedEventId, OwnedUserId, RoomVersionId, UserId,
};
use thiserror::Error;
use tracing::{error, instrument, trace, warn};
Expand Down Expand Up @@ -104,8 +104,6 @@ pub struct RepliedToInfo {
event_id: OwnedEventId,
/// The sender of the event to reply to.
sender: OwnedUserId,
/// The timestamp of the event to reply to.
timestamp: MilliSecondsSinceUnixEpoch,
/// The content of the event to reply to.
content: ReplyContent,
}
Expand Down Expand Up @@ -343,7 +341,8 @@ impl Timeline {
replied_to_info: RepliedToInfo,
forward_thread: ForwardThread,
) -> Result<(), RoomSendQueueError> {
let event_id = replied_to_info.event_id;
let event_id = &replied_to_info.event_id;
let sender = &replied_to_info.sender;

// [The specification](https://spec.matrix.org/v1.10/client-server-api/#user-and-room-mentions) says:
//
Expand All @@ -352,32 +351,21 @@ impl Timeline {
//
// If the replied to event has been written by the current user, let's toggle to
// `AddMentions::No`.
let mention_the_sender = if self.room().own_user_id() == replied_to_info.sender {
AddMentions::No
} else {
AddMentions::Yes
let mention_the_sender =
if self.room().own_user_id() == sender { AddMentions::No } else { AddMentions::Yes };

let thread = match replied_to_info.content {
ReplyContent::Message(message) => message
.thread_root()
.map(|thread_root| Thread::plain(thread_root.clone(), event_id.clone())),
ReplyContent::Raw(_raw_event) => None,
};

let content = match replied_to_info.content {
ReplyContent::Message(msg) => {
let event = OriginalRoomMessageEvent {
event_id: event_id.to_owned(),
sender: replied_to_info.sender,
origin_server_ts: replied_to_info.timestamp,
room_id: self.room().room_id().to_owned(),
content: msg.to_content(),
unsigned: Default::default(),
};
content.make_reply_to(&event, forward_thread, mention_the_sender)
}
ReplyContent::Raw(raw_event) => content.make_reply_to_raw(
&raw_event,
event_id.to_owned(),
self.room().room_id(),
forward_thread,
mention_the_sender,
),
};
let content = content.make_reply_to(
ReplyMetadata::new(event_id, sender, thread.as_ref()),
forward_thread,
mention_the_sender,
);

self.send(content.into()).await?;

Expand Down Expand Up @@ -425,7 +413,6 @@ impl Timeline {
Ok(RepliedToInfo {
event_id: event_id.to_owned(),
sender: sync_event.sender().to_owned(),
timestamp: sync_event.origin_server_ts(),
content: reply_content,
})
}
Expand Down
Loading

0 comments on commit c8a3d71

Please sign in to comment.