simplify getting event content in build_and_append_pdu
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
223f05c922
commit
f9e6caef87
1 changed files with 11 additions and 28 deletions
|
@ -18,13 +18,13 @@ use ruma::{
|
||||||
encrypted::Relation,
|
encrypted::Relation,
|
||||||
member::{MembershipState, RoomMemberEventContent},
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
power_levels::RoomPowerLevelsEventContent,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
|
redaction::RoomRedactionEventContent,
|
||||||
},
|
},
|
||||||
GlobalAccountDataEventType, StateEventType, TimelineEventType,
|
GlobalAccountDataEventType, StateEventType, TimelineEventType,
|
||||||
},
|
},
|
||||||
push::{Action, Ruleset, Tweak},
|
push::{Action, Ruleset, Tweak},
|
||||||
serde::Base64,
|
serde::Base64,
|
||||||
state_res,
|
state_res::{self, Event, RoomVersion},
|
||||||
state_res::{Event, RoomVersion},
|
|
||||||
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
|
uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||||
RoomId, RoomVersionId, ServerName, UserId,
|
RoomId, RoomVersionId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
|
@ -314,12 +314,7 @@ impl Service {
|
||||||
if pdu.kind == TimelineEventType::RoomRedaction
|
if pdu.kind == TimelineEventType::RoomRedaction
|
||||||
&& services().rooms.state.get_room_version(&pdu.room_id)? == RoomVersionId::V11
|
&& services().rooms.state.get_room_version(&pdu.room_id)? == RoomVersionId::V11
|
||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
let content = serde_json::from_str::<RoomRedactionEventContent>(pdu.content.get())
|
||||||
struct Redaction {
|
|
||||||
redacts: Option<OwnedEventId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = serde_json::from_str::<Redaction>(pdu.content.get())
|
|
||||||
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
||||||
|
|
||||||
if let Some(redact_id) = &content.redacts {
|
if let Some(redact_id) = &content.redacts {
|
||||||
|
@ -436,11 +431,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RoomVersionId::V11 => {
|
RoomVersionId::V11 => {
|
||||||
#[derive(Deserialize)]
|
let content =
|
||||||
struct Redaction {
|
serde_json::from_str::<RoomRedactionEventContent>(pdu.content.get()).map_err(|e| {
|
||||||
redacts: Option<OwnedEventId>,
|
|
||||||
}
|
|
||||||
let content = serde_json::from_str::<Redaction>(pdu.content.get()).map_err(|e| {
|
|
||||||
warn!("Invalid content in redaction pdu: {e}");
|
warn!("Invalid content in redaction pdu: {e}");
|
||||||
Error::bad_database("Invalid content in redaction pdu.")
|
Error::bad_database("Invalid content in redaction pdu.")
|
||||||
})?;
|
})?;
|
||||||
|
@ -664,12 +656,8 @@ impl Service {
|
||||||
.get_room_version(room_id)
|
.get_room_version(room_id)
|
||||||
.or_else(|_| {
|
.or_else(|_| {
|
||||||
if event_type == TimelineEventType::RoomCreate {
|
if event_type == TimelineEventType::RoomCreate {
|
||||||
#[derive(Deserialize)]
|
let content = serde_json::from_str::<RoomCreateEventContent>(content.get())
|
||||||
struct RoomCreate {
|
.expect("Invalid content in RoomCreate pdu.");
|
||||||
room_version: RoomVersionId,
|
|
||||||
}
|
|
||||||
let content =
|
|
||||||
serde_json::from_str::<RoomCreate>(content.get()).expect("Invalid content in RoomCreate pdu.");
|
|
||||||
Ok(content.room_version)
|
Ok(content.room_version)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::InconsistentRoomState(
|
Err(Error::InconsistentRoomState(
|
||||||
|
@ -841,18 +829,13 @@ impl Service {
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
TimelineEventType::RoomMember => {
|
TimelineEventType::RoomMember => {
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct ExtractMembership {
|
|
||||||
membership: MembershipState,
|
|
||||||
}
|
|
||||||
|
|
||||||
let target = pdu
|
let target = pdu
|
||||||
.state_key()
|
.state_key()
|
||||||
.filter(|v| v.starts_with('@'))
|
.filter(|v| v.starts_with('@'))
|
||||||
.unwrap_or(sender.as_str());
|
.unwrap_or(sender.as_str());
|
||||||
let server_name = services().globals.server_name();
|
let server_name = services().globals.server_name();
|
||||||
let server_user = format!("@conduit:{server_name}");
|
let server_user = format!("@conduit:{server_name}");
|
||||||
let content = serde_json::from_str::<ExtractMembership>(pdu.content.get())
|
let content = serde_json::from_str::<RoomMemberEventContent>(pdu.content.get())
|
||||||
.map_err(|_| Error::bad_database("Invalid content in pdu."))?;
|
.map_err(|_| Error::bad_database("Invalid content in pdu."))?;
|
||||||
|
|
||||||
if content.membership == MembershipState::Leave {
|
if content.membership == MembershipState::Leave {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue