Browse Source

fix: don't lookup create event when converting stripped state

by making the caller pass the room version rules, fixing stripped state conversion for invites over federation

(cherry picked from commit 03dfa72b8f)
master
Matthias Ahouansou 7 months ago
parent
commit
7a45c25d7a
No known key found for this signature in database
  1. 2
      src/api/client_server/membership.rs
  2. 2
      src/api/server_server.rs
  3. 12
      src/utils/mod.rs

2
src/api/client_server/membership.rs

@ -231,7 +231,7 @@ pub async fn knock_room_route(
.to_stripped_state_event()
.into(),
);
let stripped_state = utils::convert_stripped_state(stripped_state, &room_id)?;
let stripped_state = utils::convert_stripped_state(stripped_state, &rules)?;
services().rooms.state_cache.update_membership(
&room_id,

2
src/api/server_server.rs

@ -2169,7 +2169,7 @@ pub async fn create_invite_route(
})?;
invite_state.push(pdu.to_stripped_state_event().into());
let invite_state = utils::convert_stripped_state(invite_state, &room_id)?;
let invite_state = utils::convert_stripped_state(invite_state, &rules)?;
// If we are active in the room, the remote server will notify us about the join via /send
if !services()

12
src/utils/mod.rs

@ -22,7 +22,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};
use crate::{service::pdu::gen_event_id_canonical_json, services, Result};
use crate::{service::pdu::gen_event_id_canonical_json, Result};
pub fn millis_since_unix_epoch() -> u64 {
SystemTime::now()
@ -202,20 +202,14 @@ impl fmt::Display for HtmlEscape<'_> {
/// Converts `RawStrippedState` (federation format) into `Raw<StrippedState>` (client format)
pub fn convert_stripped_state(
stripped_state: Vec<RawStrippedState>,
room_id: &RoomId,
rules: &RoomVersionRules,
) -> Result<Vec<Raw<StrippedState>>> {
stripped_state
.into_iter()
.map(|stripped_state| match stripped_state {
RawStrippedState::Stripped(state) => Ok(state.cast()),
RawStrippedState::Pdu(state) => {
let rules = services()
.rooms
.state
.get_room_version(room_id)?
.rules()
.expect("Supported room version must have rules.");
let (event_id, mut event) = gen_event_id_canonical_json(&state, &rules)?;
let (event_id, mut event) = gen_event_id_canonical_json(&state, rules)?;
event.retain(|k, _| {
matches!(

Loading…
Cancel
Save