Upgrade Ruma
This commit is contained in:
parent
bd16850fd4
commit
a0457000ff
9 changed files with 117 additions and 143 deletions
|
@ -1,7 +1,4 @@
|
|||
use std::{
|
||||
collections::BTreeMap,
|
||||
convert::{TryFrom, TryInto},
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryInto};
|
||||
|
||||
use super::{State, DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||
use crate::{pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma};
|
||||
|
|
|
@ -25,9 +25,9 @@ use ruma::{
|
|||
EventType,
|
||||
},
|
||||
serde::{to_canonical_value, CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
state_res::{self, EventMap, RoomVersion},
|
||||
uint, EventId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use state_res::EventMap;
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
|
@ -765,9 +765,11 @@ pub async fn invite_helper(
|
|||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version_id = create_event_content
|
||||
.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
let content = serde_json::to_value(MemberEventContent {
|
||||
avatar_url: None,
|
||||
|
@ -863,7 +865,7 @@ pub async fn invite_helper(
|
|||
db.globals.server_name().as_str(),
|
||||
db.globals.keypair(),
|
||||
&mut pdu_json,
|
||||
&room_version,
|
||||
&room_version_id,
|
||||
)
|
||||
.expect("event is valid, we just created it");
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use super::State;
|
||||
use crate::client_server::invite_helper;
|
||||
use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{client_server::invite_helper, pdu::PduBuilder, ConduitResult, Database, Error, Ruma};
|
||||
use log::info;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
|
|
@ -31,7 +31,7 @@ pub async fn update_tag_route(
|
|||
tags_event
|
||||
.content
|
||||
.tags
|
||||
.insert(body.tag.to_string(), body.tag_info.clone());
|
||||
.insert(body.tag.clone().into(), body.tag_info.clone());
|
||||
|
||||
db.account_data.update(
|
||||
Some(&body.room_id),
|
||||
|
@ -65,7 +65,7 @@ pub async fn delete_tag_route(
|
|||
tags: BTreeMap::new(),
|
||||
},
|
||||
});
|
||||
tags_event.content.tags.remove(&body.tag);
|
||||
tags_event.content.tags.remove(&body.tag.clone().into());
|
||||
|
||||
db.account_data.update(
|
||||
Some(&body.room_id),
|
||||
|
|
|
@ -16,10 +16,10 @@ use ruma::{
|
|||
},
|
||||
push::{self, Action, Tweak},
|
||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
state_res::{self, Event, RoomVersion, StateMap},
|
||||
uint, EventId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use sled::IVec;
|
||||
use state_res::{Event, StateMap};
|
||||
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
|
@ -1236,9 +1236,11 @@ impl Rooms {
|
|||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version_id = create_event_content
|
||||
.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
let auth_events = self.get_auth_events(
|
||||
&room_id,
|
||||
|
@ -1326,14 +1328,14 @@ impl Rooms {
|
|||
db.globals.server_name().as_str(),
|
||||
db.globals.keypair(),
|
||||
&mut pdu_json,
|
||||
&room_version,
|
||||
&room_version_id,
|
||||
)
|
||||
.expect("event is valid, we just created it");
|
||||
|
||||
// Generate event id
|
||||
pdu.event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&pdu_json, &room_version)
|
||||
ruma::signatures::reference_hash(&pdu_json, &room_version_id)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
@ -1868,8 +1870,8 @@ impl Rooms {
|
|||
|
||||
let (make_leave_response, remote_server) = make_leave_response_and_server?;
|
||||
|
||||
let room_version = match make_leave_response.room_version {
|
||||
Some(room_version) if room_version == RoomVersionId::Version6 => room_version,
|
||||
let room_version_id = match make_leave_response.room_version {
|
||||
Some(id @ RoomVersionId::Version6) => id,
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
|
@ -1900,14 +1902,14 @@ impl Rooms {
|
|||
db.globals.server_name().as_str(),
|
||||
db.globals.keypair(),
|
||||
&mut leave_event_stub,
|
||||
&room_version,
|
||||
&room_version_id,
|
||||
)
|
||||
.expect("event is valid, we just created it");
|
||||
|
||||
// Generate event id
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&leave_event_stub, &room_version)
|
||||
ruma::signatures::reference_hash(&leave_event_stub, &room_version_id)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruma::{
|
|||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType, StateEvent,
|
||||
},
|
||||
serde::{CanonicalJsonObject, CanonicalJsonValue, Raw},
|
||||
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
|
||||
state_res, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
|
|
@ -35,9 +35,9 @@ use ruma::{
|
|||
},
|
||||
serde::Raw,
|
||||
signatures::{CanonicalJsonObject, CanonicalJsonValue},
|
||||
state_res::{self, Event, EventMap, RoomVersion, StateMap},
|
||||
uint, EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
|
||||
};
|
||||
use state_res::{Event, EventMap, StateMap};
|
||||
use std::{
|
||||
collections::{btree_map::Entry, BTreeMap, BTreeSet, HashSet},
|
||||
convert::{TryFrom, TryInto},
|
||||
|
@ -745,12 +745,13 @@ pub fn handle_incoming_pdu<'a>(
|
|||
.deserialize()
|
||||
.map_err(|_| "Invalid PowerLevels event in db.".to_owned())?;
|
||||
|
||||
let room_version = create_event_content.room_version;
|
||||
let room_version_id = &create_event_content.room_version;
|
||||
let room_version = RoomVersion::new(room_version_id).expect("room version is supported");
|
||||
|
||||
let mut val = match ruma::signatures::verify_event(
|
||||
&*pub_key_map.read().map_err(|_| "RwLock is poisoned.")?,
|
||||
&value,
|
||||
&room_version,
|
||||
room_version_id,
|
||||
) {
|
||||
Err(e) => {
|
||||
// Drop
|
||||
|
@ -760,7 +761,7 @@ pub fn handle_incoming_pdu<'a>(
|
|||
Ok(ruma::signatures::Verified::Signatures) => {
|
||||
// Redact
|
||||
warn!("Calculated hash does not match: {}", event_id);
|
||||
match ruma::signatures::redact(&value, &room_version) {
|
||||
match ruma::signatures::redact(&value, room_version_id) {
|
||||
Ok(obj) => obj,
|
||||
Err(_) => return Err("Redaction failed".to_string()),
|
||||
}
|
||||
|
@ -1162,7 +1163,7 @@ pub fn handle_incoming_pdu<'a>(
|
|||
|
||||
match state_res::StateResolution::resolve(
|
||||
&room_id,
|
||||
&room_version,
|
||||
room_version_id,
|
||||
&fork_states
|
||||
.into_iter()
|
||||
.map(|map| {
|
||||
|
@ -1718,9 +1719,12 @@ pub fn create_join_event_template_route<'a>(
|
|||
};
|
||||
|
||||
// If there was no create event yet, assume we are creating a version 6 room right now
|
||||
let room_version = create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
});
|
||||
let room_version = RoomVersion::new(
|
||||
&create_event_content.map_or(RoomVersionId::Version6, |create_event| {
|
||||
create_event.room_version
|
||||
}),
|
||||
)
|
||||
.expect("room version is supported");
|
||||
|
||||
let content = serde_json::to_value(MemberEventContent {
|
||||
avatar_url: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue