fix: account data json
This commit is contained in:
parent
7fc71b3968
commit
6215218c3c
2 changed files with 27 additions and 16 deletions
|
@ -204,6 +204,8 @@ pub fn register_route(
|
|||
},
|
||||
},
|
||||
})
|
||||
.unwrap()
|
||||
.as_object_mut()
|
||||
.unwrap(),
|
||||
&db.globals,
|
||||
)
|
||||
|
@ -383,6 +385,8 @@ pub fn set_pushrule_route(
|
|||
},
|
||||
},
|
||||
})
|
||||
.unwrap()
|
||||
.as_object_mut()
|
||||
.unwrap(),
|
||||
&db.globals,
|
||||
)
|
||||
|
@ -443,7 +447,9 @@ pub fn set_global_account_data_route(
|
|||
None,
|
||||
user_id,
|
||||
&EventType::try_from(&body.event_type).unwrap(),
|
||||
serde_json::from_str(body.data.get()).unwrap(),
|
||||
json!({"content": serde_json::from_str::<serde_json::Value>(body.data.get()).unwrap()})
|
||||
.as_object_mut()
|
||||
.unwrap(),
|
||||
&db.globals,
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -465,7 +471,11 @@ pub fn get_global_account_data_route(
|
|||
|
||||
if let Some(data) = db
|
||||
.account_data
|
||||
.get(None, user_id, &EventType::try_from(&body.event_type).unwrap())
|
||||
.get(
|
||||
None,
|
||||
user_id,
|
||||
&EventType::try_from(&body.event_type).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
{
|
||||
MatrixResult(Ok(get_global_account_data::Response { account_data: data }))
|
||||
|
@ -792,6 +802,8 @@ pub fn set_read_marker_route(
|
|||
},
|
||||
room_id: Some(body.room_id.clone()),
|
||||
})
|
||||
.unwrap()
|
||||
.as_object_mut()
|
||||
.unwrap(),
|
||||
&db.globals,
|
||||
)
|
||||
|
@ -1317,7 +1329,7 @@ pub fn sync_route(
|
|||
db: State<'_, Database>,
|
||||
body: Ruma<sync_events::Request>,
|
||||
) -> MatrixResult<sync_events::Response> {
|
||||
std::thread::sleep(Duration::from_millis(1500));
|
||||
std::thread::sleep(Duration::from_millis(1000));
|
||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -1526,7 +1538,7 @@ pub fn sync_route(
|
|||
let timestamp = edu.content.last_active_ago.unwrap();
|
||||
edu.content.last_active_ago = Some(
|
||||
js_int::UInt::try_from(utils::millis_since_unix_epoch()).unwrap()
|
||||
- timestamp
|
||||
- timestamp,
|
||||
);
|
||||
Some(edu.into())
|
||||
} else {
|
||||
|
|
|
@ -14,9 +14,14 @@ impl AccountData {
|
|||
room_id: Option<&RoomId>,
|
||||
user_id: &UserId,
|
||||
kind: &EventType,
|
||||
data: serde_json::Value,
|
||||
json: &mut serde_json::Map<String, serde_json::Value>,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
if json.get("content").is_none() {
|
||||
return Err(Error::BadRequest("json needs to have a content field"));
|
||||
}
|
||||
json.insert("type".to_owned(), kind.to_string().into());
|
||||
|
||||
let mut prefix = room_id
|
||||
.map(|r| r.to_string())
|
||||
.unwrap_or_default()
|
||||
|
@ -43,7 +48,6 @@ impl AccountData {
|
|||
{
|
||||
// This is the old room_latest
|
||||
self.roomuserdataid_accountdata.remove(old)?;
|
||||
println!("removed old account data");
|
||||
}
|
||||
|
||||
let mut key = prefix;
|
||||
|
@ -52,7 +56,7 @@ impl AccountData {
|
|||
key.extend_from_slice(kind.to_string().as_bytes());
|
||||
|
||||
self.roomuserdataid_accountdata
|
||||
.insert(key, &*data.to_string())
|
||||
.insert(key, &*serde_json::to_string(&json)?)
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
|
@ -104,18 +108,13 @@ impl AccountData {
|
|||
.ok_or(Error::BadDatabase("roomuserdataid is invalid"))?,
|
||||
)?)
|
||||
.map_err(|_| Error::BadDatabase("roomuserdataid is invalid"))?,
|
||||
serde_json::from_slice::<serde_json::Value>(&v).unwrap(),
|
||||
serde_json::from_slice::<EventJson<EduEvent>>(&v).unwrap(),
|
||||
))
|
||||
})
|
||||
{
|
||||
let (kind, content) = r.unwrap();
|
||||
let mut json = serde_json::Map::new();
|
||||
json.insert("content".to_owned(), content);
|
||||
json.insert("type".to_owned(), kind.to_string().into());
|
||||
userdata.insert(
|
||||
kind,
|
||||
serde_json::from_value::<EventJson<EduEvent>>(json.into())?,
|
||||
);
|
||||
let (kind, data) = r.unwrap();
|
||||
&data.deserialize();
|
||||
userdata.insert(kind, data);
|
||||
}
|
||||
|
||||
Ok(userdata)
|
||||
|
|
Loading…
Add table
Reference in a new issue