From eb4af8576544a54bb113006921439bb26045fc23 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 19 May 2020 22:56:28 +0200 Subject: [PATCH] fix: riot sometimes freaks out when refreshing --- src/database/account_data.rs | 13 +++++++++---- src/ruma_wrapper.rs | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/database/account_data.rs b/src/database/account_data.rs index e09ef2c..d1114ec 100644 --- a/src/database/account_data.rs +++ b/src/database/account_data.rs @@ -22,13 +22,16 @@ impl AccountData { } 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 .map(|r| r.to_string()) .unwrap_or_default() .as_bytes() .to_vec(); 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); // Remove old entry @@ -40,10 +43,12 @@ impl AccountData { .filter_map(|r| r.ok()) .take_while(|key| key.starts_with(&prefix)) .find(|key| { - key.split(|&b| b == 0xff) - .nth(1) - .filter(|&user| user == user_id.to_string().as_bytes()) + let user = key.split(|&b| b == 0xff).nth(1); + let k = key.rsplit(|&b| b == 0xff).next(); + + user.filter(|&user| user == user_id_string.as_bytes()) .is_some() + && k.filter(|&k| k == kind_string.as_bytes()).is_some() }) { // This is the old room_latest diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index d6f6cfe..28e6fbb 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -135,9 +135,6 @@ where match http_response { Ok(http_response) => { let mut response = rocket::response::Response::build(); - response - .sized_body(Cursor::new(http_response.body().clone())) - .await; let status = http_response.status(); response.raw_status(status.into(), ""); @@ -147,6 +144,10 @@ where .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-Methods",