feat: Add support for importing profile data from claims

This commit is contained in:
Ginger committed 2026-07-02 16:34:38 -04:00
1 parent 53d6887b86
commit 06afe4f1a3
9 files changed
+339 -63

No files matched your search

+17 -4
View File
@@ -1,4 +1,4 @@
use std::collections::BTreeMap;
use std::{borrow::Cow, collections::BTreeMap};
use conduwuit::{
Err, Result,
@@ -29,9 +29,9 @@ impl ProfileFieldChange {
}
}
fn value(&self) -> Option<Value> {
fn value(&self) -> Option<Cow<'_, Value>> {
if let Self::Set(value) = self {
Some(value.value().into_owned())
Some(value.value())
} else {
None
}
@@ -92,6 +92,15 @@ impl super::Service {
}
}
// Check if this change would be a no-op
if self
.get_local_profile_field(user_id, field_name.clone())
.await
.is_some_and(|value| Some(value.value()) == change.value())
{
return Ok(());
}
// If the user is local and changed their displayname or avatar_url, update it
// in all their joined rooms. This is done before updating their profile data
// so we can check the old value of the field if `propagate_to` is `unchanged`.
@@ -192,7 +201,11 @@ impl super::Service {
| ProfileFieldChange::Delete(ProfileFieldName::AvatarUrl) => {
self.set_avatar_url(user_id, None);
},
| other => self.set_profile_key(user_id, other.field_name().as_str(), other.value()),
| other => self.set_profile_key(
user_id,
other.field_name().as_str(),
other.value().map(Cow::into_owned),
),
}
Ok(())