Move to depend on ruma monorepo and ruma-events0.22

This commit is contained in:
Devin R 2020-06-21 15:58:42 -04:00
parent 9c095f1538
commit 7c38e53839
10 changed files with 176 additions and 2639 deletions

View file

@ -1,7 +1,7 @@
use crate::{utils, Error, Result};
use ruma::{
api::client::error::ErrorKind,
events::{collections::only::Event as EduEvent, EventJson, EventType},
events::{AnyEvent as EduEvent, EventJson, EventType},
identifiers::{RoomId, UserId},
};
use std::{collections::HashMap, convert::TryFrom};

View file

@ -1,12 +1,14 @@
use crate::{utils, Error, Result};
use std::convert::TryFrom;
use crate::{utils, Error, Result};
use ruma::identifiers::{ServerName, ServerNameRef};
pub const COUNTER: &str = "c";
pub struct Globals {
pub(super) globals: sled::Tree,
keypair: ruma::signatures::Ed25519KeyPair,
reqwest_client: reqwest::Client,
server_name: String,
server_name: ServerName,
registration_disabled: bool,
}
@ -24,10 +26,13 @@ impl Globals {
globals,
keypair,
reqwest_client: reqwest::Client::new(),
server_name: config
.get_str("server_name")
.unwrap_or("localhost")
.to_owned(),
server_name: ServerName::try_from(
config
.get_str("server_name")
.unwrap_or("localhost")
.to_owned(),
)
.map_err(|_| Error::bad_database("Invalid server name"))?,
registration_disabled: config.get_bool("registration_disabled").unwrap_or(false),
})
}
@ -59,8 +64,8 @@ impl Globals {
})
}
pub fn server_name(&self) -> &str {
&self.server_name
pub fn server_name(&self) -> ServerNameRef<'_> {
self.server_name.as_ref()
}
pub fn registration_disabled(&self) -> bool {

View file

@ -515,7 +515,7 @@ impl Rooms {
event_id: EventId::try_from("$thiswillbefilledinlater").expect("we know this is valid"),
room_id: room_id.clone(),
sender: sender.clone(),
origin: globals.server_name().to_owned(),
origin: globals.server_name().to_string(),
origin_server_ts: utils::millis_since_unix_epoch()
.try_into()
.expect("time is valid"),
@ -529,7 +529,7 @@ impl Rooms {
auth_events: Vec::new(),
redacts: redacts.clone(),
unsigned,
hashes: ruma::api::federation::EventHash {
hashes: ruma::events::pdu::EventHash {
sha256: "aaa".to_owned(),
},
signatures: HashMap::new(),
@ -547,7 +547,7 @@ impl Rooms {
let mut pdu_json = serde_json::to_value(&pdu).expect("event is valid, we just created it");
ruma::signatures::hash_and_sign_event(
globals.server_name(),
globals.server_name().as_str(),
globals.keypair(),
&mut pdu_json,
)

View file

@ -1,6 +1,6 @@
use crate::{utils, Error, Result};
use ruma::{
events::{collections::only::Event as EduEvent, EventJson},
events::{AnyEvent as EduEvent, EventJson},
identifiers::{RoomId, UserId},
};
use std::convert::TryFrom;
@ -235,7 +235,7 @@ impl RoomEdus {
Ok(ruma::events::typing::TypingEvent {
content: ruma::events::typing::TypingEventContent { user_ids },
room_id: None, // Can be inferred
room_id: room_id.clone(), // Can be inferred
})
}

View file

@ -8,7 +8,7 @@ use ruma::{
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
},
},
events::{to_device::AnyToDeviceEvent, EventJson, EventType},
events::{AnyToDeviceEvent, EventJson, EventType},
identifiers::UserId,
};
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};