mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-20 19:15:59 +01:00
refactor: use <_> instead of <_parameter_name>
This commit is contained in:
parent
cc411c530b
commit
489cbc0a93
7 changed files with 407 additions and 403 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -275,6 +275,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"sled",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1484,7 +1485,6 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67#8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"atomic",
|
||||
|
@ -1509,7 +1509,6 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket_codegen"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67#8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67"
|
||||
dependencies = [
|
||||
"devise",
|
||||
"glob",
|
||||
|
@ -1521,7 +1520,6 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket_http"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67#8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67"
|
||||
dependencies = [
|
||||
"cookie",
|
||||
"http",
|
||||
|
@ -1543,7 +1541,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"ruma-api",
|
||||
"ruma-client-api",
|
||||
|
@ -1558,7 +1556,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api"
|
||||
version = "0.16.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"http",
|
||||
"percent-encoding",
|
||||
|
@ -1573,7 +1571,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-api-macros"
|
||||
version = "0.16.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1583,7 +1581,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"http",
|
||||
"js_int",
|
||||
|
@ -1600,7 +1598,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-serde",
|
||||
|
@ -1612,7 +1610,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.21.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
|
@ -1627,7 +1625,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-events-macros"
|
||||
version = "0.21.3"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1637,7 +1635,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.0.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-api",
|
||||
|
@ -1652,7 +1650,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
|
@ -1662,7 +1660,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-identifiers-macros"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1673,7 +1671,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-serde"
|
||||
version = "0.2.2"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
|
@ -1685,7 +1683,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.6.0-dev.1"
|
||||
source = "git+https://github.com/ruma/ruma?rev=e047c647ddcb368e7eb1e05ae8823a9494273457#e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||
source = "git+https://github.com/ruma/ruma?rev=d5d2d1d893fa12d27960e4c58d6c09b215d06e95#d5d2d1d893fa12d27960e4c58d6c09b215d06e95"
|
||||
dependencies = [
|
||||
"base64 0.12.3",
|
||||
"ring",
|
||||
|
|
|
@ -13,8 +13,11 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
# TODO: This can become optional as soon as proper configs are supported
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67", features = ["tls"], optional = false } # Used to handle requests
|
||||
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" } # Used for matrix spec type definitions and helpers
|
||||
#rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "8d779caa22c63b15a6c3ceb75d8f6d4971b2eb67", features = ["tls"] } # Used to handle requests
|
||||
rocket = { path = "../rocket/core/lib", features = ["tls"] }
|
||||
|
||||
tokio = "0.2.22" # Used for long polling
|
||||
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "d5d2d1d893fa12d27960e4c58d6c09b215d06e95" } # Used for matrix spec type definitions and helpers
|
||||
sled = "0.32.0" # Used for storing data permanently
|
||||
log = "0.4.8" # Used for emitting log entries
|
||||
http = "0.2.1" # Used for rocket<->ruma conversions
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,9 @@ use directories::ProjectDirs;
|
|||
use log::info;
|
||||
use std::fs::remove_dir_all;
|
||||
|
||||
use rocket::Config;
|
||||
use futures::StreamExt;
|
||||
use rocket::{futures, Config};
|
||||
use ruma::{DeviceId, UserId};
|
||||
|
||||
pub struct Database {
|
||||
pub globals: globals::Globals,
|
||||
|
@ -124,4 +126,77 @@ impl Database {
|
|||
_db: db,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> () {
|
||||
let mut userid_prefix = user_id.to_string().as_bytes().to_vec();
|
||||
userid_prefix.push(0xff);
|
||||
let mut userdeviceid_prefix = userid_prefix.clone();
|
||||
userdeviceid_prefix.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid_prefix.push(0xff);
|
||||
|
||||
let mut futures = futures::stream::FuturesUnordered::new();
|
||||
|
||||
futures.push(self.users.keychangeid_userid.watch_prefix(b""));
|
||||
|
||||
// Return when *any* user changed his key
|
||||
// TODO: only send for user they share a room with
|
||||
futures.push(
|
||||
self.users
|
||||
.todeviceid_events
|
||||
.watch_prefix(&userdeviceid_prefix),
|
||||
);
|
||||
|
||||
// TODO: only send for user they share a room with
|
||||
futures.push(self.global_edus.presenceid_presence.watch_prefix(b""));
|
||||
|
||||
futures.push(self.rooms.userroomid_joined.watch_prefix(&userid_prefix));
|
||||
futures.push(self.rooms.userroomid_invited.watch_prefix(&userid_prefix));
|
||||
futures.push(self.rooms.userroomid_left.watch_prefix(&userid_prefix));
|
||||
|
||||
// Events for rooms we are in
|
||||
for room_id in self.rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
||||
let mut roomid_prefix = room_id.to_string().as_bytes().to_vec();
|
||||
roomid_prefix.push(0xff);
|
||||
|
||||
// PDUs
|
||||
futures.push(self.rooms.pduid_pdu.watch_prefix(&roomid_prefix));
|
||||
|
||||
// EDUs
|
||||
futures.push(
|
||||
self.rooms
|
||||
.edus
|
||||
.roomid_lastroomactiveupdate
|
||||
.watch_prefix(&roomid_prefix),
|
||||
);
|
||||
|
||||
futures.push(
|
||||
self.rooms
|
||||
.edus
|
||||
.roomlatestid_roomlatest
|
||||
.watch_prefix(&roomid_prefix),
|
||||
);
|
||||
|
||||
// Room account data
|
||||
let mut roomuser_prefix = roomid_prefix.clone();
|
||||
roomuser_prefix.extend_from_slice(&userid_prefix);
|
||||
|
||||
futures.push(
|
||||
self.account_data
|
||||
.roomuserdataid_accountdata
|
||||
.watch_prefix(&roomuser_prefix),
|
||||
);
|
||||
}
|
||||
|
||||
let mut globaluserdata_prefix = vec![0xff];
|
||||
globaluserdata_prefix.extend_from_slice(&userid_prefix);
|
||||
|
||||
futures.push(
|
||||
self.account_data
|
||||
.roomuserdataid_accountdata
|
||||
.watch_prefix(&globaluserdata_prefix),
|
||||
);
|
||||
|
||||
// Wait until one of them finds something
|
||||
futures.next().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -666,7 +666,7 @@ impl Rooms {
|
|||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
until: u64,
|
||||
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
|
||||
) -> impl Iterator<Item = Result<(u64, PduEvent)>> {
|
||||
// Create the first part of the full pdu id
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
@ -677,6 +677,7 @@ impl Rooms {
|
|||
let current: &[u8] = ¤t;
|
||||
|
||||
let user_id = user_id.clone();
|
||||
let prefixlen = prefix.len();
|
||||
self.pduid_pdu
|
||||
.range(..current)
|
||||
.rev()
|
||||
|
@ -688,7 +689,11 @@ impl Rooms {
|
|||
if pdu.sender != user_id {
|
||||
pdu.unsigned.remove("transaction_id");
|
||||
}
|
||||
Ok((k, pdu))
|
||||
Ok((
|
||||
utils::u64_from_bytes(&k[prefixlen..])
|
||||
.map_err(|_| Error::bad_database("Invalid pdu id in db."))?,
|
||||
pdu,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -699,7 +704,7 @@ impl Rooms {
|
|||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
from: u64,
|
||||
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
|
||||
) -> impl Iterator<Item = Result<(u64, PduEvent)>> {
|
||||
// Create the first part of the full pdu id
|
||||
let mut prefix = room_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
|
@ -710,6 +715,7 @@ impl Rooms {
|
|||
let current: &[u8] = ¤t;
|
||||
|
||||
let user_id = user_id.clone();
|
||||
let prefixlen = prefix.len();
|
||||
self.pduid_pdu
|
||||
.range(current..)
|
||||
.filter_map(|r| r.ok())
|
||||
|
@ -720,7 +726,11 @@ impl Rooms {
|
|||
if pdu.sender != user_id {
|
||||
pdu.unsigned.remove("transaction_id");
|
||||
}
|
||||
Ok((k, pdu))
|
||||
Ok((
|
||||
utils::u64_from_bytes(&k[prefixlen..])
|
||||
.map_err(|_| Error::bad_database("Invalid pdu id in db."))?,
|
||||
pdu,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -919,7 +929,7 @@ impl Rooms {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns an iterator over all left members of a room.
|
||||
/// Returns an iterator over all rooms this user joined.
|
||||
pub fn rooms_joined(&self, user_id: &UserId) -> impl Iterator<Item = Result<RoomId>> {
|
||||
self.userroomid_joined
|
||||
.scan_prefix(user_id.to_string())
|
||||
|
|
|
@ -86,7 +86,7 @@ fn setup_rocket() -> rocket::Rocket {
|
|||
client_server::get_state_events_route,
|
||||
client_server::get_state_events_for_key_route,
|
||||
client_server::get_state_events_for_empty_key_route,
|
||||
client_server::sync_route,
|
||||
client_server::sync_events_route,
|
||||
client_server::get_context_route,
|
||||
client_server::get_message_events_route,
|
||||
client_server::turn_server_route,
|
||||
|
|
|
@ -13,7 +13,7 @@ use {
|
|||
http::Status,
|
||||
response::{self, Responder},
|
||||
tokio::io::AsyncReadExt,
|
||||
Outcome::*,
|
||||
outcome::Outcome::*,
|
||||
Request, State,
|
||||
},
|
||||
ruma::api::Endpoint,
|
||||
|
@ -24,7 +24,7 @@ use {
|
|||
/// first.
|
||||
pub struct Ruma<T> {
|
||||
pub body: T,
|
||||
pub user_id: Option<UserId>,
|
||||
pub sender_id: Option<UserId>,
|
||||
pub device_id: Option<Box<DeviceId>>,
|
||||
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
|
|||
match T::try_from(http_request) {
|
||||
Ok(t) => Success(Ruma {
|
||||
body: t,
|
||||
user_id,
|
||||
sender_id: user_id,
|
||||
device_id,
|
||||
// TODO: Can we avoid parsing it again? (We only need this for append_pdu)
|
||||
json_body: utils::string_from_bytes(&body)
|
||||
|
|
Loading…
Reference in a new issue