Upgrade Ruma

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2023-08-22 17:25:02 +02:00
committed by GitHub
parent 329b6c4eb1
commit e01421a3dd
11 changed files with 112 additions and 101 deletions

16
Cargo.lock generated
View File

@@ -4870,7 +4870,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.8.2"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"assign",
"js_int",
@@ -4885,7 +4885,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.8.1"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"js_int",
"ruma-common",
@@ -4896,7 +4896,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.16.2"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"assign",
"bytes",
@@ -4913,7 +4913,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.11.3"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"base64 0.21.2",
"bytes",
@@ -4946,7 +4946,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.7.1"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"js_int",
"ruma-common",
@@ -4957,7 +4957,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.9.1"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"js_int",
"thiserror",
@@ -4966,7 +4966,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.11.3"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"once_cell",
"proc-macro-crate",
@@ -4981,7 +4981,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.7.1"
source = "git+https://github.com/ruma/ruma?rev=f1772ae5bc1d849655498f51b0fec7b0ef10e339#f1772ae5bc1d849655498f51b0fec7b0ef10e339"
source = "git+https://github.com/ruma/ruma?rev=f59652b94086a5733cc741cf8e21d90bd56e05b1#f59652b94086a5733cc741cf8e21d90bd56e05b1"
dependencies = [
"js_int",
"ruma-common",

View File

@@ -34,8 +34,8 @@ futures-executor = "0.3.21"
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
http = "0.2.6"
itertools = "0.11.0"
ruma = { git = "https://github.com/ruma/ruma", rev = "f1772ae5bc1d849655498f51b0fec7b0ef10e339", features = ["client-api-c", "compat-upload-signatures", "compat-user-id"] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "f1772ae5bc1d849655498f51b0fec7b0ef10e339" }
ruma = { git = "https://github.com/ruma/ruma", rev = "f59652b94086a5733cc741cf8e21d90bd56e05b1", features = ["client-api-c", "compat-upload-signatures", "compat-user-id"] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "f59652b94086a5733cc741cf8e21d90bd56e05b1" }
once_cell = "1.16.0"
serde = "1.0.151"
serde_html_form = "0.2.0"

View File

@@ -19,7 +19,7 @@ use matrix_sdk::{
receipt::ReceiptThread,
relation::{Annotation, Replacement},
room::message::{
ForwardThread, LocationMessageEventContent, MessageType, Relation,
AddMentions, ForwardThread, LocationMessageEventContent, MessageType, Relation,
RoomMessageEvent, RoomMessageEventContent,
},
AnyMessageLikeEventContent,
@@ -422,10 +422,11 @@ impl Room {
let original_message =
event_content.as_original().context("Couldn't retrieve original message.")?;
anyhow::Ok(
RoomMessageEventContent::text_markdown(msg)
.make_reply_to(original_message, ForwardThread::Yes),
)
anyhow::Ok(RoomMessageEventContent::text_markdown(msg).make_reply_to(
original_message,
ForwardThread::Yes,
AddMentions::No,
))
})?;
RUNTIME.spawn(async move {

View File

@@ -28,14 +28,6 @@ use matrix_sdk_crypto::{
store::DynCryptoStore, EncryptionSettings, EncryptionSyncChanges, OlmError, OlmMachine,
ToDeviceRequest,
};
#[cfg(feature = "e2e-encryption")]
use ruma::events::{
room::{
history_visibility::HistoryVisibility, message::MessageType,
redaction::SyncRoomRedactionEvent,
},
AnySyncMessageLikeEvent, SyncMessageLikeEvent,
};
use ruma::{
api::client::{self as api, push::get_notifications::v3::Notification},
events::{
@@ -52,6 +44,14 @@ use ruma::{
serde::Raw,
MilliSecondsSinceUnixEpoch, OwnedUserId, RoomId, UInt, UserId,
};
#[cfg(feature = "e2e-encryption")]
use ruma::{
events::{
room::{history_visibility::HistoryVisibility, message::MessageType},
AnySyncMessageLikeEvent, SyncMessageLikeEvent,
},
RoomVersionId,
};
use tokio::sync::RwLock;
#[cfg(feature = "e2e-encryption")]
use tokio::sync::RwLockReadGuard;
@@ -343,17 +343,17 @@ impl BaseClient {
#[cfg(feature = "e2e-encryption")]
AnySyncTimelineEvent::MessageLike(
AnySyncMessageLikeEvent::RoomRedaction(
// Redacted redactions don't have the `redacts` key, so we can't
// know what they were meant to redact. A future room version might
// move the redacts key, replace the current redaction event
// altogether, or have the redacts key survive redaction.
SyncRoomRedactionEvent::Original(r),
),
AnySyncMessageLikeEvent::RoomRedaction(r),
) => {
room_info.handle_redaction(r, event.event.cast_ref());
let raw_event = event.event.clone().cast();
changes.add_redaction(room.room_id(), &r.redacts, raw_event);
let room_version =
room_info.room_version().unwrap_or(&RoomVersionId::V1);
if let Some(redacts) = r.redacts(room_version) {
room_info.handle_redaction(r, event.event.cast_ref());
let raw_event = event.event.clone().cast();
changes.add_redaction(room.room_id(), redacts, raw_event);
}
}
#[cfg(feature = "e2e-encryption")]

View File

@@ -17,8 +17,8 @@ use ruma::{
guest_access::RoomGuestAccessEventContent,
history_visibility::RoomHistoryVisibilityEventContent,
join_rules::RoomJoinRulesEventContent, member::MembershipState,
name::RoomNameEventContent, redaction::OriginalSyncRoomRedactionEvent,
tombstone::RoomTombstoneEventContent, topic::RoomTopicEventContent,
name::RoomNameEventContent, tombstone::RoomTombstoneEventContent,
topic::RoomTopicEventContent,
},
AnyStrippedStateEvent, AnySyncStateEvent, RedactContent, RedactedStateEventContent,
StaticStateEventContent, SyncStateEvent,
@@ -214,27 +214,27 @@ impl BaseRoomInfo {
true
}
pub fn handle_redaction(&mut self, event: &OriginalSyncRoomRedactionEvent) {
pub fn handle_redaction(&mut self, redacts: &EventId) {
let room_version = self.room_version().unwrap_or(&RoomVersionId::V1).to_owned();
// FIXME: Use let chains once available to get rid of unwrap()s
if self.avatar.has_event_id(&event.redacts) {
if self.avatar.has_event_id(redacts) {
self.avatar.as_mut().unwrap().redact(&room_version);
} else if self.canonical_alias.has_event_id(&event.redacts) {
} else if self.canonical_alias.has_event_id(redacts) {
self.canonical_alias.as_mut().unwrap().redact(&room_version);
} else if self.create.has_event_id(&event.redacts) {
} else if self.create.has_event_id(redacts) {
self.create.as_mut().unwrap().redact(&room_version);
} else if self.guest_access.has_event_id(&event.redacts) {
} else if self.guest_access.has_event_id(redacts) {
self.guest_access.as_mut().unwrap().redact(&room_version);
} else if self.history_visibility.has_event_id(&event.redacts) {
} else if self.history_visibility.has_event_id(redacts) {
self.history_visibility.as_mut().unwrap().redact(&room_version);
} else if self.join_rules.has_event_id(&event.redacts) {
} else if self.join_rules.has_event_id(redacts) {
self.join_rules.as_mut().unwrap().redact(&room_version);
} else if self.name.has_event_id(&event.redacts) {
} else if self.name.has_event_id(redacts) {
self.name.as_mut().unwrap().redact(&room_version);
} else if self.tombstone.has_event_id(&event.redacts) {
} else if self.tombstone.has_event_id(redacts) {
self.tombstone.as_mut().unwrap().redact(&room_version);
} else if self.topic.has_event_id(&event.redacts) {
} else if self.topic.has_event_id(redacts) {
self.topic.as_mut().unwrap().redact(&room_version);
}
}

View File

@@ -38,7 +38,7 @@ use ruma::{
join_rules::JoinRule,
member::{MembershipState, RoomMemberEventContent},
name::RoomNameEventContent,
redaction::OriginalSyncRoomRedactionEvent,
redaction::SyncRoomRedactionEvent,
tombstone::RoomTombstoneEventContent,
},
tag::Tags,
@@ -866,13 +866,18 @@ impl RoomInfo {
/// Handle the given redaction.
pub fn handle_redaction(
&mut self,
event: &OriginalSyncRoomRedactionEvent,
_raw: &Raw<OriginalSyncRoomRedactionEvent>,
event: &SyncRoomRedactionEvent,
_raw: &Raw<SyncRoomRedactionEvent>,
) {
let room_version = self.base_info.room_version().unwrap_or(&RoomVersionId::V1);
let Some(redacts) = event.redacts(room_version) else {
return;
};
#[cfg(feature = "experimental-sliding-sync")]
if let Some(latest_event) = &mut self.latest_event {
if latest_event.event_id().as_deref() == Some(&*event.redacts) {
let room_version = self.base_info.room_version().unwrap_or(&RoomVersionId::V1);
if latest_event.event_id().as_deref() == Some(redacts) {
match apply_redaction(&latest_event.event, _raw, room_version) {
Some(redacted) => latest_event.event = redacted,
None => self.latest_event = None,
@@ -880,7 +885,7 @@ impl RoomInfo {
}
}
self.base_info.handle_redaction(event);
self.base_info.handle_redaction(redacts);
}
/// Update the room name
@@ -970,10 +975,11 @@ impl RoomInfo {
}
fn creator(&self) -> Option<&UserId> {
Some(match self.base_info.create.as_ref()? {
MinimalStateEvent::Original(ev) => &ev.content.creator,
MinimalStateEvent::Redacted(ev) => &ev.content.creator,
})
#[allow(deprecated)]
match self.base_info.create.as_ref()? {
MinimalStateEvent::Original(ev) => ev.content.creator.as_deref(),
MinimalStateEvent::Redacted(ev) => ev.content.creator.as_deref(),
}
}
fn guest_access(&self) -> &GuestAccess {
@@ -1013,7 +1019,7 @@ impl RoomInfo {
#[cfg(feature = "experimental-sliding-sync")]
fn apply_redaction(
event: &Raw<AnySyncTimelineEvent>,
raw_redaction: &Raw<OriginalSyncRoomRedactionEvent>,
raw_redaction: &Raw<SyncRoomRedactionEvent>,
room_version: &RoomVersionId,
) -> Option<Raw<AnySyncTimelineEvent>> {
use ruma::canonical_json::redact_in_place;

View File

@@ -46,7 +46,7 @@ use ruma::{
events::{
presence::PresenceEvent,
receipt::ReceiptEventContent,
room::{member::StrippedRoomMemberEvent, redaction::OriginalSyncRoomRedactionEvent},
room::{member::StrippedRoomMemberEvent, redaction::SyncRoomRedactionEvent},
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
},
@@ -275,8 +275,7 @@ pub struct StateChanges {
/// A map of `RoomId` to maps of `OwnedEventId` to be redacted by
/// `SyncRoomRedactionEvent`.
pub redactions:
BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, Raw<OriginalSyncRoomRedactionEvent>>>,
pub redactions: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, Raw<SyncRoomRedactionEvent>>>,
/// A mapping of `RoomId` to a map of event type to a map of state key to
/// `AnyStrippedStateEvent`.
@@ -368,7 +367,7 @@ impl StateChanges {
&mut self,
room_id: &RoomId,
redacted_event_id: &EventId,
redaction: Raw<OriginalSyncRoomRedactionEvent>,
redaction: Raw<SyncRoomRedactionEvent>,
) {
self.redactions
.entry(room_id.to_owned())

View File

@@ -202,7 +202,7 @@ impl From<&StrippedRoomNameEvent> for MinimalStateEvent<RoomNameEventContent> {
impl From<&StrippedRoomCreateEvent> for MinimalStateEvent<RoomCreateEventContent> {
fn from(event: &StrippedRoomCreateEvent) -> Self {
let content = assign!(RoomCreateEventContent::new(event.content.creator.clone()), {
let content = assign!(RoomCreateEventContent::new_v1(event.sender.clone()), {
federate: event.content.federate,
room_version: event.content.room_version.clone(),
predecessor: event.content.predecessor.clone(),

View File

@@ -29,9 +29,7 @@ use ruma::{
self, sanitize::RemoveReplyFallback, RoomMessageEventContent,
RoomMessageEventContentWithoutRelation,
},
redaction::{
OriginalSyncRoomRedactionEvent, RoomRedactionEventContent, SyncRoomRedactionEvent,
},
redaction::{RoomRedactionEventContent, SyncRoomRedactionEvent},
},
AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnySyncStateEvent,
AnySyncTimelineEvent, BundledMessageLikeRelations, EventContent, FullStateEventContent,
@@ -39,6 +37,7 @@ use ruma::{
},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId,
RoomVersionId,
};
use tracing::{debug, error, field::debug, info, instrument, trace, warn};
@@ -121,42 +120,21 @@ pub(super) enum TimelineEventKind {
}
impl TimelineEventKind {
pub(super) fn failed_to_parse(
event: SyncTimelineEventWithoutContent,
error: serde_json::Error,
) -> Self {
let error = Arc::new(error);
/// Creates a new `TimelineEventKind` with the given event and room version.
pub fn from_event(event: AnySyncTimelineEvent, room_version: &RoomVersionId) -> Self {
match event {
SyncTimelineEventWithoutContent::OriginalMessageLike(ev) => {
Self::FailedToParseMessageLike { event_type: ev.content.event_type, error }
}
SyncTimelineEventWithoutContent::RedactedMessageLike(ev) => {
Self::FailedToParseMessageLike { event_type: ev.content.event_type, error }
}
SyncTimelineEventWithoutContent::OriginalState(ev) => Self::FailedToParseState {
event_type: ev.content.event_type,
state_key: ev.state_key,
error,
},
SyncTimelineEventWithoutContent::RedactedState(ev) => Self::FailedToParseState {
event_type: ev.content.event_type,
state_key: ev.state_key,
error,
},
}
}
}
AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomRedaction(ev)) => {
if let Some(redacts) = ev.redacts(room_version).map(ToOwned::to_owned) {
let content = match ev {
SyncRoomRedactionEvent::Original(e) => e.content,
SyncRoomRedactionEvent::Redacted(_) => Default::default(),
};
impl From<AnySyncTimelineEvent> for TimelineEventKind {
fn from(event: AnySyncTimelineEvent) -> Self {
match event {
AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomRedaction(
SyncRoomRedactionEvent::Original(OriginalSyncRoomRedactionEvent {
redacts,
content,
..
}),
)) => Self::Redaction { redacts, content },
Self::Redaction { redacts, content }
} else {
Self::RedactedMessage { event_type: ev.event_type() }
}
}
AnySyncTimelineEvent::MessageLike(ev) => match ev.original_content() {
Some(content) => Self::Message { content, relations: ev.relations() },
None => Self::RedactedMessage { event_type: ev.event_type() },
@@ -184,6 +162,31 @@ impl From<AnySyncTimelineEvent> for TimelineEventKind {
},
}
}
pub(super) fn failed_to_parse(
event: SyncTimelineEventWithoutContent,
error: serde_json::Error,
) -> Self {
let error = Arc::new(error);
match event {
SyncTimelineEventWithoutContent::OriginalMessageLike(ev) => {
Self::FailedToParseMessageLike { event_type: ev.content.event_type, error }
}
SyncTimelineEventWithoutContent::RedactedMessageLike(ev) => {
Self::FailedToParseMessageLike { event_type: ev.content.event_type, error }
}
SyncTimelineEventWithoutContent::OriginalState(ev) => Self::FailedToParseState {
event_type: ev.content.event_type,
state_key: ev.state_key,
error,
},
SyncTimelineEventWithoutContent::RedactedState(ev) => Self::FailedToParseState {
event_type: ev.content.event_type,
state_key: ev.state_key,
error,
},
}
}
}
#[derive(Clone, Debug)]

View File

@@ -206,12 +206,13 @@ impl TimelineInnerState {
{
Ok(event) => {
let should_add = should_add_event(&event);
let room_version = room_data_provider.room_version();
(
event.event_id().to_owned(),
event.sender().to_owned(),
event.origin_server_ts(),
event.transaction_id().map(ToOwned::to_owned),
event.into(),
TimelineEventKind::from_event(event, &room_version),
should_add,
)
}

View File

@@ -22,8 +22,8 @@ use ruma::{
relation::Annotation,
room::{
message::{
ForwardThread, OriginalSyncRoomMessageEvent, RedactedRoomMessageEventContent,
RoomMessageEventContent,
AddMentions, ForwardThread, OriginalSyncRoomMessageEvent,
RedactedRoomMessageEventContent, RoomMessageEventContent,
},
name::RoomNameEventContent,
},
@@ -87,6 +87,7 @@ async fn redact_replied_to_event() {
RoomMessageEventContent::text_plain("Hello, alice.").make_reply_to(
&first_event.into_full_event(owned_room_id!("!whocares:local.host")),
ForwardThread::Yes,
AddMentions::No,
),
)
.await;