|
|
@ -602,15 +602,17 @@ pub fn get_global_account_data_route(
|
|
|
|
)?
|
|
|
|
)?
|
|
|
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
|
|
|
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO clearly this is not ideal...
|
|
|
|
let data: Result<EduEvent, Error> = data
|
|
|
|
// NOTE: EventJson is no longer needed as all the enums and event structs impl ser/de
|
|
|
|
.deserialize()
|
|
|
|
let data: Result<EduEvent, Error> = data.deserialize().map_err(Into::into);
|
|
|
|
.map_err(|_| Error::bad_database("Deserialization of account data failed"));
|
|
|
|
match data? {
|
|
|
|
|
|
|
|
EduEvent::Basic(data) => Ok(get_global_account_data::Response {
|
|
|
|
if let EduEvent::Basic(data) = data? {
|
|
|
|
|
|
|
|
Ok(get_global_account_data::Response {
|
|
|
|
account_data: EventJson::from(data),
|
|
|
|
account_data: EventJson::from(data),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.into()),
|
|
|
|
.into())
|
|
|
|
_ => panic!("timo what do i do here"),
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(Error::bad_database("Encountered a non account data event."))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -2523,7 +2525,6 @@ pub fn sync_route(
|
|
|
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
|
|
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
|
|
|
.filter_map(|r| {
|
|
|
|
.filter_map(|r| {
|
|
|
|
if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() {
|
|
|
|
if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() {
|
|
|
|
// TODO we could get rid of EventJson?
|
|
|
|
|
|
|
|
Some(EventJson::from(ev))
|
|
|
|
Some(EventJson::from(ev))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
@ -2554,8 +2555,8 @@ 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()
|
|
|
|
.flat_map(|(_, v)| {
|
|
|
|
.filter_map(|(_, v)| {
|
|
|
|
if let Some(EduEvent::Basic(account_event)) = v.deserialize().ok() {
|
|
|
|
if let Ok(EduEvent::Basic(account_event)) = v.deserialize() {
|
|
|
|
Some(EventJson::from(account_event))
|
|
|
|
Some(EventJson::from(account_event))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
@ -2618,7 +2619,6 @@ pub fn sync_route(
|
|
|
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
|
|
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
|
|
|
.filter_map(|r| {
|
|
|
|
.filter_map(|r| {
|
|
|
|
if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() {
|
|
|
|
if let Ok(EduEvent::Ephemeral(ev)) = r.deserialize() {
|
|
|
|
// TODO we could get rid of EventJson?
|
|
|
|
|
|
|
|
Some(EventJson::from(ev))
|
|
|
|
Some(EventJson::from(ev))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
@ -2710,8 +2710,8 @@ pub fn sync_route(
|
|
|
|
.account_data
|
|
|
|
.account_data
|
|
|
|
.changes_since(None, &user_id, since)?
|
|
|
|
.changes_since(None, &user_id, since)?
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.flat_map(|(_, v)| {
|
|
|
|
.filter_map(|(_, v)| {
|
|
|
|
if let Some(EduEvent::Basic(account_event)) = v.deserialize().ok() {
|
|
|
|
if let Ok(EduEvent::Basic(account_event)) = v.deserialize() {
|
|
|
|
Some(EventJson::from(account_event))
|
|
|
|
Some(EventJson::from(account_event))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
None
|
|
|
@ -2859,13 +2859,12 @@ pub fn get_message_events_route(
|
|
|
|
.clone()
|
|
|
|
.clone()
|
|
|
|
.parse()
|
|
|
|
.parse()
|
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from` value."))?;
|
|
|
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from` value."))?;
|
|
|
|
|
|
|
|
let limit = body
|
|
|
|
|
|
|
|
.limit
|
|
|
|
|
|
|
|
.try_into()
|
|
|
|
|
|
|
|
.map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?;
|
|
|
|
match body.dir {
|
|
|
|
match body.dir {
|
|
|
|
get_message_events::Direction::Forward => {
|
|
|
|
get_message_events::Direction::Forward => {
|
|
|
|
let limit = body
|
|
|
|
|
|
|
|
.limit
|
|
|
|
|
|
|
|
.try_into()
|
|
|
|
|
|
|
|
.map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let events_after = db
|
|
|
|
let events_after = db
|
|
|
|
.rooms
|
|
|
|
.rooms
|
|
|
|
.pdus_after(&user_id, &body.room_id, from)
|
|
|
|
.pdus_after(&user_id, &body.room_id, from)
|
|
|
@ -2897,11 +2896,6 @@ pub fn get_message_events_route(
|
|
|
|
.into())
|
|
|
|
.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
get_message_events::Direction::Backward => {
|
|
|
|
get_message_events::Direction::Backward => {
|
|
|
|
let limit = body
|
|
|
|
|
|
|
|
.limit
|
|
|
|
|
|
|
|
.try_into()
|
|
|
|
|
|
|
|
.map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let events_before = db
|
|
|
|
let events_before = db
|
|
|
|
.rooms
|
|
|
|
.rooms
|
|
|
|
.pdus_until(&user_id, &body.room_id, from)
|
|
|
|
.pdus_until(&user_id, &body.room_id, from)
|
|
|
|