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