fix: riot sometimes freaks out when refreshing

This commit is contained in:
timokoesters 2020-05-19 22:56:28 +02:00
parent d544d28b6e
commit eb4af85765
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
2 changed files with 13 additions and 7 deletions

View file

@ -22,13 +22,16 @@ impl AccountData {
} }
json.insert("type".to_owned(), kind.to_string().into()); json.insert("type".to_owned(), kind.to_string().into());
let user_id_string = user_id.to_string();
let kind_string = kind.to_string();
let mut prefix = room_id let mut prefix = room_id
.map(|r| r.to_string()) .map(|r| r.to_string())
.unwrap_or_default() .unwrap_or_default()
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(&user_id.to_string().as_bytes()); prefix.extend_from_slice(&user_id_string.as_bytes());
prefix.push(0xff); prefix.push(0xff);
// Remove old entry // Remove old entry
@ -40,10 +43,12 @@ impl AccountData {
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.take_while(|key| key.starts_with(&prefix)) .take_while(|key| key.starts_with(&prefix))
.find(|key| { .find(|key| {
key.split(|&b| b == 0xff) let user = key.split(|&b| b == 0xff).nth(1);
.nth(1) let k = key.rsplit(|&b| b == 0xff).next();
.filter(|&user| user == user_id.to_string().as_bytes())
user.filter(|&user| user == user_id_string.as_bytes())
.is_some() .is_some()
&& k.filter(|&k| k == kind_string.as_bytes()).is_some()
}) })
{ {
// This is the old room_latest // This is the old room_latest

View file

@ -135,9 +135,6 @@ where
match http_response { match http_response {
Ok(http_response) => { Ok(http_response) => {
let mut response = rocket::response::Response::build(); let mut response = rocket::response::Response::build();
response
.sized_body(Cursor::new(http_response.body().clone()))
.await;
let status = http_response.status(); let status = http_response.status();
response.raw_status(status.into(), ""); response.raw_status(status.into(), "");
@ -147,6 +144,10 @@ where
.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned()); .raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
} }
response
.sized_body(Cursor::new(http_response.into_body()))
.await;
response.raw_header("Access-Control-Allow-Origin", "*"); response.raw_header("Access-Control-Allow-Origin", "*");
response.raw_header( response.raw_header(
"Access-Control-Allow-Methods", "Access-Control-Allow-Methods",