fix: double join over federation
This commit is contained in:
parent
a89f7eaf9f
commit
9109cb492f
2 changed files with 23 additions and 6 deletions
|
@ -22,9 +22,7 @@ use ruma::{
|
||||||
EventId, Raw, RoomId, RoomVersionId, ServerName, UserId,
|
EventId, Raw, RoomId, RoomVersionId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
use state_res::StateEvent;
|
use state_res::StateEvent;
|
||||||
use std::{
|
use std::{collections::BTreeMap, collections::HashMap, collections::HashSet, convert::TryFrom, iter, sync::Arc};
|
||||||
collections::BTreeMap, collections::HashMap, collections::HashSet, convert::TryFrom, sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(feature = "conduit_bin")]
|
#[cfg(feature = "conduit_bin")]
|
||||||
use rocket::{get, post};
|
use rocket::{get, post};
|
||||||
|
@ -474,6 +472,17 @@ async fn join_room_by_id_helper(
|
||||||
"origin_server_ts".to_owned(),
|
"origin_server_ts".to_owned(),
|
||||||
utils::millis_since_unix_epoch().into(),
|
utils::millis_since_unix_epoch().into(),
|
||||||
);
|
);
|
||||||
|
join_event_stub.insert(
|
||||||
|
"content".to_owned(),
|
||||||
|
serde_json::to_value(member::MemberEventContent {
|
||||||
|
membership: member::MembershipState::Join,
|
||||||
|
displayname: db.users.displayname(&sender_id)?,
|
||||||
|
avatar_url: db.users.avatar_url(&sender_id)?,
|
||||||
|
is_direct: None,
|
||||||
|
third_party_invite: None,
|
||||||
|
})
|
||||||
|
.expect("event is valid, we just created it"),
|
||||||
|
);
|
||||||
|
|
||||||
// Generate event id
|
// Generate event id
|
||||||
let event_id = EventId::try_from(&*format!(
|
let event_id = EventId::try_from(&*format!(
|
||||||
|
@ -494,14 +503,20 @@ async fn join_room_by_id_helper(
|
||||||
)
|
)
|
||||||
.expect("event is valid, we just created it");
|
.expect("event is valid, we just created it");
|
||||||
|
|
||||||
|
// Add event_id back
|
||||||
|
let join_event_stub = join_event_stub_value.as_object_mut().unwrap();
|
||||||
|
join_event_stub.insert("event_id".to_owned(), event_id.to_string().into());
|
||||||
|
|
||||||
|
// It has enough fields to be called a proper event now
|
||||||
|
let join_event = join_event_stub_value;
|
||||||
|
|
||||||
let send_join_response = server_server::send_request(
|
let send_join_response = server_server::send_request(
|
||||||
&db.globals,
|
&db.globals,
|
||||||
remote_server.clone(),
|
remote_server.clone(),
|
||||||
federation::membership::create_join_event::v2::Request {
|
federation::membership::create_join_event::v2::Request {
|
||||||
room_id,
|
room_id,
|
||||||
event_id: &event_id,
|
event_id: &event_id,
|
||||||
pdu_stub: serde_json::from_value(join_event_stub_value)
|
pdu_stub: PduEvent::convert_to_outgoing_federation_event(join_event.clone()),
|
||||||
.expect("we just created this event"),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -529,6 +544,7 @@ async fn join_room_by_id_helper(
|
||||||
let state_events = room_state
|
let state_events = room_state
|
||||||
.clone()
|
.clone()
|
||||||
.map(|pdu: Result<(EventId, serde_json::Value)>| Ok(pdu?.0))
|
.map(|pdu: Result<(EventId, serde_json::Value)>| Ok(pdu?.0))
|
||||||
|
.chain(iter::once(Ok(event_id.clone()))) // Add join event we just created
|
||||||
.collect::<Result<HashSet<EventId>>>()?;
|
.collect::<Result<HashSet<EventId>>>()?;
|
||||||
|
|
||||||
let auth_chain = send_join_response
|
let auth_chain = send_join_response
|
||||||
|
@ -539,6 +555,7 @@ async fn join_room_by_id_helper(
|
||||||
|
|
||||||
let mut event_map = room_state
|
let mut event_map = room_state
|
||||||
.chain(auth_chain)
|
.chain(auth_chain)
|
||||||
|
.chain(iter::once(Ok((event_id, join_event)))) // Add join event we just created
|
||||||
.map(|r| {
|
.map(|r| {
|
||||||
let (event_id, value) = r?;
|
let (event_id, value) = r?;
|
||||||
serde_json::from_value::<StateEvent>(value)
|
serde_json::from_value::<StateEvent>(value)
|
||||||
|
|
|
@ -483,7 +483,7 @@ impl Rooms {
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
Error::BadRequest(
|
Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
"Invalid redaction event content.",
|
"Invalid member event content.",
|
||||||
)
|
)
|
||||||
})?,
|
})?,
|
||||||
&pdu.sender,
|
&pdu.sender,
|
||||||
|
|
Loading…
Reference in a new issue