|
|
|
@ -594,27 +594,18 @@ pub fn get_global_account_data_route( |
|
|
|
) -> ConduitResult<get_global_account_data::Response> { |
|
|
|
) -> ConduitResult<get_global_account_data::Response> { |
|
|
|
let user_id = body.user_id.as_ref().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.as_ref().expect("user is authenticated"); |
|
|
|
|
|
|
|
|
|
|
|
let data = db |
|
|
|
db.account_data |
|
|
|
.account_data |
|
|
|
|
|
|
|
.get( |
|
|
|
.get( |
|
|
|
None, |
|
|
|
None, |
|
|
|
user_id, |
|
|
|
user_id, |
|
|
|
&EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"), |
|
|
|
&EventType::try_from(&body.event_type).expect("EventType::try_from can never fail"), |
|
|
|
)? |
|
|
|
)? |
|
|
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; |
|
|
|
.and_then(|ev| { |
|
|
|
|
|
|
|
serde_json::from_str(ev.json().get()) |
|
|
|
let data: AnyEvent = data |
|
|
|
.map(|data| get_global_account_data::Response { account_data: data }.into()) |
|
|
|
.deserialize() |
|
|
|
.ok() |
|
|
|
.map_err(|_| Error::bad_database("Deserialization of account data failed"))?; |
|
|
|
}) |
|
|
|
|
|
|
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found.")) |
|
|
|
if let AnyEvent::Basic(data) = data { |
|
|
|
|
|
|
|
Ok(get_global_account_data::Response { |
|
|
|
|
|
|
|
account_data: data.into(), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.into()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Err(Error::bad_database("Encountered a non account data event.")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")] |
|
|
|
#[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")] |
|
|
|
@ -2546,14 +2537,12 @@ pub fn sync_route( |
|
|
|
.account_data |
|
|
|
.account_data |
|
|
|
.changes_since(Some(&room_id), &user_id, since)? |
|
|
|
.changes_since(Some(&room_id), &user_id, since)? |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|(_, v)| { |
|
|
|
.filter_map(|(_, v)| { |
|
|
|
if let Ok(AnyEvent::Basic(account_event)) = v.deserialize() { |
|
|
|
serde_json::from_str(v.json().get()) |
|
|
|
Ok(EventJson::from(account_event)) |
|
|
|
.map_err(|_| Error::bad_database("Invalid account event in database.")) |
|
|
|
} else { |
|
|
|
.ok() |
|
|
|
Err(Error::bad_database("found invalid event")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.collect::<Result<Vec<_>, _>>()?, |
|
|
|
.collect::<Vec<_>>(), |
|
|
|
}, |
|
|
|
}, |
|
|
|
summary: sync_events::RoomSummary { |
|
|
|
summary: sync_events::RoomSummary { |
|
|
|
heroes, |
|
|
|
heroes, |
|
|
|
@ -2690,14 +2679,12 @@ pub fn sync_route( |
|
|
|
.account_data |
|
|
|
.account_data |
|
|
|
.changes_since(None, &user_id, since)? |
|
|
|
.changes_since(None, &user_id, since)? |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|(_, v)| { |
|
|
|
.filter_map(|(_, v)| { |
|
|
|
if let Ok(AnyEvent::Basic(account_event)) = v.deserialize() { |
|
|
|
serde_json::from_str(v.json().get()) |
|
|
|
Ok(EventJson::from(account_event)) |
|
|
|
.map_err(|_| Error::bad_database("Invalid account event in database.")) |
|
|
|
} else { |
|
|
|
.ok() |
|
|
|
Err(Error::bad_database("found invalid event")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.collect::<Result<Vec<_>, _>>()?, |
|
|
|
.collect::<Vec<_>>(), |
|
|
|
}, |
|
|
|
}, |
|
|
|
device_lists: sync_events::DeviceLists { |
|
|
|
device_lists: sync_events::DeviceLists { |
|
|
|
changed: if since != 0 { |
|
|
|
changed: if since != 0 { |
|
|
|
|