Update to latest ruma/master rev
This commit is contained in:
parent
61458536ab
commit
60381ddcf4
7 changed files with 248 additions and 218 deletions
|
@ -169,14 +169,14 @@ pub fn register_route(
|
|||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) =
|
||||
db.uiaa
|
||||
.try_auth(&user_id, "", auth, &uiaainfo, &db.users, &db.globals)?;
|
||||
.try_auth(&user_id, "".into(), auth, &uiaainfo, &db.users, &db.globals)?;
|
||||
if !worked {
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
// Success!
|
||||
} else {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa.create(&user_id, "", &uiaainfo)?;
|
||||
db.uiaa.create(&user_id, "".into(), &uiaainfo)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ pub fn register_route(
|
|||
let device_id = body
|
||||
.device_id
|
||||
.clone()
|
||||
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH));
|
||||
.unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into());
|
||||
|
||||
// Generate new token for the device
|
||||
let token = utils::random_string(TOKEN_LENGTH);
|
||||
|
@ -300,7 +300,7 @@ pub fn logout_route(
|
|||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
||||
|
||||
db.users.remove_device(&user_id, &device_id)?;
|
||||
db.users.remove_device(&user_id, device_id)?;
|
||||
|
||||
Ok(logout::Response.into())
|
||||
}
|
||||
|
@ -340,14 +340,9 @@ pub fn change_password_route(
|
|||
};
|
||||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&user_id,
|
||||
&device_id,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
&db.users,
|
||||
&db.globals,
|
||||
)?;
|
||||
let (worked, uiaainfo) =
|
||||
db.uiaa
|
||||
.try_auth(&user_id, device_id, auth, &uiaainfo, &db.users, &db.globals)?;
|
||||
if !worked {
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
|
@ -452,11 +447,11 @@ pub fn deactivate_route(
|
|||
pub fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> {
|
||||
let mut available = BTreeMap::new();
|
||||
available.insert(
|
||||
RoomVersionId::version_5(),
|
||||
RoomVersionId::Version5,
|
||||
get_capabilities::RoomVersionStability::Stable,
|
||||
);
|
||||
available.insert(
|
||||
RoomVersionId::version_6(),
|
||||
RoomVersionId::Version6,
|
||||
get_capabilities::RoomVersionStability::Stable,
|
||||
);
|
||||
|
||||
|
@ -890,7 +885,7 @@ pub fn get_keys_route(
|
|||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
container.insert(device_id.into(), keys);
|
||||
container.insert(device_id, keys);
|
||||
}
|
||||
}
|
||||
device_keys.insert(user_id.clone(), container);
|
||||
|
@ -909,7 +904,7 @@ pub fn get_keys_route(
|
|||
device_display_name: metadata.display_name,
|
||||
});
|
||||
|
||||
container.insert(device_id.as_ref().into(), keys);
|
||||
container.insert(device_id.clone(), keys);
|
||||
}
|
||||
device_keys.insert(user_id.clone(), container);
|
||||
}
|
||||
|
@ -1212,7 +1207,7 @@ pub fn create_room_route(
|
|||
.creation_content
|
||||
.as_ref()
|
||||
.and_then(|c| c.predecessor.clone());
|
||||
content.room_version = RoomVersionId::version_6();
|
||||
content.room_version = RoomVersionId::Version6;
|
||||
|
||||
// 1. The room create event
|
||||
db.rooms.append_pdu(
|
||||
|
@ -1298,15 +1293,14 @@ pub fn create_room_route(
|
|||
user_id.clone(),
|
||||
EventType::RoomJoinRules,
|
||||
match preset {
|
||||
create_room::RoomPreset::PublicChat => {
|
||||
serde_json::to_value(join_rules::JoinRulesEventContent {
|
||||
join_rule: join_rules::JoinRule::Public,
|
||||
})
|
||||
.expect("event is valid, we just created it")
|
||||
}
|
||||
_ => serde_json::to_value(join_rules::JoinRulesEventContent {
|
||||
join_rule: join_rules::JoinRule::Invite,
|
||||
})
|
||||
create_room::RoomPreset::PublicChat => serde_json::to_value(
|
||||
join_rules::JoinRulesEventContent::new(join_rules::JoinRule::Public),
|
||||
)
|
||||
.expect("event is valid, we just created it"),
|
||||
// according to spec "invite" is the default
|
||||
_ => serde_json::to_value(join_rules::JoinRulesEventContent::new(
|
||||
join_rules::JoinRule::Invite,
|
||||
))
|
||||
.expect("event is valid, we just created it"),
|
||||
},
|
||||
None,
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
r0::uiaa::{AuthData, UiaaInfo},
|
||||
},
|
||||
identifiers::UserId,
|
||||
identifiers::{DeviceId, UserId},
|
||||
};
|
||||
|
||||
pub struct Uiaa {
|
||||
|
@ -13,14 +13,19 @@ pub struct Uiaa {
|
|||
|
||||
impl Uiaa {
|
||||
/// Creates a new Uiaa session. Make sure the session token is unique.
|
||||
pub fn create(&self, user_id: &UserId, device_id: &str, uiaainfo: &UiaaInfo) -> Result<()> {
|
||||
pub fn create(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
uiaainfo: &UiaaInfo,
|
||||
) -> Result<()> {
|
||||
self.update_uiaa_session(user_id, device_id, Some(uiaainfo))
|
||||
}
|
||||
|
||||
pub fn try_auth(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
auth: &AuthData,
|
||||
uiaainfo: &UiaaInfo,
|
||||
users: &super::users::Users,
|
||||
|
@ -130,7 +135,7 @@ impl Uiaa {
|
|||
|
||||
// UIAA was successful! Remove this session and return true
|
||||
self.update_uiaa_session(user_id, device_id, None)?;
|
||||
return Ok((true, uiaainfo));
|
||||
Ok((true, uiaainfo))
|
||||
} else {
|
||||
panic!("FallbackAcknowledgement is not supported yet");
|
||||
}
|
||||
|
@ -139,12 +144,12 @@ impl Uiaa {
|
|||
fn update_uiaa_session(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
uiaainfo: Option<&UiaaInfo>,
|
||||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
if let Some(uiaainfo) = uiaainfo {
|
||||
self.userdeviceid_uiaainfo.insert(
|
||||
|
@ -161,12 +166,12 @@ impl Uiaa {
|
|||
fn get_uiaa_session(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Result<UiaaInfo> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
let uiaainfo = serde_json::from_slice::<UiaaInfo>(
|
||||
&self
|
||||
|
|
|
@ -177,7 +177,7 @@ impl Users {
|
|||
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
self.userdeviceid_metadata.insert(
|
||||
userdeviceid,
|
||||
|
@ -191,16 +191,16 @@ impl Users {
|
|||
.as_bytes(),
|
||||
)?;
|
||||
|
||||
self.set_token(user_id, device_id, token)?;
|
||||
self.set_token(user_id, &device_id, token)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes a device from a user.
|
||||
pub fn remove_device(&self, user_id: &UserId, device_id: &str) -> Result<()> {
|
||||
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
// Remove tokens
|
||||
if let Some(old_token) = self.userdeviceid_token.remove(&userdeviceid)? {
|
||||
|
@ -223,7 +223,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<String>> {
|
||||
pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<Box<DeviceId>>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
// All devices have metadata
|
||||
|
@ -237,17 +237,16 @@ impl Users {
|
|||
.next()
|
||||
.ok_or_else(|| Error::bad_database("UserDevice ID in db is invalid."))?,
|
||||
)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Device ID in userdeviceid_metadata is invalid.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("Device ID in userdeviceid_metadata is invalid."))?
|
||||
.into())
|
||||
})
|
||||
}
|
||||
|
||||
/// Replaces the access token of one device.
|
||||
fn set_token(&self, user_id: &UserId, device_id: &str, token: &str) -> Result<()> {
|
||||
fn set_token(&self, user_id: &UserId, device_id: &DeviceId, 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());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
// All devices have metadata
|
||||
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
|
||||
|
@ -268,13 +267,13 @@ impl Users {
|
|||
pub fn add_one_time_key(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
one_time_key_key: &AlgorithmAndDeviceId,
|
||||
one_time_key_value: &OneTimeKey,
|
||||
) -> Result<()> {
|
||||
let mut key = user_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(device_id.as_bytes());
|
||||
key.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
// All devices have metadata
|
||||
// Only existing devices should be able to call this.
|
||||
|
@ -301,12 +300,12 @@ impl Users {
|
|||
pub fn take_one_time_key(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
key_algorithm: &KeyAlgorithm,
|
||||
) -> Result<Option<(AlgorithmAndDeviceId, OneTimeKey)>> {
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(device_id.as_bytes());
|
||||
prefix.extend_from_slice(device_id.as_str().as_bytes());
|
||||
prefix.push(0xff);
|
||||
prefix.push(b'"'); // Annoying quotation mark
|
||||
prefix.extend_from_slice(key_algorithm.to_string().as_bytes());
|
||||
|
@ -337,11 +336,11 @@ impl Users {
|
|||
pub fn count_one_time_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
) -> Result<BTreeMap<KeyAlgorithm, UInt>> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
let mut counts = BTreeMap::new();
|
||||
|
||||
|
@ -370,13 +369,13 @@ impl Users {
|
|||
pub fn add_device_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
device_keys: &DeviceKeys,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
self.keyid_key.insert(
|
||||
&userdeviceid,
|
||||
|
@ -550,10 +549,14 @@ impl Users {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_device_keys(&self, user_id: &UserId, device_id: &str) -> Result<Option<DeviceKeys>> {
|
||||
pub fn get_device_keys(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
) -> Result<Option<DeviceKeys>> {
|
||||
let mut key = user_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(device_id.as_bytes());
|
||||
key.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
self.keyid_key.get(key)?.map_or(Ok(None), |bytes| {
|
||||
Ok(Some(serde_json::from_slice(&bytes).map_err(|_| {
|
||||
|
@ -633,14 +636,14 @@ impl Users {
|
|||
&self,
|
||||
sender: &UserId,
|
||||
target_user_id: &UserId,
|
||||
target_device_id: &str,
|
||||
target_device_id: &DeviceId,
|
||||
event_type: &EventType,
|
||||
content: serde_json::Value,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let mut key = target_user_id.to_string().as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(target_device_id.as_bytes());
|
||||
key.extend_from_slice(target_device_id.as_str().as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
|
||||
|
@ -660,14 +663,14 @@ impl Users {
|
|||
pub fn take_to_device_events(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
max: usize,
|
||||
) -> Result<Vec<EventJson<AnyToDeviceEvent>>> {
|
||||
let mut events = Vec::new();
|
||||
|
||||
let mut prefix = user_id.to_string().as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(device_id.as_bytes());
|
||||
prefix.extend_from_slice(device_id.as_str().as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
for result in self.todeviceid_events.scan_prefix(&prefix).take(max) {
|
||||
|
@ -685,12 +688,12 @@ impl Users {
|
|||
pub fn update_device_metadata(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &str,
|
||||
device_id: &DeviceId,
|
||||
device: &Device,
|
||||
) -> Result<()> {
|
||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||
userdeviceid.push(0xff);
|
||||
userdeviceid.extend_from_slice(device_id.as_bytes());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
// Only existing devices should be able to call this.
|
||||
assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some());
|
||||
|
@ -706,10 +709,14 @@ impl Users {
|
|||
}
|
||||
|
||||
/// Get device metadata.
|
||||
pub fn get_device_metadata(&self, user_id: &UserId, device_id: &str) -> Result<Option<Device>> {
|
||||
pub fn get_device_metadata(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
) -> 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());
|
||||
userdeviceid.extend_from_slice(device_id.as_str().as_bytes());
|
||||
|
||||
self.userdeviceid_metadata
|
||||
.get(&userdeviceid)?
|
||||
|
|
|
@ -2,47 +2,46 @@ use js_int::uint;
|
|||
use ruma::{
|
||||
identifiers::UserId,
|
||||
push::{
|
||||
Action, ConditionalPushRule, PatternedPushRule, PushCondition, RoomMemberCountIs, Ruleset,
|
||||
Tweak,
|
||||
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule,
|
||||
PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn default_pushrules(user_id: &UserId) -> Ruleset {
|
||||
Ruleset {
|
||||
content: vec![contains_user_name_rule(&user_id)],
|
||||
override_: vec![
|
||||
master_rule(),
|
||||
suppress_notices_rule(),
|
||||
invite_for_me_rule(),
|
||||
member_event_rule(),
|
||||
contains_display_name_rule(),
|
||||
tombstone_rule(),
|
||||
roomnotif_rule(),
|
||||
],
|
||||
room: vec![],
|
||||
sender: vec![],
|
||||
underride: vec![
|
||||
call_rule(),
|
||||
encrypted_room_one_to_one_rule(),
|
||||
room_one_to_one_rule(),
|
||||
message_rule(),
|
||||
encrypted_rule(),
|
||||
],
|
||||
}
|
||||
let mut rules = Ruleset::default();
|
||||
rules.content = vec![contains_user_name_rule(&user_id)];
|
||||
rules.override_ = vec![
|
||||
master_rule(),
|
||||
suppress_notices_rule(),
|
||||
invite_for_me_rule(),
|
||||
member_event_rule(),
|
||||
contains_display_name_rule(),
|
||||
tombstone_rule(),
|
||||
roomnotif_rule(),
|
||||
];
|
||||
rules.underride = vec![
|
||||
call_rule(),
|
||||
encrypted_room_one_to_one_rule(),
|
||||
room_one_to_one_rule(),
|
||||
message_rule(),
|
||||
encrypted_rule(),
|
||||
];
|
||||
rules
|
||||
}
|
||||
|
||||
pub fn master_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::DontNotify],
|
||||
default: true,
|
||||
enabled: false,
|
||||
rule_id: ".m.rule.master".to_owned(),
|
||||
conditions: vec![],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn suppress_notices_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::DontNotify],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -52,10 +51,11 @@ pub fn suppress_notices_rule() -> ConditionalPushRule {
|
|||
pattern: "m.notice".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn invite_for_me_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("default".to_owned())),
|
||||
|
@ -69,10 +69,11 @@ pub fn invite_for_me_rule() -> ConditionalPushRule {
|
|||
pattern: "m.invite".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn member_event_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::DontNotify],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -82,10 +83,11 @@ pub fn member_event_rule() -> ConditionalPushRule {
|
|||
pattern: "type".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn contains_display_name_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("default".to_owned())),
|
||||
|
@ -96,10 +98,11 @@ pub fn contains_display_name_rule() -> ConditionalPushRule {
|
|||
rule_id: ".m.rule.contains_display_name".to_owned(),
|
||||
conditions: vec![PushCondition::ContainsDisplayName],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn tombstone_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -115,10 +118,11 @@ pub fn tombstone_rule() -> ConditionalPushRule {
|
|||
},
|
||||
],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn roomnotif_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -133,10 +137,11 @@ pub fn roomnotif_rule() -> ConditionalPushRule {
|
|||
},
|
||||
],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn contains_user_name_rule(user_id: &UserId) -> PatternedPushRule {
|
||||
PatternedPushRule {
|
||||
PatternedPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("default".to_owned())),
|
||||
|
@ -147,10 +152,11 @@ pub fn contains_user_name_rule(user_id: &UserId) -> PatternedPushRule {
|
|||
rule_id: ".m.rule.contains_user_name".to_owned(),
|
||||
pattern: user_id.localpart().to_owned(),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn call_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("ring".to_owned())),
|
||||
|
@ -164,10 +170,11 @@ pub fn call_rule() -> ConditionalPushRule {
|
|||
pattern: "m.call.invite".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("default".to_owned())),
|
||||
|
@ -186,10 +193,11 @@ pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule {
|
|||
},
|
||||
],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn room_one_to_one_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![
|
||||
Action::Notify,
|
||||
Action::SetTweak(Tweak::Sound("default".to_owned())),
|
||||
|
@ -208,10 +216,11 @@ pub fn room_one_to_one_rule() -> ConditionalPushRule {
|
|||
},
|
||||
],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn message_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -221,10 +230,11 @@ pub fn message_rule() -> ConditionalPushRule {
|
|||
pattern: "m.room.message".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn encrypted_rule() -> ConditionalPushRule {
|
||||
ConditionalPushRule {
|
||||
ConditionalPushRuleInit {
|
||||
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))],
|
||||
default: true,
|
||||
enabled: true,
|
||||
|
@ -234,4 +244,5 @@ pub fn encrypted_rule() -> ConditionalPushRule {
|
|||
pattern: "m.room.encrypted".to_owned(),
|
||||
}],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@ use rocket::{
|
|||
Outcome::*,
|
||||
Request, State,
|
||||
};
|
||||
use ruma::{api::Endpoint, identifiers::UserId};
|
||||
use ruma::{
|
||||
api::Endpoint,
|
||||
identifiers::{DeviceId, UserId},
|
||||
};
|
||||
use std::{convert::TryInto, io::Cursor, ops::Deref};
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
|
@ -18,7 +21,7 @@ const MESSAGE_LIMIT: u64 = 20 * 1024 * 1024; // 20 MB
|
|||
pub struct Ruma<T> {
|
||||
pub body: T,
|
||||
pub user_id: Option<UserId>,
|
||||
pub device_id: Option<String>,
|
||||
pub device_id: Option<Box<DeviceId>>,
|
||||
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
||||
}
|
||||
|
||||
|
@ -63,7 +66,7 @@ impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma<T> {
|
|||
match db.users.find_from_token(&token).unwrap() {
|
||||
// TODO: M_UNKNOWN_TOKEN
|
||||
None => return Failure((Status::Unauthorized, ())),
|
||||
Some((user_id, device_id)) => (Some(user_id), Some(device_id)),
|
||||
Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())),
|
||||
}
|
||||
} else {
|
||||
(None, None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue