1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-08-11 17:50:59 +00:00

chore: bump ruma

This commit is contained in:
Matthias Ahouansou 2025-08-01 17:05:00 +02:00
parent f6d14fdabd
commit 8170b4ff14
No known key found for this signature in database
13 changed files with 160 additions and 105 deletions

26
Cargo.lock generated
View file

@ -2520,8 +2520,8 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.12.5"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
version = "0.12.6"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"assign",
"js_int",
@ -2540,7 +2540,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.12.2"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"js_int",
"ruma-common",
@ -2552,7 +2552,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.20.4"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"as_variant",
"assign",
@ -2575,7 +2575,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.15.4"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"as_variant",
"base64 0.22.1",
@ -2606,8 +2606,8 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.30.4"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
version = "0.30.5"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"as_variant",
"indexmap 2.9.0",
@ -2631,7 +2631,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.11.2"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"bytes",
"headers",
@ -2653,7 +2653,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.10.1"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"js_int",
"thiserror 2.0.12",
@ -2662,7 +2662,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.15.2"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"cfg-if",
"proc-macro-crate",
@ -2677,7 +2677,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.11.0"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"js_int",
"ruma-common",
@ -2689,7 +2689,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.17.1"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"base64 0.22.1",
"ed25519-dalek",
@ -2705,7 +2705,7 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.13.0"
source = "git+https://github.com/ruma/ruma.git#739fecf1af28c7348442fc27a66ab34222b99ec3"
source = "git+https://github.com/ruma/ruma.git#d6a03802a457e2b6173920bb9beb8ae49291c71b"
dependencies = [
"js_int",
"ruma-common",

View file

@ -18,7 +18,6 @@ use ruma::{
},
StateEventType, TimelineEventType,
},
serde::Raw,
CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedServerName, RoomId, UserId,
};
use serde_json::value::to_raw_value;
@ -159,7 +158,7 @@ pub async fn knock_room_route(
.sending
.send_federation_request(
&remote_server,
federation::knock::create_knock_event_template::v1::Request {
federation::membership::prepare_knock_event::v1::Request {
room_id: room_id.to_owned(),
user_id: sender_user.to_owned(),
ver: services().globals.supported_room_versions(),
@ -205,7 +204,7 @@ pub async fn knock_room_route(
.sending
.send_federation_request(
&remote_server,
federation::knock::send_knock::v1::Request {
federation::membership::create_knock_event::v1::Request {
room_id: room_id.to_owned(),
event_id: event_id.to_owned(),
pdu: PduEvent::convert_to_outgoing_federation_event(knock_event.clone()),
@ -217,9 +216,17 @@ pub async fn knock_room_route(
let mut stripped_state = send_kock_response.knock_room_state;
// Not sure how useful this is in reality, but spec examples show `/sync` returning the actual knock membership event
stripped_state.push(Raw::from_json(to_raw_value(&knock_event).expect(
"All keys are Strings, and CanonicalJsonValue Serialization never fails",
)));
stripped_state.push(
PduEvent::from_id_val(&event_id, knock_event)
.map_err(|_| {
Error::BadServerResponse(
"Invalid JSON in membership event, likely due to bad template from remote server",
)
})?
.to_stripped_state_event()
.into(),
);
let stripped_state = utils::convert_stripped_state(stripped_state, &room_id)?;
services().rooms.state_cache.update_membership(
&room_id,
@ -702,13 +709,16 @@ pub(crate) async fn invite_helper(
&state_lock,
)?;
let mut invite_room_state = services().rooms.state.stripped_state(&pdu.room_id)?;
let mut invite_room_state = services()
.rooms
.state
.stripped_state_federation(&pdu.room_id)?;
if let Some(sender) = services().rooms.state_accessor.room_state_get(
&pdu.room_id,
&StateEventType::RoomMember,
sender_user.as_str(),
)? {
invite_room_state.push(sender.to_stripped_state_event());
invite_room_state.push(sender.to_stripped_state_event().into());
}
drop(state_lock);

View file

@ -4,7 +4,7 @@ use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaRespons
use ruma::{
api::client::{
error::ErrorKind,
state::{get_state_events, get_state_events_for_key, send_state_event},
state::{get_state_event_for_key, get_state_events, send_state_event},
},
events::{
room::canonical_alias::RoomCanonicalAliasEventContent, AnyStateEventContent, StateEventType,
@ -120,9 +120,9 @@ pub async fn get_state_events_route(
/// Get single state event of a room.
///
/// - If not joined: Only works if current room history visibility is world readable
pub async fn get_state_events_for_key_route(
body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<get_state_events_for_key::v3::Response> {
pub async fn get_state_event_for_key_route(
body: Ruma<get_state_event_for_key::v3::Request>,
) -> Result<get_state_event_for_key::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services()
@ -148,8 +148,8 @@ pub async fn get_state_events_for_key_route(
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
})?;
Ok(get_state_events_for_key::v3::Response {
content: serde_json::from_str(event.content.get())
Ok(get_state_event_for_key::v3::Response {
event_or_content: serde_json::from_str(event.content.get())
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
})
}
@ -159,9 +159,9 @@ pub async fn get_state_events_for_key_route(
/// Get single state event of a room.
///
/// - If not joined: Only works if current room history visibility is world readable
pub async fn get_state_events_for_empty_key_route(
body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
pub async fn get_state_event_for_empty_key_route(
body: Ruma<get_state_event_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_event_for_key::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services()
@ -187,8 +187,8 @@ pub async fn get_state_events_for_empty_key_route(
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
})?;
Ok(get_state_events_for_key::v3::Response {
content: serde_json::from_str(event.content.get())
Ok(get_state_event_for_key::v3::Response {
event_or_content: serde_json::from_str(event.content.get())
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
}
.into())

View file

@ -11,7 +11,7 @@ use ruma::{
v3::{
Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom,
KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms,
State, Timeline, ToDevice,
State, StateEvents, Timeline, ToDevice,
},
DeviceLists, UnreadNotificationsCount,
},
@ -366,9 +366,9 @@ async fn sync_helper(
prev_batch: Some(next_batch_string.clone()),
events: Vec::new(),
},
state: State {
state: State::Before(StateEvents {
events: vec![event.to_sync_state_event()],
},
}),
},
);
@ -463,9 +463,9 @@ async fn sync_helper(
prev_batch: Some(next_batch_string.clone()),
events: Vec::new(),
},
state: State {
state: State::Before(StateEvents {
events: left_state_events,
},
}),
},
);
}
@ -1199,12 +1199,12 @@ async fn load_joined_room(
prev_batch,
events: room_events,
},
state: State {
state: State::Before(StateEvents {
events: state_events
.iter()
.map(|pdu| pdu.to_sync_state_event())
.collect(),
},
}),
ephemeral: Ephemeral { events: edus },
unread_thread_notifications: BTreeMap::new(),
})

View file

@ -31,10 +31,9 @@ use ruma::{
},
event::{get_event, get_missing_events, get_room_state, get_room_state_ids},
keys::{claim_keys, get_keys},
knock::{create_knock_event_template, send_knock},
membership::{
create_invite, create_join_event, create_leave_event, prepare_join_event,
prepare_leave_event,
create_invite, create_join_event, create_knock_event, create_leave_event,
prepare_join_event, prepare_knock_event, prepare_leave_event,
},
openid::get_openid_userinfo,
query::{get_profile_information, get_room_information},
@ -1506,13 +1505,13 @@ pub async fn get_room_state_ids_route(
///
/// Creates a knock template.
pub async fn create_knock_event_template_route(
body: Ruma<create_knock_event_template::v1::Request>,
) -> Result<create_knock_event_template::v1::Response> {
body: Ruma<prepare_knock_event::v1::Request>,
) -> Result<prepare_knock_event::v1::Response> {
let (mutex_state, room_version_id) =
member_shake_preamble(&body.sender_servername, &body.room_id).await?;
let state_lock = mutex_state.lock().await;
Ok(create_knock_event_template::v1::Response {
Ok(prepare_knock_event::v1::Response {
room_version: room_version_id,
event: create_membership_template(
&body.user_id,
@ -1972,8 +1971,8 @@ pub async fn create_leave_event_route(
///
/// Submits a signed knock event.
pub async fn create_knock_event_route(
body: Ruma<send_knock::v1::Request>,
) -> Result<send_knock::v1::Response> {
body: Ruma<create_knock_event::v1::Request>,
) -> Result<create_knock_event::v1::Response> {
let sender_servername = body
.sender_servername
.as_ref()
@ -1988,8 +1987,11 @@ pub async fn create_knock_event_route(
)
.await?;
Ok(send_knock::v1::Response {
knock_room_state: services().rooms.state.stripped_state(&body.room_id)?,
Ok(create_knock_event::v1::Response {
knock_room_state: services()
.rooms
.state
.stripped_state_federation(&body.room_id)?,
})
}
@ -2169,7 +2171,8 @@ pub async fn create_invite_route(
Error::BadRequest(ErrorKind::InvalidParam, "Invalid invite event.")
})?;
invite_state.push(pdu.to_stripped_state_event());
invite_state.push(pdu.to_stripped_state_event().into());
let invite_state = utils::convert_stripped_state(invite_state, &room_id)?;
// If we are active in the room, the remote server will notify us about the join via /send
if !services()

View file

@ -1,8 +1,7 @@
use std::{collections::HashSet, sync::Arc};
use ruma::{
events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw,
api::client::sync::sync_events::StrippedState, events::AnySyncStateEvent, serde::Raw,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
};
@ -39,7 +38,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
&self,
user_id: &UserId,
room_id: &RoomId,
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
last_state: Option<Vec<Raw<StrippedState>>>,
) -> Result<()> {
let (roomuser_id, userroom_id) = get_room_and_user_byte_ids(room_id, user_id);
@ -66,7 +65,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
&self,
user_id: &UserId,
room_id: &RoomId,
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
last_state: Option<Vec<Raw<StrippedState>>>,
) -> Result<()> {
let (roomuser_id, userroom_id) = get_room_and_user_byte_ids(room_id, user_id);
@ -483,7 +482,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn rooms_invited<'a>(
&'a self,
user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a> {
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a> {
scan_userroom_id_memberstate_tree(user_id, &self.userroomid_invitestate)
}
@ -493,7 +492,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
fn rooms_knocked<'a>(
&'a self,
user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a> {
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a> {
scan_userroom_id_memberstate_tree(user_id, &self.userroomid_knockstate)
}
@ -502,7 +501,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(room_id.as_bytes());
@ -523,7 +522,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(room_id.as_bytes());
@ -544,7 +543,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
let mut key = user_id.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(room_id.as_bytes());

View file

@ -391,28 +391,28 @@ fn routes(config: &Config) -> Router {
.ruma_route(client_server::send_message_event_route)
.ruma_route(client_server::send_state_event_for_key_route)
.ruma_route(client_server::get_state_events_route)
.ruma_route(client_server::get_state_events_for_key_route)
.ruma_route(client_server::get_state_event_for_key_route)
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes
// share one Ruma request / response type pair with {get,send}_state_event_for_key_route
.route(
"/_matrix/client/r0/rooms/{room_id}/state/{event_type}",
get(client_server::get_state_events_for_empty_key_route)
get(client_server::get_state_event_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/{room_id}/state/{event_type}",
get(client_server::get_state_events_for_empty_key_route)
get(client_server::get_state_event_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
// These two endpoints allow trailing slashes
.route(
"/_matrix/client/r0/rooms/{room_id}/state/{event_type}/",
get(client_server::get_state_events_for_empty_key_route)
get(client_server::get_state_event_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.route(
"/_matrix/client/v3/rooms/{room_id}/state/{event_type}/",
get(client_server::get_state_events_for_empty_key_route)
get(client_server::get_state_event_for_empty_key_route)
.put(client_server::send_state_event_for_empty_key_route),
)
.ruma_route(client_server::sync_events_route)

View file

@ -141,13 +141,16 @@ impl Service {
let power_levels = services().rooms.state_accessor.power_levels(&pdu.room_id)?;
for action in self.get_actions(
user,
&ruleset,
power_levels.into(),
&pdu.to_sync_room_event(),
&pdu.room_id,
)? {
for action in self
.get_actions(
user,
&ruleset,
power_levels.into(),
&pdu.to_sync_room_event(),
&pdu.room_id,
)
.await?
{
let n = match action {
Action::Notify => true,
Action::SetTweak(tweak) => {
@ -175,7 +178,7 @@ impl Service {
}
#[tracing::instrument(skip(self, user, ruleset, pdu))]
pub fn get_actions<'a>(
pub async fn get_actions<'a>(
&self,
user: &UserId,
ruleset: &'a Ruleset,
@ -194,7 +197,7 @@ impl Service {
power_levels: Some(power_levels),
};
Ok(ruleset.get_actions(pdu, &ctx))
Ok(ruleset.get_actions(pdu, &ctx).await)
}
#[tracing::instrument(skip(self, unread, pusher, tweaks, event))]

View file

@ -6,11 +6,13 @@ use std::{
pub use data::Data;
use ruma::{
api::client::error::ErrorKind,
api::{
client::{error::ErrorKind, sync::sync_events::StrippedState},
federation::membership::RawStrippedState,
},
events::{
room::{create::RoomCreateEventContent, member::MembershipState},
AnyStrippedStateEvent, StateEventType, TimelineEventType,
RECOMMENDED_STRIPPED_STATE_EVENT_TYPES,
StateEventType, TimelineEventType, RECOMMENDED_STRIPPED_STATE_EVENT_TYPES,
},
room_version_rules::AuthorizationRules,
serde::Raw,
@ -264,7 +266,7 @@ impl Service {
/// Gets all the [recommended stripped state events] from the given room
///
/// [recommended stripped state events]: https://spec.matrix.org/v1.13/client-server-api/#stripped-state
pub fn stripped_state(&self, room_id: &RoomId) -> Result<Vec<Raw<AnyStrippedStateEvent>>> {
pub fn stripped_state_federation(&self, room_id: &RoomId) -> Result<Vec<RawStrippedState>> {
RECOMMENDED_STRIPPED_STATE_EVENT_TYPES
.iter()
.filter_map(|state_event_type| {
@ -274,7 +276,21 @@ impl Service {
.room_state_get(room_id, state_event_type, "")
.transpose()
})
.map(|e| e.map(|e| e.to_stripped_state_event()))
.map(|e| e.map(|e| RawStrippedState::Stripped(e.to_stripped_state_event())))
.collect()
}
pub fn stripped_state_client(&self, room_id: &RoomId) -> Result<Vec<Raw<StrippedState>>> {
RECOMMENDED_STRIPPED_STATE_EVENT_TYPES
.iter()
.filter_map(|state_event_type| {
services()
.rooms
.state_accessor
.room_state_get(room_id, state_event_type, "")
.transpose()
})
.map(|e| e.map(|e| e.to_stripped_state_event().cast()))
.collect::<Result<Vec<_>>>()
}

View file

@ -2,8 +2,7 @@ use std::{collections::HashSet, sync::Arc};
use crate::{service::appservice::RegistrationInfo, Result};
use ruma::{
events::{AnyStrippedStateEvent, AnySyncStateEvent},
serde::Raw,
api::client::sync::sync_events::StrippedState, events::AnySyncStateEvent, serde::Raw,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
};
@ -14,13 +13,13 @@ pub trait Data: Send + Sync {
&self,
user_id: &UserId,
room_id: &RoomId,
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
last_state: Option<Vec<Raw<StrippedState>>>,
) -> Result<()>;
fn mark_as_knocked(
&self,
user_id: &UserId,
room_id: &RoomId,
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
last_state: Option<Vec<Raw<StrippedState>>>,
) -> Result<()>;
fn mark_as_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>;
@ -86,32 +85,32 @@ pub trait Data: Send + Sync {
fn rooms_invited<'a>(
&'a self,
user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>;
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a>;
/// Returns an iterator over all rooms a user has knocked on.
#[allow(clippy::type_complexity)]
fn rooms_knocked<'a>(
&'a self,
user_id: &UserId,
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>;
) -> Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a>;
fn invite_state(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>>;
) -> Result<Option<Vec<Raw<StrippedState>>>>;
fn knock_state(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>>;
) -> Result<Option<Vec<Raw<StrippedState>>>>;
fn left_state(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>>;
) -> Result<Option<Vec<Raw<StrippedState>>>>;
/// Returns an iterator over all rooms a user left.
#[allow(clippy::type_complexity)]

View file

@ -4,12 +4,12 @@ use std::{collections::HashSet, sync::Arc};
pub use data::Data;
use ruma::{
api::client::sync::sync_events::StrippedState,
events::{
direct::DirectEvent,
ignored_user_list::IgnoredUserListEvent,
room::{create::RoomCreateEventContent, member::MembershipState},
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
RoomAccountDataEventType, StateEventType,
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
},
serde::Raw,
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId,
@ -31,7 +31,7 @@ impl Service {
user_id: &UserId,
membership: MembershipState,
sender: &UserId,
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
last_state: Option<Vec<Raw<StrippedState>>>,
update_joined_count: bool,
) -> Result<()> {
// Keep track what remote users exist by adding them as "deactivated" users
@ -317,7 +317,7 @@ impl Service {
pub fn rooms_invited<'a>(
&'a self,
user_id: &UserId,
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a {
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a {
self.db.rooms_invited(user_id)
}
@ -326,7 +326,7 @@ impl Service {
pub fn rooms_knocked<'a>(
&'a self,
user_id: &UserId,
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a {
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<StrippedState>>)>> + 'a {
self.db.rooms_knocked(user_id)
}
@ -335,7 +335,7 @@ impl Service {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
self.db.invite_state(user_id, room_id)
}
@ -344,7 +344,7 @@ impl Service {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
self.db.knock_state(user_id, room_id)
}
@ -353,7 +353,7 @@ impl Service {
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
) -> Result<Option<Vec<Raw<StrippedState>>>> {
self.db.left_state(user_id, room_id)
}

View file

@ -348,13 +348,17 @@ impl Service {
let mut highlight = false;
let mut notify = false;
for action in services().pusher.get_actions(
user,
&rules_for_user,
power_levels.clone(),
&sync_pdu,
&pdu.room_id,
)? {
for action in services()
.pusher
.get_actions(
user,
&rules_for_user,
power_levels.clone(),
&sync_pdu,
&pdu.room_id,
)
.await?
{
match action {
Action::Notify => notify = true,
Action::SetTweak(Tweak::Highlight(true)) => {
@ -444,9 +448,10 @@ impl Service {
let stripped_state = match content.membership {
MembershipState::Invite | MembershipState::Knock => {
let mut state = services().rooms.state.stripped_state(&pdu.room_id)?;
let mut state =
services().rooms.state.stripped_state_client(&pdu.room_id)?;
// So that clients can get info about who invitied them (not relevant for knocking), the reason, when, etc.
state.push(pdu.to_stripped_state_event());
state.push(pdu.to_stripped_state_event().cast());
Some(state)
}
_ => None,

View file

@ -4,13 +4,20 @@ use argon2::{Config, Variant};
use cmp::Ordering;
use rand::prelude::*;
use ring::digest;
use ruma::{canonical_json::try_from_json_map, CanonicalJsonError, CanonicalJsonObject};
use ruma::{
api::{client::sync::sync_events::StrippedState, federation::membership::RawStrippedState},
canonical_json::try_from_json_map,
serde::Raw,
CanonicalJsonError, CanonicalJsonObject, RoomId,
};
use std::{
cmp, fmt,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
use crate::Result;
pub fn millis_since_unix_epoch() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
@ -185,3 +192,16 @@ impl fmt::Display for HtmlEscape<'_> {
Ok(())
}
}
/// Converts `RawStrippedState` (federation format) into `Raw<StrippedState>` (client format)
pub fn convert_stripped_state(
stripped_state: Vec<RawStrippedState>,
_room_id: &RoomId,
) -> Result<Vec<Raw<StrippedState>>> {
stripped_state
.into_iter()
.map(|stripped_state| match stripped_state {
RawStrippedState::Stripped(state) => Ok(state.cast()),
})
.collect()
}