Fix custom profile field values being double-serialized with escapes.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -292,7 +292,7 @@ pub(crate) async fn get_profile_route(
|
||||
return Err!(Request(NotFound("Profile was not found.")));
|
||||
}
|
||||
|
||||
let mut custom_profile_fields: BTreeMap<String, serde_json::Value> = services
|
||||
let mut custom_profile_fields: BTreeMap<String, _> = services
|
||||
.users
|
||||
.all_profile_keys(&body.user_id)
|
||||
.collect()
|
||||
@@ -317,11 +317,24 @@ pub(crate) async fn get_profile_route(
|
||||
("m.tz", tz),
|
||||
];
|
||||
|
||||
let response = canonical_fields
|
||||
Ok(canonical_fields
|
||||
.into_iter()
|
||||
.filter_map(|(key, val)| val.map(|val| (key, val)))
|
||||
.map(|(key, val)| (key.to_owned(), val.into()))
|
||||
.chain(custom_profile_fields.into_iter());
|
||||
|
||||
Ok(response.collect::<get_profile::v3::Response>())
|
||||
.map(|(key, val)| (key.to_owned(), val))
|
||||
.filter_map(|(key, val)| {
|
||||
val.map(serde_json::to_value)
|
||||
.transpose()
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|val| (key, val))
|
||||
})
|
||||
.chain(
|
||||
custom_profile_fields
|
||||
.into_iter()
|
||||
.filter_map(|(key, val)| {
|
||||
serde_json::to_value(val.json())
|
||||
.map(|val| (key, val))
|
||||
.ok()
|
||||
}),
|
||||
)
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -366,6 +366,7 @@ pub(crate) async fn get_profile_field_route(
|
||||
.users
|
||||
.profile_key(&body.user_id, body.field.as_str())
|
||||
.await
|
||||
.and_then(|val| serde_json::to_value(val.json()).map_err(Into::into))
|
||||
.map_err(|_| err!(Request(NotFound("The requested profile key does not exist."))))?;
|
||||
|
||||
let profile_key_value = ProfileFieldValue::new(body.field.as_str(), value)?;
|
||||
|
||||
@@ -98,7 +98,11 @@ pub(crate) async fn get_profile_information_route(
|
||||
.await
|
||||
{
|
||||
Ok(Response {
|
||||
custom_profile_fields: [(custom_field.to_string(), value)].into(),
|
||||
custom_profile_fields: [(
|
||||
custom_field.to_string(),
|
||||
serde_json::to_value(value.json())?,
|
||||
)]
|
||||
.into(),
|
||||
..Response::default()
|
||||
})
|
||||
} else {
|
||||
@@ -117,11 +121,17 @@ pub(crate) async fn get_profile_information_route(
|
||||
let custom_profile_fields = services
|
||||
.users
|
||||
.all_profile_keys(&body.user_id)
|
||||
.collect();
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let (avatar_url, blurhash, custom_profile_fields, displayname, tz) =
|
||||
join5(avatar_url, blurhash, custom_profile_fields, displayname, tz).await;
|
||||
|
||||
let custom_profile_fields = custom_profile_fields
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, serde_json::to_value(v)))
|
||||
.filter_map(|(k, v)| v.ok().map(|v| (k, v)))
|
||||
.collect();
|
||||
|
||||
Ok(Response {
|
||||
avatar_url,
|
||||
blurhash,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future::join3};
|
||||
use ruma::{
|
||||
MxcUri, OwnedMxcUri, OwnedRoomId, UserId,
|
||||
api::client::profile::ProfileFieldValue,
|
||||
events::room::member::{MembershipState, RoomMemberEventContent},
|
||||
serde::Raw,
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Result, implement,
|
||||
@@ -216,8 +218,8 @@ pub async fn timezone(&self, user_id: &UserId) -> Result<String> {
|
||||
pub fn all_profile_keys<'a>(
|
||||
&'a self,
|
||||
user_id: &'a UserId,
|
||||
) -> impl Stream<Item = (String, serde_json::Value)> + 'a + Send {
|
||||
type KeyVal = ((Ignore, String), serde_json::Value);
|
||||
) -> impl Stream<Item = (String, Raw<ProfileFieldValue>)> + 'a + Send {
|
||||
type KeyVal = ((Ignore, String), Raw<ProfileFieldValue>);
|
||||
|
||||
let prefix = (user_id, Interfix);
|
||||
self.db
|
||||
@@ -253,7 +255,7 @@ pub async fn profile_key(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
profile_key: &str,
|
||||
) -> Result<serde_json::Value> {
|
||||
) -> Result<Raw<ProfileFieldValue>> {
|
||||
let key = (user_id, profile_key);
|
||||
self.db
|
||||
.useridprofilekey_value
|
||||
|
||||
Reference in New Issue
Block a user