1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-17 13:00:50 +01:00

Rename userid_avatar_url to userid_avatarurl and fix debug print

Run cargo fmt

Took 5 minutes
This commit is contained in:
Marcel 2020-04-09 21:01:39 +02:00
parent b1284fd509
commit 49fe5e3271
3 changed files with 28 additions and 35 deletions

View file

@ -84,13 +84,13 @@ impl Data {
/// Removes a avatar_url. /// Removes a avatar_url.
pub fn avatar_url_remove(&self, user_id: &UserId) { pub fn avatar_url_remove(&self, user_id: &UserId) {
self.db.userid_avatar_url.remove(user_id).unwrap(); self.db.userid_avatarurl.remove(user_id).unwrap();
} }
/// Set a new avatar_url. /// Set a new avatar_url.
pub fn avatar_url_set(&self, user_id: &UserId, avatar_url: String) { pub fn avatar_url_set(&self, user_id: &UserId, avatar_url: String) {
self.db self.db
.userid_avatar_url .userid_avatarurl
.insert(user_id.to_string(), &*avatar_url) .insert(user_id.to_string(), &*avatar_url)
.unwrap(); .unwrap();
} }
@ -98,7 +98,7 @@ impl Data {
/// Get a the avatar_url of a user. /// Get a the avatar_url of a user.
pub fn avatar_url_get(&self, user_id: &UserId) -> Option<String> { pub fn avatar_url_get(&self, user_id: &UserId) -> Option<String> {
self.db self.db
.userid_avatar_url .userid_avatarurl
.get(user_id.to_string()) .get(user_id.to_string())
.unwrap() .unwrap()
.map(|bytes| utils::string_from_bytes(&bytes)) .map(|bytes| utils::string_from_bytes(&bytes))

View file

@ -53,7 +53,7 @@ pub struct Database {
pub userid_password: sled::Tree, pub userid_password: sled::Tree,
pub userid_deviceids: MultiValue, pub userid_deviceids: MultiValue,
pub userid_displayname: sled::Tree, pub userid_displayname: sled::Tree,
pub userid_avatar_url: sled::Tree, pub userid_avatarurl: sled::Tree,
pub deviceid_token: sled::Tree, pub deviceid_token: sled::Tree,
pub token_userid: sled::Tree, pub token_userid: sled::Tree,
pub pduid_pdus: sled::Tree, pub pduid_pdus: sled::Tree,
@ -78,7 +78,7 @@ impl Database {
userid_password: db.open_tree("userid_password").unwrap(), userid_password: db.open_tree("userid_password").unwrap(),
userid_deviceids: MultiValue(db.open_tree("userid_deviceids").unwrap()), userid_deviceids: MultiValue(db.open_tree("userid_deviceids").unwrap()),
userid_displayname: db.open_tree("userid_displayname").unwrap(), userid_displayname: db.open_tree("userid_displayname").unwrap(),
userid_avatar_url: db.open_tree("userid_avatar_url").unwrap(), userid_avatarurl: db.open_tree("userid_avatarurl").unwrap(),
deviceid_token: db.open_tree("deviceid_token").unwrap(), deviceid_token: db.open_tree("deviceid_token").unwrap(),
token_userid: db.open_tree("token_userid").unwrap(), token_userid: db.open_tree("token_userid").unwrap(),
pduid_pdus: db.open_tree("pduid_pdus").unwrap(), pduid_pdus: db.open_tree("pduid_pdus").unwrap(),
@ -107,7 +107,7 @@ impl Database {
String::from_utf8_lossy(&v), String::from_utf8_lossy(&v),
); );
} }
println!("# AccountData -> Displayname:"); println!("# UserId -> Displayname:");
for (k, v) in self.userid_displayname.iter().map(|r| r.unwrap()) { for (k, v) in self.userid_displayname.iter().map(|r| r.unwrap()) {
println!( println!(
"{:?} -> {:?}", "{:?} -> {:?}",
@ -115,8 +115,8 @@ impl Database {
String::from_utf8_lossy(&v), String::from_utf8_lossy(&v),
); );
} }
println!("# AccountData -> AvatarURL:"); println!("# UserId -> AvatarURL:");
for (k, v) in self.userid_avatar_url.iter().map(|r| r.unwrap()) { for (k, v) in self.userid_avatarurl.iter().map(|r| r.unwrap()) {
println!( println!(
"{:?} -> {:?}", "{:?} -> {:?}",
String::from_utf8_lossy(&k), String::from_utf8_lossy(&k),

View file

@ -89,7 +89,7 @@ fn register_route(
.unwrap_or_else(|| utils::random_string(GUEST_NAME_LENGTH)), .unwrap_or_else(|| utils::random_string(GUEST_NAME_LENGTH)),
data.hostname() data.hostname()
)) ))
.try_into() .try_into()
{ {
Err(_) => { Err(_) => {
debug!("Username invalid"); debug!("Username invalid");
@ -153,7 +153,7 @@ fn login_route(data: State<Data>, body: Ruma<login::Request>) -> MatrixResult<lo
// Validate login method // Validate login method
let user_id = let user_id =
if let (login::UserInfo::MatrixId(mut username), login::LoginInfo::Password { password }) = if let (login::UserInfo::MatrixId(mut username), login::LoginInfo::Password { password }) =
(body.user.clone(), body.login_info.clone()) (body.user.clone(), body.login_info.clone())
{ {
if !username.contains(':') { if !username.contains(':') {
username = format!("@{}:{}", username, data.hostname()); username = format!("@{}:{}", username, data.hostname());
@ -230,8 +230,8 @@ fn get_pushrules_all_route() -> MatrixResult<get_pushrules_all::Response> {
} }
#[get( #[get(
"/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>", "/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>",
data = "<body>" data = "<body>"
)] )]
fn get_filter_route( fn get_filter_route(
body: Ruma<get_filter::Request>, body: Ruma<get_filter::Request>,
@ -262,8 +262,8 @@ fn create_filter_route(
} }
#[put( #[put(
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>", "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
data = "<body>" data = "<body>"
)] )]
fn set_global_account_data_route( fn set_global_account_data_route(
body: Ruma<set_global_account_data::Request>, body: Ruma<set_global_account_data::Request>,
@ -275,8 +275,8 @@ fn set_global_account_data_route(
} }
#[get( #[get(
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>", "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
data = "<body>" data = "<body>"
)] )]
fn get_global_account_data_route( fn get_global_account_data_route(
body: Ruma<get_global_account_data::Request>, body: Ruma<get_global_account_data::Request>,
@ -317,7 +317,6 @@ fn set_displayname_route(
data.displayname_set(&user_id, body.displayname.clone()); data.displayname_set(&user_id, body.displayname.clone());
// TODO send a new m.room.member join event with the updated displayname // TODO send a new m.room.member join event with the updated displayname
// TODO send a new m.presence event with the updated displayname // TODO send a new m.presence event with the updated displayname
} }
} }
@ -325,8 +324,8 @@ fn set_displayname_route(
} }
#[get( #[get(
"/_matrix/client/r0/profile/<user_id_raw>/displayname", "/_matrix/client/r0/profile/<user_id_raw>/displayname",
data = "<body>" data = "<body>"
)] )]
fn get_displayname_route( fn get_displayname_route(
data: State<Data>, data: State<Data>,
@ -349,9 +348,7 @@ fn get_displayname_route(
})); }));
} }
MatrixResult(Ok(get_display_name::Response { MatrixResult(Ok(get_display_name::Response { displayname: None }))
displayname: None,
}))
} }
#[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")] #[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
@ -374,14 +371,12 @@ fn set_avatar_url_route(
// TODO in the future when we can handle media uploads make sure that this url is our own server // TODO in the future when we can handle media uploads make sure that this url is our own server
// TODO also make sure this is valid mxc:// format (not only starting with it) // TODO also make sure this is valid mxc:// format (not only starting with it)
if body.avatar_url == "" { if body.avatar_url == "" {
data.avatar_url_remove(&user_id); data.avatar_url_remove(&user_id);
} else { } else {
data.avatar_url_set(&user_id, body.displayname.clone()); data.avatar_url_set(&user_id, body.displayname.clone());
// TODO send a new m.room.member join event with the updated avatar_url // TODO send a new m.room.member join event with the updated avatar_url
// TODO send a new m.presence event with the updated avatar_url // TODO send a new m.presence event with the updated avatar_url
} }
MatrixResult(Ok(set_avatar_url::Response)) MatrixResult(Ok(set_avatar_url::Response))
@ -409,9 +404,7 @@ fn get_avatar_url_route(
})); }));
} }
MatrixResult(Ok(get_avatar_url::Response { MatrixResult(Ok(get_avatar_url::Response { avatar_url: None }))
avatar_url: None,
}))
} }
#[get("/_matrix/client/r0/profile/<user_id_raw>", data = "<body>")] #[get("/_matrix/client/r0/profile/<user_id_raw>", data = "<body>")]
@ -527,8 +520,8 @@ fn get_alias_route(room_alias: String) -> MatrixResult<get_alias::Response> {
})); }));
} }
} }
.try_into() .try_into()
.unwrap(); .unwrap();
MatrixResult(Ok(get_alias::Response { MatrixResult(Ok(get_alias::Response {
room_id, room_id,
@ -635,8 +628,8 @@ fn get_protocols_route(
} }
#[put( #[put(
"/_matrix/client/r0/rooms/<_room_id>/send/<_event_type>/<_txn_id>", "/_matrix/client/r0/rooms/<_room_id>/send/<_event_type>/<_txn_id>",
data = "<body>" data = "<body>"
)] )]
fn create_message_event_route( fn create_message_event_route(
data: State<Data>, data: State<Data>,
@ -660,8 +653,8 @@ fn create_message_event_route(
} }
#[put( #[put(
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>", "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
data = "<body>" data = "<body>"
)] )]
fn create_state_event_for_key_route( fn create_state_event_for_key_route(
data: State<Data>, data: State<Data>,
@ -683,8 +676,8 @@ fn create_state_event_for_key_route(
} }
#[put( #[put(
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>", "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
data = "<body>" data = "<body>"
)] )]
fn create_state_event_for_empty_key_route( fn create_state_event_for_empty_key_route(
data: State<Data>, data: State<Data>,