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.
232.It Sy ":room user name show" 232.It Sy ":room user name show"
233Show the display name you currently have in this room. 233Show the display name you currently have in this room.
234.El 234.El
235
236.Sh "SPACE COMMANDS" 235.Sh "SPACE COMMANDS"
237.Bl -tag -width Ds 236.Bl -tag -width Ds
238.It Sy ":space child set [room_id] [arguments]" 237.It Sy ":space child set [room_id] [arguments]"
@@ -244,7 +243,27 @@ specifies a string by which children are lexicographically ordered.
244.It Sy ":space child remove" 243.It Sy ":space child remove"
245Remove the selected room from the currently focused space. 244Remove the selected room from the currently focused space.
246.El 245.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
248.Sh "WINDOW COMMANDS" 267.Sh "WINDOW COMMANDS"
249.Bl -tag -width Ds 268.Bl -tag -width Ds
250.It Sy ":horizontal [cmd]" 269.It Sy ":horizontal [cmd]"
src/base.rs +10
@@ -67,6 +67,7 @@ use matrix_sdk::{
67 tag::{TagName, Tags}, 67 tag::{TagName, Tags},
68 }, 68 },
69 presence::PresenceState, 69 presence::PresenceState,
70 profile::{ProfileFieldName, ProfileFieldValue},
70 }, 71 },
71}; 72};
72 73
@@ -547,6 +548,15 @@ pub enum HomeserverAction {
547 548
548 /// Forget all left rooms 549 /// Forget all left rooms
549 Forget, 550 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),
550} 560}
551 561
552/// An action performed against the user's room keys. 562/// An action performed against the user's room keys.
src/commands.rs +87
@@ -5,11 +5,13 @@
5use std::{convert::TryFrom, str::FromStr as _}; 5use std::{convert::TryFrom, str::FromStr as _};
6 6
7use matrix_sdk::ruma::{ 7use matrix_sdk::ruma::{
8 OwnedMxcUri,
8 OwnedRoomId, 9 OwnedRoomId,
9 OwnedRoomOrAliasId, 10 OwnedRoomOrAliasId,
10 OwnedUserId, 11 OwnedUserId,
11 RoomVersionId, 12 RoomVersionId,
12 events::tag::TagName, 13 events::tag::TagName,
14 profile::{ProfileFieldName, ProfileFieldValue},
13}; 15};
14 16
15use modalkit::{ 17use modalkit::{
@@ -449,6 +451,90 @@ fn iamb_mentions(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult
449 return Ok(step); 451 return Ok(step);
450} 452}
451 453
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
452fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { 538fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
453 if !desc.arg.text.is_empty() { 539 if !desc.arg.text.is_empty() {
454 return Result::Err(CommandError::InvalidArgument); 540 return Result::Err(CommandError::InvalidArgument);
@@ -982,6 +1068,7 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
982 aliases: vec![], 1068 aliases: vec![],
983 f: iamb_mentions, 1069 f: iamb_mentions,
984 }); 1070 });
1071 cmds.add_command(ProgramCommand { name: "self".into(), aliases: vec![], f: iamb_self });
985 cmds.add_command(ProgramCommand { 1072 cmds.add_command(ProgramCommand {
986 name: "unreact".into(), 1073 name: "unreact".into(),
987 aliases: vec![], 1074 aliases: vec![],
src/main.rs +51
@@ -30,6 +30,7 @@ use std::time::{Duration, Instant};
30use clap::{CommandFactory, Parser}; 30use clap::{CommandFactory, Parser};
31use matrix_sdk::ruma::OwnedUserId; 31use matrix_sdk::ruma::OwnedUserId;
32use matrix_sdk::ruma::api::error::ErrorKind; 32use matrix_sdk::ruma::api::error::ErrorKind;
33use matrix_sdk::ruma::profile::{ProfileFieldName, ProfileFieldValue};
33use matrix_sdk_crypto::encrypt_room_key_export; 34use matrix_sdk_crypto::encrypt_room_key_export;
34use modalkit::keybindings::InputBindings; 35use modalkit::keybindings::InputBindings;
35use rand::RngExt as _; 36use rand::RngExt as _;
@@ -682,6 +683,56 @@ impl Application {
682 } 683 }
683 Ok(vec![]) 684 Ok(vec![])
684 }, 685 },
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 },
685 } 736 }
686 } 737 }
687 738