fix: show device display names

next
timokoesters 2020-06-03 20:55:11 +02:00
parent 325e373684
commit b192fddf2f
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
5 changed files with 75 additions and 57 deletions

4
Cargo.lock generated
View File

@ -26,9 +26,9 @@ checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.31" version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26c4f3195085c36ea8d24d32b2f828d23296a9370a28aa39d111f6f16bef9f3b" checksum = "0eb7f9ad01405feb3c1dac82463038945cf88eea4569acaf3ad662233496dd96"
dependencies = [ dependencies = [
"proc-macro2 1.0.18", "proc-macro2 1.0.18",
"quote 1.0.6", "quote 1.0.6",

View File

@ -15,7 +15,7 @@ edition = "2018"
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] } rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] }
http = "0.2.1" http = "0.2.1"
ruma-client-api = { git = "https://github.com/ruma/ruma-client-api.git", rev = "c725288cd099690c1d13f1a9b9e57228bc860a62" } ruma-client-api = { git = "https://github.com/ruma/ruma-client-api.git", rev = "c725288cd099690c1d13f1a9b9e57228bc860a62" }
ruma-identifiers = { version = "0.16.1", features = ["rand"] } ruma-identifiers = { version = "0.16.2", features = ["rand"] }
ruma-api = "0.16.1" ruma-api = "0.16.1"
ruma-events = { git = "https://github.com/ruma/ruma-events.git", rev = "4d09416cd1663d63c22153705c9e1fd77910797f" } ruma-events = { git = "https://github.com/ruma/ruma-events.git", rev = "4d09416cd1663d63c22153705c9e1fd77910797f" }
ruma-signatures = { git = "https://github.com/ruma/ruma-signatures.git", rev = "1ca545cba8dfd43e0fc8e3c18e1311fb73390a97" } ruma-signatures = { git = "https://github.com/ruma/ruma-signatures.git", rev = "1ca545cba8dfd43e0fc8e3c18e1311fb73390a97" }

View File

