Update to latest ruma/ruma commit
This will most likely be the API that is released to crates.io so it should be fairly stable...
This commit is contained in:
parent
63e23154f3
commit
d02685a4fd
8 changed files with 205 additions and 217 deletions
|
@ -220,7 +220,7 @@ pub fn register_route(
|
|||
Ok(register::Response {
|
||||
access_token: Some(token),
|
||||
user_id,
|
||||
device_id: Some(device_id),
|
||||
device_id: Some(device_id.into_boxed_str()),
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ pub fn login_route(
|
|||
.body
|
||||
.device_id
|
||||
.clone()
|
||||
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH));
|
||||
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into_boxed_str());
|
||||
|
||||
// Generate a new token for the device
|
||||
let token = utils::random_string(TOKEN_LENGTH);
|
||||
|
@ -285,7 +285,7 @@ pub fn login_route(
|
|||
user_id,
|
||||
access_token: token,
|
||||
home_server: Some(db.globals.server_name().to_string()),
|
||||
device_id,
|
||||
device_id: device_id.to_string(),
|
||||
well_known: None,
|
||||
}
|
||||
.into())
|
||||
|
@ -898,7 +898,7 @@ pub fn get_keys_route(
|
|||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
container.insert(device_id.to_owned(), keys);
|
||||
container.insert(device_id.to_owned().into_boxed_str(), keys);
|
||||
}
|
||||
}
|
||||
device_keys.insert(user_id.clone(), container);
|
||||
|
@ -917,7 +917,7 @@ pub fn get_keys_route(
|
|||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
container.insert(device_id.clone(), keys);
|
||||
container.insert(device_id.to_string().into_boxed_str(), keys);
|
||||
}
|
||||
device_keys.insert(user_id.clone(), container);
|
||||
}
|
||||
|
@ -1214,21 +1214,19 @@ pub fn create_room_route(
|
|||
}
|
||||
})?;
|
||||
|
||||
let mut content = ruma::events::room::create::CreateEventContent::new(user_id.clone());
|
||||
content.federate = body.creation_content.as_ref().map_or(true, |c| c.federate);
|
||||
content.predecessor = body
|
||||
.creation_content
|
||||
.as_ref()
|
||||
.and_then(|c| c.predecessor.clone());
|
||||
content.room_version = RoomVersionId::version_6();
|
||||
// 1. The room create event
|
||||
db.rooms.append_pdu(
|
||||
room_id.clone(),
|
||||
user_id.clone(),
|
||||
EventType::RoomCreate,
|
||||
serde_json::to_value(ruma::events::room::create::CreateEventContent {
|
||||
creator: user_id.clone(),
|
||||
federate: body.creation_content.as_ref().map_or(true, |c| c.federate),
|
||||
predecessor: body
|
||||
.creation_content
|
||||
.as_ref()
|
||||
.and_then(|c| c.predecessor.clone()),
|
||||
room_version: RoomVersionId::version_6(),
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
serde_json::to_value(content).expect("event is valid, we just created it"),
|
||||
None,
|
||||
Some("".to_owned()),
|
||||
None,
|
||||
|
@ -1329,9 +1327,9 @@ pub fn create_room_route(
|
|||
room_id.clone(),
|
||||
user_id.clone(),
|
||||
EventType::RoomHistoryVisibility,
|
||||
serde_json::to_value(history_visibility::HistoryVisibilityEventContent {
|
||||
history_visibility: history_visibility::HistoryVisibility::Shared,
|
||||
})
|
||||
serde_json::to_value(history_visibility::HistoryVisibilityEventContent::new(
|
||||
history_visibility::HistoryVisibility::Shared,
|
||||
))
|
||||
.expect("event is valid, we just created it"),
|
||||
None,
|
||||
Some("".to_owned()),
|
||||
|
@ -1345,15 +1343,13 @@ pub fn create_room_route(
|
|||
user_id.clone(),
|
||||
EventType::RoomGuestAccess,
|
||||
match preset {
|
||||
create_room::RoomPreset::PublicChat => {
|
||||
serde_json::to_value(guest_access::GuestAccessEventContent {
|
||||
guest_access: guest_access::GuestAccess::Forbidden,
|
||||
})
|
||||
.expect("event is valid, we just created it")
|
||||
}
|
||||
_ => serde_json::to_value(guest_access::GuestAccessEventContent {
|
||||
guest_access: guest_access::GuestAccess::CanJoin,
|
||||
})
|
||||
create_room::RoomPreset::PublicChat => serde_json::to_value(
|
||||
guest_access::GuestAccessEventContent::new(guest_access::GuestAccess::Forbidden),
|
||||
)
|
||||
.expect("event is valid, we just created it"),
|
||||
_ => serde_json::to_value(guest_access::GuestAccessEventContent::new(
|
||||
guest_access::GuestAccess::CanJoin,
|
||||
))
|
||||
.expect("event is valid, we just created it"),
|
||||
},
|
||||
None,
|
||||
|
@ -2567,11 +2563,7 @@ pub fn sync_route(
|
|||
notification_count,
|
||||
},
|
||||
timeline: sync_events::Timeline {
|
||||
limited: if limited || joined_since_last_sync {
|
||||
Some(true)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
limited: limited || joined_since_last_sync,
|
||||
prev_batch,
|
||||
events: room_events,
|
||||
},
|
||||
|
@ -2620,7 +2612,7 @@ pub fn sync_route(
|
|||
{
|
||||
edus.push(
|
||||
serde_json::from_str(
|
||||
&serde_json::to_string(&ruma::events::AnyEphemeralRoomEventStub::Typing(
|
||||
&serde_json::to_string(&ruma::events::AnySyncEphemeralRoomEvent::Typing(
|
||||
db.rooms.edus.roomactives_all(&room_id)?,
|
||||
))
|
||||
.expect("event is valid, we just created it"),
|
||||
|
@ -2632,7 +2624,7 @@ pub fn sync_route(
|
|||
let left_room = sync_events::LeftRoom {
|
||||
account_data: sync_events::AccountData { events: Vec::new() },
|
||||
timeline: sync_events::Timeline {
|
||||
limited: Some(false),
|
||||
limited: false,
|
||||
prev_batch: Some(next_batch.clone()),
|
||||
events: room_events,
|
||||
},
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::{utils, Error, Result};
|
||||
use ruma::identifiers::{ServerName, ServerNameRef};
|
||||
use ruma::identifiers::ServerName;
|
||||
pub const COUNTER: &str = "c";
|
||||
|
||||
pub struct Globals {
|
||||
pub(super) globals: sled::Tree,
|
||||
keypair: ruma::signatures::Ed25519KeyPair,
|
||||
reqwest_client: reqwest::Client,
|
||||
server_name: ServerName,
|
||||
server_name: Box<ServerName>,
|
||||
registration_disabled: bool,
|
||||
}
|
||||
|
||||
|
@ -26,13 +26,12 @@ impl Globals {
|
|||
globals,
|
||||
keypair,
|
||||
reqwest_client: reqwest::Client::new(),
|
||||
server_name: ServerName::try_from(
|
||||
config
|
||||
.get_str("server_name")
|
||||
.unwrap_or("localhost")
|
||||
.to_owned(),
|
||||
)
|
||||
.map_err(|_| Error::BadConfig("Invalid server name"))?,
|
||||
server_name: config
|
||||
.get_str("server_name")
|
||||
.unwrap_or("localhost")
|
||||
.to_string()
|
||||
.try_into()
|
||||
.map_err(|_| crate::Error::bad_database("Private or public keys are invalid."))?,
|
||||
registration_disabled: config.get_bool("registration_disabled").unwrap_or(false),
|
||||
})
|
||||
}
|
||||
|
@ -64,7 +63,7 @@ impl Globals {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn server_name(&self) -> ServerNameRef<'_> {
|
||||
pub fn server_name(&self) -> &ServerName {
|
||||
self.server_name.as_ref()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{utils, Error, Result};
|
|||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
r0::backup::{get_backup_keys::Sessions, BackupAlgorithm, KeyData},
|
||||
r0::backup::{BackupAlgorithm, KeyData, Sessions},
|
||||
},
|
||||
identifiers::{RoomId, UserId},
|
||||
};
|
||||
|
|
|
@ -61,7 +61,7 @@ impl RoomEdus {
|
|||
&self,
|
||||
room_id: &RoomId,
|
||||
since: u64,
|
||||
) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::AnyEphemeralRoomEventStub>>>>
|
||||
) -> Result<impl Iterator<Item = Result<EventJson<ruma::events::AnySyncEphemeralRoomEvent>>>>
|
||||
{
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
|
|
@ -9,7 +9,7 @@ use ruma::{
|
|||
},
|
||||
},
|
||||
events::{AnyToDeviceEvent, EventJson, EventType},
|
||||
identifiers::UserId,
|
||||
identifiers::{DeviceId, UserId},
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
|
||||
|
||||
|
@ -168,7 +168,7 @@ impl Users {
|
|||
pub fn create_device(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
token: &str,
|
||||
initial_device_display_name: Option<String>,
|
||||
) -> Result<()> {
|
||||
|
@ -182,7 +182,7 @@ impl Users {
|
|||
self.userdeviceid_metadata.insert(
|
||||
userdeviceid,
|
||||
serde_json::to_string(&Device {
|
||||
device_id: device_id.to_owned(),
|
||||
device_id: device_id.to_string().into_boxed_str(),
|
||||
display_name: initial_device_display_name,
|
||||
last_seen_ip: None, // TODO
|
||||
last_seen_ts: Some(SystemTime::now()),
|
||||
|
|
16
src/pdu.rs
16
src/pdu.rs
|
@ -2,8 +2,8 @@ use crate::{Error, Result};
|
|||
use js_int::UInt;
|
||||
use ruma::{
|
||||
events::{
|
||||
pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyRoomEventStub,
|
||||
AnyStateEvent, AnyStateEventStub, AnyStrippedStateEventStub, EventJson, EventType,
|
||||
pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent,
|
||||
AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType,
|
||||
StateEvent,
|
||||
},
|
||||
identifiers::{EventId, RoomId, UserId},
|
||||
|
@ -79,9 +79,9 @@ impl PduEvent {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn to_room_event_stub(&self) -> EventJson<AnyRoomEventStub> {
|
||||
pub fn to_room_event_stub(&self) -> EventJson<AnySyncRoomEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyRoomEventStub>>(&json)
|
||||
serde_json::from_str::<EventJson<AnySyncRoomEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
}
|
||||
pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> {
|
||||
|
@ -94,14 +94,14 @@ impl PduEvent {
|
|||
serde_json::from_str::<EventJson<AnyStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
}
|
||||
pub fn to_state_event_stub(&self) -> EventJson<AnyStateEventStub> {
|
||||
pub fn to_state_event_stub(&self) -> EventJson<AnySyncStateEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyStateEventStub>>(&json)
|
||||
serde_json::from_str::<EventJson<AnySyncStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
}
|
||||
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEventStub> {
|
||||
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> {
|
||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||
serde_json::from_str::<EventJson<AnyStrippedStateEventStub>>(&json)
|
||||
serde_json::from_str::<EventJson<AnyStrippedStateEvent>>(&json)
|
||||
.expect("EventJson::from_str always works")
|
||||
}
|
||||
pub fn to_member_event(&self) -> EventJson<StateEvent<MemberEventContent>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue