mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-19 02:40:49 +01:00
refactor: replace DeviceId with str or String
This commit is contained in:
parent
b4d65ab67d
commit
588049678b
4 changed files with 29 additions and 29 deletions
|
@ -56,7 +56,7 @@ use ruma::{
|
|||
room::{canonical_alias, guest_access, history_visibility, join_rules, member, redaction},
|
||||
EventJson, EventType,
|
||||
},
|
||||
identifiers::{DeviceId, RoomAliasId, RoomId, RoomVersionId, UserId},
|
||||
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
|
||||
};
|
||||
use serde_json::{json, value::RawValue};
|
||||
|
||||
|
@ -2841,13 +2841,15 @@ pub fn get_devices_route(
|
|||
MatrixResult(Ok(get_devices::Response { devices }))
|
||||
}
|
||||
|
||||
#[get("/_matrix/client/r0/devices/<device_id>", data = "<body>")]
|
||||
#[get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||
pub fn get_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<get_device::Request>,
|
||||
device_id: DeviceId,
|
||||
_device_id: String,
|
||||
) -> MatrixResult<get_device::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let device = db.users.get_device_metadata(&user_id, &device_id).unwrap();
|
||||
|
||||
match device {
|
||||
|
@ -2860,13 +2862,15 @@ pub fn get_device_route(
|
|||
}
|
||||
}
|
||||
|
||||
#[put("/_matrix/client/r0/devices/<device_id>", data = "<body>")]
|
||||
#[put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||
pub fn update_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<update_device::Request>,
|
||||
device_id: DeviceId,
|
||||
_device_id: String,
|
||||
) -> MatrixResult<update_device::Response> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
||||
|
||||
let device = db.users.get_device_metadata(&user_id, &device_id).unwrap();
|
||||
|
||||
match device {
|
||||
|
@ -2887,13 +2891,14 @@ pub fn update_device_route(
|
|||
}
|
||||
}
|
||||
|
||||
#[delete("/_matrix/client/r0/devices/<device_id>", data = "<body>")]
|
||||
#[delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||
pub fn delete_device_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<delete_device::Request>,
|
||||
device_id: DeviceId,
|
||||
_device_id: String,
|
||||
) -> MatrixResult<delete_device::Response, UiaaResponse> {
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
||||
|
||||
// UIAA
|
||||
let uiaainfo = UiaaInfo {
|
||||
|
|
|
@ -11,7 +11,7 @@ use ruma::{
|
|||
},
|
||||
},
|
||||
events::{to_device::AnyToDeviceEvent, EventJson, EventType},
|
||||
identifiers::{DeviceId, UserId},
|
||||
identifiers::UserId,
|
||||
};
|
||||
use serde_json::value::RawValue;
|
||||
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
|
||||
|
@ -29,7 +29,7 @@ impl Uiaa {
|
|||
pub fn try_auth(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
auth: &AuthData,
|
||||
uiaainfo: &UiaaInfo,
|
||||
users: &super::users::Users,
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruma::{
|
|||
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
|
||||
},
|
||||
events::{to_device::AnyToDeviceEvent, EventJson, EventType},
|
||||
identifiers::{DeviceId, UserId},
|
||||
identifiers::UserId,
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
|
||||
|
||||
|
@ -113,7 +113,7 @@ impl Users {
|
|||
pub fn create_device(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
token: &str,
|
||||
initial_device_display_name: Option<String>,
|
||||
) -> Result<()> {
|
||||
|
@ -130,7 +130,7 @@ impl Users {
|
|||
self.userdeviceid_metadata.insert(
|
||||
userdeviceid,
|
||||
serde_json::to_string(&Device {
|
||||
device_id: device_id.clone(),
|
||||
device_id: device_id.to_owned(),
|
||||
display_name: initial_device_display_name,
|
||||
last_seen_ip: None, // TODO
|
||||
last_seen_ts: Some(SystemTime::now()),
|
||||
|
@ -144,7 +144,7 @@ impl Users {
|
|||
}
|
||||
|
||||
/// Removes a device from a user.
|
||||
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
|
||||
pub fn remove_device(&self, user_id: &UserId, device_id: &str) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
@ -173,7 +173,7 @@ impl Users {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all device ids of this user.
|
||||
pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<DeviceId>> {
|
||||
pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<String>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
// All devices have metadata
|
||||
|
@ -191,7 +191,7 @@ impl Users {
|
|||
}
|
||||
|
||||
/// Replaces the access token of one device.
|
||||
pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> {
|
||||
pub fn set_token(&self, user_id: &UserId, device_id: &str, token: &str) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
@ -219,7 +219,7 @@ impl Users {
|
|||
pub fn add_one_time_key(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
one_time_key_key: &AlgorithmAndDeviceId,
|
||||
one_time_key_value: &OneTimeKey,
|
||||
) -> Result<()> {
|
||||
|
@ -248,7 +248,7 @@ impl Users {
|
|||
pub fn take_one_time_key(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
key_algorithm: &KeyAlgorithm,
|
||||
) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
|
@ -282,7 +282,7 @@ impl Users {
|
|||
pub fn count_one_time_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
|
@ -315,7 +315,7 @@ impl Users {
|
|||
pub fn add_device_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
device_keys: &DeviceKeys,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
|
@ -335,7 +335,7 @@ impl Users {
|
|||
pub fn get_device_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
) -> impl Iterator<Item = Result<DeviceKeys>> {
|
||||
let mut key = user_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
|
@ -376,7 +376,7 @@ impl Users {
|
|||
&self,
|
||||
sender: &UserId,
|
||||
target_user_id: &UserId,
|
||||
target_device_id: &DeviceId,
|
||||
target_device_id: &str,
|
||||
event_type: &EventType,
|
||||
content: serde_json::Value,
|
||||
globals: &super::globals::Globals,
|
||||
|
@ -401,7 +401,7 @@ impl Users {
|
|||
pub fn take_to_device_events(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
max: usize,
|
||||
) -> Result<Vec<EventJson<AnyToDeviceEvent>>> {
|
||||
let mut events = Vec::new();
|
||||
|
@ -423,7 +423,7 @@ impl Users {
|
|||
pub fn update_device_metadata(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device_id: &str,
|
||||
device: &Device,
|
||||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
|
@ -441,11 +441,7 @@ impl Users {
|
|||
}
|
||||
|
||||
/// Get device metadata.
|
||||
pub fn get_device_metadata(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
) -> Result<Option<Device>> {
|
||||
pub fn get_device_metadata(&self, user_id: &UserId, device_id: &str) -> Result<Option<Device>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
|
|
|
@ -43,7 +43,6 @@ GET /profile/:user_id/displayname publicly accessible
|
|||
GET /device/{deviceId} gives a 404 for unknown devices
|
||||
PUT /device/{deviceId} gives a 404 for unknown devices
|
||||
After deactivating account, can't log in with an email
|
||||
Can create filter
|
||||
Should reject keys claiming to belong to a different user
|
||||
Can add account data
|
||||
Checking local federation server
|
||||
|
|
Loading…
Reference in a new issue