Commit 3d8e122247

3d8e1222476713e7dc17d8aa26d070f2dbd8f357

parent: 661dff6adb

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-01 12:39 UTC
committer: <noreply@github.com>

Add support for updating user profile information (#662)

Layout: unified · split

docs/iamb.1 +21 −2
@@ -232,7 +232,6 @@ Delete your per-room user display name.
232232.It Sy ":room user name show"
233233Show the display name you currently have in this room.
234234.El
235
236235.Sh "SPACE COMMANDS"
237236.Bl -tag -width Ds
238237.It Sy ":space child set [room_id] [arguments]"
@@ -244,7 +243,27 @@ specifies a string by which children are lexicographically ordered.
244243.It Sy ":space child remove"
245244Remove the selected room from the currently focused space.
246245.El
247
246.Sh "PROFILE COMMANDS"
247.Bl -tag -width Ds
248.It Sy ":self avatar set [mxc://...]"
249Set the avatar URL for your profile.
250.It Sy ":self avatar unset"
251Unset the avatar for your profile.
252.It Sy ":self avatar show"
253Show the current avatar URL for your profile.
254.It Sy ":self name set [nickname]"
255Set the display name for your profile.
256.It Sy ":self name unset"
257Unset the display name for your profile.
258.It Sy ":self name show"
259Show the current display name for your profile.
260.It Sy ":self timezone set [tz]"
261Set the timezone for your profile.
262.It Sy ":self timezone unset"
263Unset the timezone for your profile.
264.It Sy ":self timezone show"
265Show the current timezone for your profile.
266.El
248267.Sh "WINDOW COMMANDS"
249268.Bl -tag -width Ds
250269.It Sy ":horizontal [cmd]"
src/base.rs +10
@@ -67,6 +67,7 @@ use matrix_sdk::{
6767 tag::{TagName, Tags},
6868 },
6969 presence::PresenceState,
70 profile::{ProfileFieldName, ProfileFieldValue},
7071 },
7172};
7273
@@ -547,6 +548,15 @@ pub enum HomeserverAction {
547548
548549 /// Forget all left rooms
549550 Forget,
551
552 /// Set a profile field.
553 ProfileFieldSet(ProfileFieldValue),
554
555 /// Set a profile field.
556 ProfileFieldUnset(ProfileFieldName),
557
558 /// Set a profile field.
559 ProfileFieldShow(ProfileFieldName),
550560}
551561
552562/// An action performed against the user's room keys.
src/commands.rs +87
@@ -5,11 +5,13 @@
55use std::{convert::TryFrom, str::FromStr as _};
66
77use matrix_sdk::ruma::{
8 OwnedMxcUri,
89 OwnedRoomId,
910 OwnedRoomOrAliasId,
1011 OwnedUserId,
1112 RoomVersionId,
1213 events::tag::TagName,
14 profile::{ProfileFieldName, ProfileFieldValue},
1315};
1416
1517use modalkit::{
@@ -449,6 +451,90 @@ fn iamb_mentions(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult
449451 return Ok(step);
450452}
451453
454fn iamb_self(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
455 let mut iter = desc.arg.strings()?.into_iter();
456 let field = iter.next().ok_or(CommandError::InvalidArgument)?;
457 let action = iter.next().ok_or(CommandError::InvalidArgument)?;
458 let arg = iter.next();
459 let trailing = iter.collect::<Vec<_>>();
460
461 if !trailing.is_empty() {
462 // Reject if we have any trailing arguments:
463 return Result::Err(CommandError::InvalidArgument);
464 }
465
466 let act: IambAction = match (field.as_str(), action.as_str(), arg) {
467 // :self avatar show
468 ("avatar", "show", None) => {
469 HomeserverAction::ProfileFieldShow(ProfileFieldName::AvatarUrl).into()
470 },
471 ("avatar", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
472
473 // :self avatar set
474 ("avatar", "set", Some(s)) => {
475 let url = OwnedMxcUri::from(s.as_str());
476 if let Err(e) = url.validate() {
477 return Err(CommandError::Error(format!(
478 "{s:?} is not a valid Matrix content URI: {e}"
479 )));
480 }
481 HomeserverAction::ProfileFieldSet(ProfileFieldValue::AvatarUrl(url)).into()
482 },
483 ("avatar", "set", None) => return Result::Err(CommandError::InvalidArgument),
484
485 // :self avatar unset
486 ("avatar", "unset", None) => {
487 HomeserverAction::ProfileFieldUnset(ProfileFieldName::AvatarUrl).into()
488 },
489 ("avatar", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument),
490
491 // :self name show
492 ("name" | "nick", "show", None) => {
493 HomeserverAction::ProfileFieldShow(ProfileFieldName::DisplayName).into()
494 },
495 ("name" | "nick", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
496
497 // :self name set
498 ("name" | "nick", "set", Some(s)) => {
499 HomeserverAction::ProfileFieldSet(ProfileFieldValue::DisplayName(s)).into()
500 },
501 ("name" | "nick", "set", None) => return Result::Err(CommandError::InvalidArgument),
502
503 // :self name unset
504 ("name" | "nick", "unset", None) => {
505 HomeserverAction::ProfileFieldUnset(ProfileFieldName::DisplayName).into()
506 },
507 ("name" | "nick", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument),
508
509 // :self timezone show
510 ("timezone" | "tz", "show", None) => {
511 HomeserverAction::ProfileFieldShow(ProfileFieldName::TimeZone).into()
512 },
513 ("timezone" | "tz", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
514
515 // :self timezone set
516 ("timezone" | "tz", "set", Some(s)) => {
517 HomeserverAction::ProfileFieldSet(ProfileFieldValue::TimeZone(s)).into()
518 },
519 ("timezone" | "tz", "set", None) => return Result::Err(CommandError::InvalidArgument),
520
521 // :self timezone set
522 ("timezone" | "tz", "unset", None) => {
523 HomeserverAction::ProfileFieldUnset(ProfileFieldName::TimeZone).into()
524 },
525 ("timezone" | "tz", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument),
526
527 // Reject anything we don't recognize:
528 (f, a, _) => {
529 return Result::Err(CommandError::Error(format!("unrecognized command: {f} {a}")));
530 },
531 };
532
533 let step = CommandStep::Continue(act.into(), ctx.context.clone());
534
535 return Ok(step);
536}
537
452538fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
453539 if !desc.arg.text.is_empty() {
454540 return Result::Err(CommandError::InvalidArgument);
@@ -982,6 +1068,7 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
9821068 aliases: vec![],
9831069 f: iamb_mentions,
9841070 });
1071 cmds.add_command(ProgramCommand { name: "self".into(), aliases: vec![], f: iamb_self });
9851072 cmds.add_command(ProgramCommand {
9861073 name: "unreact".into(),
9871074 aliases: vec![],
src/main.rs +51
@@ -30,6 +30,7 @@ use std::time::{Duration, Instant};
3030use clap::{CommandFactory, Parser};
3131use matrix_sdk::ruma::OwnedUserId;
3232use matrix_sdk::ruma::api::error::ErrorKind;
33use matrix_sdk::ruma::profile::{ProfileFieldName, ProfileFieldValue};
3334use matrix_sdk_crypto::encrypt_room_key_export;
3435use modalkit::keybindings::InputBindings;
3536use rand::RngExt as _;
@@ -682,6 +683,56 @@ impl Application {
682683 }
683684 Ok(vec![])
684685 },
686 HomeserverAction::ProfileFieldSet(value) => {
687 let client = &store.application.worker.client;
688 let account = client.account();
689 account.set_profile_field(value).await.map_err(IambError::from)?;
690 Ok(vec![])
691 },
692 HomeserverAction::ProfileFieldUnset(field) => {
693 let client = &store.application.worker.client;
694 let account = client.account();
695 account.delete_profile_field(field).await.map_err(IambError::from)?;
696 Ok(vec![])
697 },
698 HomeserverAction::ProfileFieldShow(field) => {
699 let client = &store.application.worker.client;
700 let user_id = store.application.settings.profile.user_id.clone();
701 let account = client.account();
702 let value = account
703 .fetch_profile_field_of(user_id, field.clone())
704 .await
705 .map_err(IambError::from)?;
706
707 let msg = match (field, value) {
708 (_, Some(ProfileFieldValue::DisplayName(s))) => {
709 format!("Your profile's display name is set to: {s}")
710 },
711 (_, Some(ProfileFieldValue::TimeZone(s))) => {
712 format!("Your profile's timezone is set to: {s}")
713 },
714 (_, Some(ProfileFieldValue::AvatarUrl(s))) => {
715 format!("Your profile's avatar URL is set to: {s}")
716 },
717 (ProfileFieldName::DisplayName, None) => {
718 "Your profile's display name is currently unset".into()
719 },
720 (ProfileFieldName::TimeZone, None) => {
721 "Your profile's timezone is currently unset".into()
722 },
723 (ProfileFieldName::AvatarUrl, None) => {
724 "Your profile's avatar URL is currently unset".into()
725 },
726 (f, None) => {
727 format!("Your profile's {f:?} is currently unset")
728 },
729 (f, Some(s)) => {
730 format!("Your profile's {f:?} is set to {s:?}")
731 },
732 };
733
734 Ok(vec![(Action::ShowInfoMessage(msg.into()), ctx)])
735 },
685736 }
686737 }
687738