fix: show device display names

This commit is contained in:
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]]
name = "async-trait"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26c4f3195085c36ea8d24d32b2f828d23296a9370a28aa39d111f6f16bef9f3b"
checksum = "0eb7f9ad01405feb3c1dac82463038945cf88eea4569acaf3ad662233496dd96"
dependencies = [
"proc-macro2 1.0.18",
"quote 1.0.6",

View file

@ -15,7 +15,7 @@ edition = "2018"
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async", features = ["tls"] }
http = "0.2.1"
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-events = { git = "https://github.com/ruma/ruma-events.git", rev = "4d09416cd1663d63c22153705c9e1fd77910797f" }
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},
capabilities::get_capabilities,
config::{get_global_account_data, set_global_account_data},
device::{
self, delete_device, delete_devices, get_device, get_devices, update_device,
},
device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
directory::{
self, get_public_rooms, get_public_rooms_filtered, get_room_visibility,
set_room_visibility,
},
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},
membership::{
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
let device_id = body
.device_id.clone()
.device_id
.clone()
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH));
// Generate new token for the device
@ -184,7 +183,12 @@ pub fn register_route(
// Add device
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();
// Initial data
@ -311,7 +315,12 @@ pub fn login_route(
// Add device
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();
MatrixResult(Ok(login::Response {
@ -758,11 +767,21 @@ pub fn get_keys_route(
for (user_id, device_ids) in &body.device_keys {
if device_ids.is_empty() {
let mut container = BTreeMap::new();
for (device_id, keys) in db
for (device_id, mut keys) in db
.users
.all_device_keys(&user_id.clone())
.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);
}
device_keys.insert(user_id.clone(), container);
@ -770,7 +789,18 @@ pub fn get_keys_route(
for device_id in device_ids {
let mut container = BTreeMap::new();
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);
}
@ -1288,11 +1318,11 @@ pub fn get_alias_route(
}))
} else {
debug!("Room alias not found.");
return MatrixResult(Err(Error {
MatrixResult(Err(Error {
kind: ErrorKind::NotFound,
message: "Room with alias not found.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST,
}));
}))
}
} else {
todo!("ask remote server");

View file

@ -329,15 +329,11 @@ impl Rooms {
false
} else if let member::MembershipState::Ban = current_membership {
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 {
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 {
if let Some(third_party_invite_json) = content.get("third_party_invite")
@ -351,46 +347,35 @@ impl Rooms {
)?;
todo!("handle third party invites");
}
} else if sender_membership != member::MembershipState::Join {
false
} else if current_membership == member::MembershipState::Join
} else if sender_membership != member::MembershipState::Join
|| current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Ban
{
false
} else if sender_power
.filter(|&p| p >= &power_levels.invite)
.is_some()
{
true
} else {
false
sender_power
.filter(|&p| p >= &power_levels.invite)
.is_some()
}
} else if target_membership == member::MembershipState::Leave {
if sender == target_user_id {
current_membership == member::MembershipState::Join
|| current_membership == member::MembershipState::Invite
} else if sender_membership != member::MembershipState::Join {
false
} else if current_membership == member::MembershipState::Ban
&& sender_power.filter(|&p| p < &power_levels.ban).is_some()
} else if sender_membership != member::MembershipState::Join
|| current_membership == member::MembershipState::Ban
&& sender_power.filter(|&p| p < &power_levels.ban).is_some()
{
false
} else if sender_power.filter(|&p| p >= &power_levels.kick).is_some()
&& target_power < sender_power
{
true
} else {
false
sender_power.filter(|&p| p >= &power_levels.kick).is_some()
&& target_power < sender_power
}
} else if target_membership == member::MembershipState::Ban {
if sender_membership != member::MembershipState::Join {
false
} else if sender_power.filter(|&p| p >= &power_levels.ban).is_some()
&& target_power < sender_power
{
true
} else {
false
sender_power.filter(|&p| p >= &power_levels.ban).is_some()
&& target_power < sender_power
}
} else {
false
@ -668,16 +653,21 @@ impl Rooms {
globals: &super::globals::Globals,
) -> Result<()> {
if let Some(room_id) = room_id {
// New alias
self.alias_roomid
.insert(alias.alias(), &*room_id.to_string())?;
let mut aliasid = room_id.to_string().as_bytes().to_vec();
aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes());
self.aliasid_alias.insert(aliasid, &*alias.alias())?;
} else {
if let Some(room_id) = self.alias_roomid.remove(alias.alias())? {
for key in self.aliasid_alias.scan_prefix(room_id).keys() {
self.aliasid_alias.remove(key?)?;
}
// room_id=None means remove alias
let room_id = self
.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| {
let (key, value) = r?;
Ok((
utils::string_from_bytes(
key.rsplit(|&b| b == 0xff)
.next()
.ok_or(Error::BadDatabase("userdeviceid is invalid"))?,
)?,
serde_json::from_slice(&*value)?,
))
let userdeviceid = utils::string_from_bytes(
key.rsplit(|&b| b == 0xff)
.next()
.ok_or(Error::BadDatabase("userdeviceid is invalid"))?,
)?;
Ok((userdeviceid, serde_json::from_slice(&*value)?))
})
}