fix MSC4133 fields not being returned as original types

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2025-01-01 23:19:51 -05:00
parent b4ef646485
commit 72797532b6
2 changed files with 16 additions and 5 deletions

View file

@ -506,6 +506,10 @@ pub(crate) async fn get_profile_key_route(
return Err!(Request(NotFound("The requested profile key does not exist."))); return Err!(Request(NotFound("The requested profile key does not exist.")));
} }
if profile_key_value.is_empty() {
return Err!(Request(NotFound("The requested profile key does not exist.")));
}
return Ok(get_profile_key::unstable::Response { value: profile_key_value }); return Ok(get_profile_key::unstable::Response { value: profile_key_value });
} }
} }
@ -522,5 +526,9 @@ pub(crate) async fn get_profile_key_route(
return Err!(Request(NotFound("The requested profile key does not exist."))); return Err!(Request(NotFound("The requested profile key does not exist.")));
} }
if profile_key_value.is_empty() {
return Err!(Request(NotFound("The requested profile key does not exist.")));
}
Ok(get_profile_key::unstable::Response { value: profile_key_value }) Ok(get_profile_key::unstable::Response { value: profile_key_value })
} }

View file

@ -947,12 +947,13 @@ impl Service {
user_id: &UserId, user_id: &UserId,
profile_key: &str, profile_key: &str,
) -> Result<serde_json::Value> { ) -> Result<serde_json::Value> {
let key = (user_id, profile_key);
self.db self.db
.useridprofilekey_value .useridprofilekey_value
.qry(&key) .qry(&(user_id, profile_key))
.await .await
.deserialized() .deserialized::<Raw<serde_json::Value>>()
.map(serde_json::to_value)?
.map_err(Into::into)
} }
/// Gets all the user's profile keys and values in an iterator /// Gets all the user's profile keys and values in an iterator
@ -960,14 +961,16 @@ impl Service {
&'a self, &'a self,
user_id: &'a UserId, user_id: &'a UserId,
) -> impl Stream<Item = (String, serde_json::Value)> + 'a + Send { ) -> impl Stream<Item = (String, serde_json::Value)> + 'a + Send {
type KeyVal = ((Ignore, String), serde_json::Value); type KeyVal = ((Ignore, String), Raw<serde_json::Value>);
let prefix = (user_id, Interfix); let prefix = (user_id, Interfix);
self.db self.db
.useridprofilekey_value .useridprofilekey_value
.stream_prefix(&prefix) .stream_prefix(&prefix)
.ignore_err() .ignore_err()
.map(|((_, key), val): KeyVal| (key, val)) .ready_filter_map(|((_, key), val): KeyVal| {
Some((key, serde_json::to_value(val).ok()?))
})
} }
/// Sets a new profile key value, removes the key if value is None /// Sets a new profile key value, removes the key if value is None