@ -13,15 +13,13 @@ use ruma_client_api::{
alias::{create_alias, delete_alias, get_alias}, alias::{create_alias, delete_alias, get_alias},
capabilities::get_capabilities, capabilities::get_capabilities,
config::{get_global_account_data, set_global_account_data}, config::{get_global_account_data, set_global_account_data},
device::{ device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
self, delete_device, delete_devices, get_device, get_devices, update_device,
},
directory::{ directory::{
self, get_public_rooms, get_public_rooms_filtered, get_room_visibility, self, get_public_rooms, get_public_rooms_filtered, get_room_visibility,
set_room_visibility, set_room_visibility,
}, },
filter::{self, create_filter, get_filter}, filter::{self, create_filter, get_filter},
keys::{claim_keys, get_keys, upload_keys}, keys::{self, claim_keys, get_keys, upload_keys},
media::{create_content, get_content, get_content_thumbnail, get_media_config}, media::{create_content, get_content, get_content_thumbnail, get_media_config},
membership::{ membership::{
forget_room, get_member_events, invite_user, join_room_by_id, join_room_by_id_or_alias, forget_room, get_member_events, invite_user, join_room_by_id, join_room_by_id_or_alias,
@ -176,7 +174,8 @@ pub fn register_route(
// Generate new device id if the user didn't specify one // Generate new device id if the user didn't specify one
let device_id = body let device_id = body
.device_id.clone() .device_id
.clone()
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH));
// Generate new token for the device // Generate new token for the device
@ -184,7 +183,12 @@ pub fn register_route(
// Add device // Add device
db.users db.users
.create_device(&user_id, &device_id, &token, body.initial_device_display_name.clone()) .create_device(
&user_id,
&device_id,
&token,
body.initial_device_display_name.clone(),
)
.unwrap(); .unwrap();
// Initial data // Initial data
@ -311,7 +315,12 @@ pub fn login_route(
// Add device // Add device
db.users db.users
.create_device(&user_id, &device_id, &token, body.initial_device_display_name.clone()) .create_device(
&user_id,
&device_id,
&token,
body.initial_device_display_name.clone(),
)
.unwrap(); .unwrap();
MatrixResult(Ok(login::Response { MatrixResult(Ok(login::Response {
@ -758,11 +767,21 @@ pub fn get_keys_route(
for (user_id, device_ids) in &body.device_keys { for (user_id, device_ids) in &body.device_keys {
if device_ids.is_empty() { if device_ids.is_empty() {
let mut container = BTreeMap::new(); let mut container = BTreeMap::new();
for (device_id, keys) in db for (device_id, mut keys) in db
.users .users
.all_device_keys(&user_id.clone()) .all_device_keys(&user_id.clone())
.map(|r| r.unwrap()) .map(|r| r.unwrap())
{ {
let metadata = db
.users
.get_device_metadata(user_id, &device_id)
.unwrap()
.expect("this device should exist");
keys.unsigned = Some(keys::UnsignedDeviceInfo {
device_display_name: metadata.display_name,
});
container.insert(device_id, keys); container.insert(device_id, keys);
} }
device_keys.insert(user_id.clone(), container); device_keys.insert(user_id.clone(), container);
@ -770,7 +789,18 @@ pub fn get_keys_route(
for device_id in device_ids { for device_id in device_ids {
let mut container = BTreeMap::new(); let mut container = BTreeMap::new();
for keys in db.users.get_device_keys(&user_id.clone(), &device_id) { for keys in db.users.get_device_keys(&user_id.clone(), &device_id) {
container.insert(device_id.clone(), keys.unwrap()); let mut keys = keys.unwrap();
let metadata = db
.users
.get_device_metadata(user_id, &device_id)
.unwrap()
.expect("this device should exist");
keys.unsigned = Some(keys::UnsignedDeviceInfo {
device_display_name: metadata.display_name,
});
container.insert(device_id.clone(), keys);
} }
device_keys.insert(user_id.clone(), container); device_keys.insert(user_id.clone(), container);
} }
@ -1288,11 +1318,11 @@ pub fn get_alias_route(
})) }))
} else { } else {
debug!("Room alias not found."); debug!("Room alias not found.");
return MatrixResult(Err(Error { MatrixResult(Err(Error {
kind: ErrorKind::NotFound, kind: ErrorKind::NotFound,
message: "Room with alias not found.".to_owned(), message: "Room with alias not found.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST, status_code: http::StatusCode::BAD_REQUEST,
})); }))
} }
} else { } else {
todo!("ask remote server"); todo!("ask remote server");

View File

@ -329,15 +329,11 @@ impl Rooms {
false false
} else if let member::MembershipState::Ban = current_membership { } else if let member::MembershipState::Ban = current_membership {
false false
} else if join_rules == join_rules::JoinRule::Invite
&& (current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Invite)
{
true
} else if join_rules == join_rules::JoinRule::Public {
true
} else { } else {
false join_rules == join_rules::JoinRule::Invite
&& (current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Invite)
|| join_rules == join_rules::JoinRule::Public
} }
} else if target_membership == member::MembershipState::Invite { } else if target_membership == member::MembershipState::Invite {
if let Some(third_party_invite_json) = content.get("third_party_invite") if let Some(third_party_invite_json) = content.get("third_party_invite")
@ -351,46 +347,35 @@ impl Rooms {
)?; )?;
todo!("handle third party invites"); todo!("handle third party invites");
} }
} else if sender_membership != member::MembershipState::Join { } else if sender_membership != member::MembershipState::Join
false || current_membership == member::MembershipState::Join
} else if current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Ban || current_membership == member::MembershipState::Ban
{ {
false false
} else if sender_power
.filter(|&p| p >= &power_levels.invite)
.is_some()
{
true
} else { } else {
false sender_power
.filter(|&p| p >= &power_levels.invite)
.is_some()
} }
} else if target_membership == member::MembershipState::Leave { } else if target_membership == member::MembershipState::Leave {
if sender == target_user_id { if sender == target_user_id {
current_membership == member::MembershipState::Join current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Invite || current_membership == member::MembershipState::Invite
} else if sender_membership != member::MembershipState::Join { } else if sender_membership != member::MembershipState::Join
false || current_membership == member::MembershipState::Ban
} else if current_membership == member::MembershipState::Ban && sender_power.filter(|&p| p < &power_levels.ban).is_some()
&& sender_power.filter(|&p| p < &power_levels.ban).is_some()
{ {
false false
} else if sender_power.filter(|&p| p >= &power_levels.kick).is_some()
&& target_power < sender_power
{
true
} else { } else {
false sender_power.filter(|&p| p >= &power_levels.kick).is_some()
&& target_power < sender_power
} }
} else if target_membership == member::MembershipState::Ban { } else if target_membership == member::MembershipState::Ban {
if sender_membership != member::MembershipState::Join { if sender_membership != member::MembershipState::Join {
false false
} else if sender_power.filter(|&p| p >= &power_levels.ban).is_some()
&& target_power < sender_power
{
true
} else { } else {
false sender_power.filter(|&p| p >= &power_levels.ban).is_some()
&& target_power < sender_power
} }
} else { } else {
false false
@ -668,16 +653,21 @@ impl Rooms {
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
if let Some(room_id) = room_id { if let Some(room_id) = room_id {
// New alias
self.alias_roomid self.alias_roomid
.insert(alias.alias(), &*room_id.to_string())?; .insert(alias.alias(), &*room_id.to_string())?;
let mut aliasid = room_id.to_string().as_bytes().to_vec(); let mut aliasid = room_id.to_string().as_bytes().to_vec();
aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes()); aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes());
self.aliasid_alias.insert(aliasid, &*alias.alias())?; self.aliasid_alias.insert(aliasid, &*alias.alias())?;
} else { } else {
if let Some(room_id) = self.alias_roomid.remove(alias.alias())? { // room_id=None means remove alias
for key in self.aliasid_alias.scan_prefix(room_id).keys() { let room_id = self
self.aliasid_alias.remove(key?)?; .alias_roomid
} .remove(alias.alias())?
.ok_or(Error::BadRequest("Alias does not exist"))?;
for key in self.aliasid_alias.scan_prefix(room_id).keys() {
self.aliasid_alias.remove(key?)?;
} }
} }

View File

@ -361,14 +361,12 @@ impl Users {
self.userdeviceid_devicekeys.scan_prefix(key).map(|r| { self.userdeviceid_devicekeys.scan_prefix(key).map(|r| {
let (key, value) = r?; let (key, value) = r?;
Ok(( let userdeviceid = utils::string_from_bytes(
utils::string_from_bytes( key.rsplit(|&b| b == 0xff)
key.rsplit(|&b| b == 0xff) .next()
.next() .ok_or(Error::BadDatabase("userdeviceid is invalid"))?,
.ok_or(Error::BadDatabase("userdeviceid is invalid"))?, )?;
)?, Ok((userdeviceid, serde_json::from_slice(&*value)?))
serde_json::from_slice(&*value)?,
))
}) })
} }