Browse Source

fix: don't ignore content of membership template

In case there are any custom fields, we shouldn't ignore them
merge-requests/181/merge
Matthias Ahouansou 3 months ago
parent
commit
346913268f
No known key found for this signature in database
  1. 49
      src/service/rooms/helpers/mod.rs

49
src/service/rooms/helpers/mod.rs

@ -12,7 +12,6 @@ use ruma::{
}, },
federation, federation,
}, },
canonical_json::to_canonical_value,
events::{ events::{
room::{ room::{
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
@ -22,7 +21,7 @@ use ruma::{
}, },
room_version_rules::RoomVersionRules, room_version_rules::RoomVersionRules,
state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
OwnedEventId, OwnedServerName, OwnedUserId, RoomId, RoomVersionId, UserId, OwnedEventId, OwnedServerName, RoomId, RoomVersionId, UserId,
}; };
use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@ -529,16 +528,15 @@ impl Service {
Error::BadServerResponse("Invalid make_knock event json received from server.") Error::BadServerResponse("Invalid make_knock event json received from server.")
})?; })?;
let join_authorized_via_users_server = member_event_stub let mut content: CanonicalJsonObject = member_event_stub
.get("content") .remove("content")
.map(|s| { .map(|s| match s {
s.as_object()? CanonicalJsonValue::Object(obj) => obj,
.get("join_authorised_via_users_server")? _ => BTreeMap::new(),
.as_str()
}) })
.and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok()); .unwrap_or_default();
let restricted_join = join_authorized_via_users_server.is_some(); let restricted_join = content.contains_key("join_authorized_via_users_server");
member_event_stub.insert( member_event_stub.insert(
"origin".to_owned(), "origin".to_owned(),
@ -556,20 +554,23 @@ impl Service {
member_event_stub.insert("type".to_owned(), "m.room.member".into()); member_event_stub.insert("type".to_owned(), "m.room.member".into());
member_event_stub.insert( content.insert("membership".to_owned(), membership.to_string().into());
"content".to_owned(), if let Some(displayname) = services().users.displayname(sender_user)? {
to_canonical_value(RoomMemberEventContent { content.insert("displayname".to_owned(), displayname.into());
membership, }
displayname: services().users.displayname(sender_user)?, if let Some(avatar_url) = services().users.avatar_url(sender_user)? {
avatar_url: services().users.avatar_url(sender_user)?, content.insert(
is_direct: None, "avatar_url".to_owned(),
third_party_invite: None, avatar_url.as_str().to_owned().into(),
blurhash: services().users.blurhash(sender_user)?, );
reason: reason.clone(), }
join_authorized_via_users_server, if let Some(blurhash) = services().users.blurhash(sender_user)? {
}) content.insert("blurhash".to_owned(), blurhash.into());
.expect("event is valid, we just created it"), }
); if let Some(reason) = reason {
content.insert("reason".to_owned(), reason.into());
}
member_event_stub.insert("content".to_owned(), content.into());
member_event_stub.insert("sender".to_owned(), sender_user.to_string().into()); member_event_stub.insert("sender".to_owned(), sender_user.to_string().into());
member_event_stub.insert("state_key".to_owned(), sender_user.to_string().into()); member_event_stub.insert("state_key".to_owned(), sender_user.to_string().into());

Loading…
Cancel
Save