fix: ruma

This commit is contained in:
Timo Kösters 2021-07-15 19:54:04 +02:00
parent d07762f596
commit 0fcefa4125
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
8 changed files with 115 additions and 66 deletions

View file

@ -1,4 +1,8 @@
use std::{collections::BTreeMap, convert::TryInto, sync::Arc};
use std::{
collections::BTreeMap,
convert::{TryFrom, TryInto},
sync::Arc,
};
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
@ -16,7 +20,8 @@ use ruma::{
},
events::{
room::{
canonical_alias, guest_access, history_visibility, join_rules, member, message, name,
canonical_alias, guest_access, history_visibility, join_rules, member, message,
name::{self, RoomName},
topic,
},
EventType,
@ -375,11 +380,9 @@ pub async fn register_route(
db.rooms.build_and_append_pdu(
PduBuilder {
event_type: EventType::RoomName,
content: serde_json::to_value(
name::NameEventContent::new("Admin Room".to_owned()).map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.")
})?,
)
content: serde_json::to_value(name::NameEventContent::new(Some(
RoomName::try_from("Admin Room".to_owned()).expect("Room name is valid"),
)))
.expect("event is valid, we just created it"),
unsigned: None,
state_key: Some("".to_owned()),

View file

@ -87,17 +87,17 @@ pub async fn set_room_visibility_route(
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
match &body.visibility {
room::Visibility::_Custom(_s) => {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room visibility type is not supported.",
));
}
room::Visibility::Public => {
db.rooms.set_public(&body.room_id, true)?;
info!("{} made {} public", sender_user, body.room_id);
}
room::Visibility::Private => db.rooms.set_public(&body.room_id, false)?,
_ => {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room visibility type is not supported.",
));
}
}
db.flush().await?;
@ -231,8 +231,8 @@ pub async fn get_public_rooms_filtered_helper(
.map_err(|_| {
Error::bad_database("Invalid room name event in database.")
})?
.name()
.map(|n| n.to_owned()))
.name
.map(|n| n.to_owned().into()))
})?,
num_joined_members: (db.rooms.room_members(&room_id).count() as u32).into(),
topic: db

View file

@ -81,7 +81,7 @@ pub async fn get_pushrule_route(
.content
.get(body.rule_id.as_str())
.map(|rule| rule.clone().into()),
RuleKind::_Custom(_) => None,
_ => None,
};
if let Some(rule) = rule {
@ -181,7 +181,7 @@ pub async fn set_pushrule_route(
.into(),
);
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(
@ -245,7 +245,7 @@ pub async fn get_pushrule_actions_route(
.content
.get(body.rule_id.as_str())
.map(|rule| rule.actions.clone()),
RuleKind::_Custom(_) => None,
_ => None,
};
db.flush().await?;
@ -314,7 +314,7 @@ pub async fn set_pushrule_actions_route(
global.content.replace(rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
};
db.account_data.update(
@ -383,7 +383,7 @@ pub async fn get_pushrule_enabled_route(
.iter()
.find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.enabled),
RuleKind::_Custom(_) => false,
_ => false,
};
db.flush().await?;
@ -454,7 +454,7 @@ pub async fn set_pushrule_enabled_route(
global.content.insert(rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(
@ -523,7 +523,7 @@ pub async fn delete_pushrule_route(
global.content.remove(&rule);
}
}
RuleKind::_Custom(_) => {}
_ => {}
}
db.account_data.update(

View file

@ -9,7 +9,11 @@ use ruma::{
r0::room::{self, create_room, get_room_event, upgrade_room},
},
events::{
room::{guest_access, history_visibility, join_rules, member, name, topic},
room::{
guest_access, history_visibility, join_rules, member,
name::{self, RoomName},
topic,
},
EventType,
},
serde::Raw,
@ -113,7 +117,7 @@ pub async fn create_room_route(
.unwrap_or_else(|| match &body.visibility {
room::Visibility::Private => create_room::RoomPreset::PrivateChat,
room::Visibility::Public => create_room::RoomPreset::PublicChat,
room::Visibility::_Custom(_) => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
_ => create_room::RoomPreset::PrivateChat, // Room visibility should not be custom
});
let mut users = BTreeMap::new();
@ -251,11 +255,11 @@ pub async fn create_room_route(
db.rooms.build_and_append_pdu(
PduBuilder {
event_type: EventType::RoomName,
content: serde_json::to_value(
name::NameEventContent::new(name.clone()).map_err(|_| {
content: serde_json::to_value(name::NameEventContent::new(Some(
RoomName::try_from(name.clone()).map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Name is invalid.")
})?,
)
)))
.expect("event is valid, we just created it"),
unsigned: None,
state_key: Some("".to_owned()),