Commit 65399063e5

65399063e515fc486ffc2680946d28b61cf4cd1e

parent: 559683f9d3

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-08-30 03:25 UTC
committer: <noreply@github.com>

Support upgrading rooms and following tombstone information (#656)

Layout: unified · split

docs/iamb.1 +9 −1
@@ -72,7 +72,6 @@ View the startup Welcome window.
7272.It Sy ":forget"
7373Remove all left rooms from the internal database.
7474.El
75
7675.Sh "E2EE COMMANDS"
7776.Bl -tag -width Ds
7877.It Sy ":keys export [path] [passphrase]"
@@ -133,6 +132,10 @@ Create a new room. Arguments can be
133132.Dq ++space ,
134133and
135134.Dq ++encrypted .
135.It Sy ":follow next"
136Follow the tombstone information to the upgraded room.
137.It Sy ":follow previous"
138Follow the room creation information to the pre-upgraded room.
136139.It Sy ":invite accept"
137140Accept an invitation to the currently focused room.
138141.It Sy ":invite reject"
@@ -160,6 +163,11 @@ Mark the currently focused room as read.
160163.It Sy ":room unread clear"
161164Alias for
162165.Sy :room unread unset .
166.It Sy ":room version show"
167Show the Matrix version for this room.
168.It Sy ":room version upgrade [version] [additional creators...]"
169Upgrade the Matrix version for this room to the specified version.
170Note that room upgrading in Matrix works by creating a new room that everyone else will then need to join.
163171.It Sy ":room notify set [level]"
164172Set a notification level for the currently focused room.
165173Valid levels are
src/base.rs +11 −2
@@ -14,10 +14,10 @@ use std::time::{Duration, Instant};
1414use emojis::Emoji;
1515
1616use matrix_sdk::ruma::OwnedMxcUri;
17use matrix_sdk::ruma::OwnedTransactionId;
1817use matrix_sdk::ruma::events::receipt::ReceiptThread;
1918use matrix_sdk::ruma::events::room::MediaSource;
2019use matrix_sdk::ruma::events::sticker::StickerEvent;
20use matrix_sdk::ruma::{OwnedTransactionId, RoomVersionId};
2121use ratatui::{
2222 buffer::Buffer,
2323 layout::{Alignment, Rect},
@@ -91,7 +91,7 @@ use modalkit::{
9191 errors::{UIError, UIResult},
9292 key::TerminalKey,
9393 keybindings::SequenceStatus,
94 prelude::{CommandType, WordStyle},
94 prelude::{CommandType, MoveDir1D, WordStyle},
9595};
9696
9797use crate::config::ImagePreviewSize;
@@ -407,6 +407,9 @@ pub enum RoomField {
407407 /// The room name.
408408 Name,
409409
410 /// The room version.
411 Version,
412
410413 /// The room id.
411414 Id,
412415
@@ -450,6 +453,9 @@ impl Display for MemberUpdateAction {
450453/// An action that operates on a focused room.
451454#[derive(Clone, Debug, Eq, PartialEq)]
452455pub enum RoomAction {
456 /// Follow the room upgrade information.
457 Follow(Box<CommandContext>, MoveDir1D),
458
453459 /// Accept an invitation to join this room.
454460 InviteAccept,
455461
@@ -477,6 +483,9 @@ pub enum RoomAction {
477483 /// Unset a room property.
478484 Unset(RoomField),
479485
486 /// Upgrade the version of a room.
487 Upgrade(RoomVersionId, Vec<OwnedUserId>, bool),
488
480489 /// List the values in a list room property.
481490 Show(RoomField),
482491
src/commands.rs +113 −19
@@ -4,12 +4,12 @@
44//! [modalkit::env::vim::command] for additional Vim commands we pull in.
55use std::{convert::TryFrom, str::FromStr as _};
66
7use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId, events::tag::TagName};
7use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId, RoomVersionId, events::tag::TagName};
88
99use modalkit::{
1010 commands::{CommandError, CommandResult, CommandStep},
1111 env::vim::command::{CommandContext, CommandDescription, OptionType},
12 prelude::OpenTarget,
12 prelude::{MoveDir1D, OpenTarget},
1313};
1414
1515use crate::base::{
@@ -200,6 +200,27 @@ fn iamb_leave(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
200200 return Ok(step);
201201}
202202
203fn iamb_follow(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
204 let mut args = desc.arg.strings()?;
205
206 if args.len() > 1 {
207 return Result::Err(CommandError::InvalidArgument);
208 }
209
210 let dir = match args.pop().as_deref() {
211 None | Some("next") => MoveDir1D::Next,
212 Some("prev") | Some("previous") => MoveDir1D::Previous,
213 Some(_) => return Result::Err(CommandError::InvalidArgument),
214 };
215
216 let context = Box::new(ctx.clone());
217 let follow = RoomAction::Follow(context, dir);
218 let follow = IambAction::Room(follow);
219 let step = CommandStep::Continue(follow.into(), ctx.context.clone());
220
221 return Ok(step);
222}
223
203224fn iamb_forget(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
204225 if !desc.arg.text.is_empty() {
205226 return Result::Err(CommandError::InvalidArgument);
@@ -448,20 +469,22 @@ fn iamb_create(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
448469}
449470
450471fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
451 let mut args = desc.arg.strings()?;
452
453 if args.len() < 2 {
454 return Result::Err(CommandError::InvalidArgument);
455 }
456
457 let field = args.remove(0);
458 let action = args.remove(0);
459
460 if args.len() > 1 {
461 return Result::Err(CommandError::InvalidArgument);
472 let mut iter = desc.arg.strings()?.into_iter();
473 let field = iter.next().ok_or(CommandError::InvalidArgument)?;
474 let action = iter.next().ok_or(CommandError::InvalidArgument)?;
475 let arg = iter.next();
476 let trailing = iter.collect::<Vec<_>>();
477
478 match (field.as_str(), action.as_str()) {
479 // Skip check for commands that takes a variable number of arguments:
480 ("version", "upgrade") => (),
481
482 // Reject if we have any trailing arguments:
483 (_, _) if !trailing.is_empty() => return Result::Err(CommandError::InvalidArgument),
484 (_, _) => (),
462485 }
463486
464 let act: IambAction = match (field.as_str(), action.as_str(), args.pop()) {
487 let act: IambAction = match (field.as_str(), action.as_str(), arg) {
465488 // :room dm set
466489 ("dm", "set", None) => RoomAction::SetDirect(true).into(),
467490 ("dm", "set", Some(_)) => return Result::Err(CommandError::InvalidArgument),
@@ -533,6 +556,28 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
533556 ("notify", "show", None) => RoomAction::Show(RoomField::NotificationMode).into(),
534557 ("notify", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
535558
559 // :room version show
560 ("version", "show", None) => RoomAction::Show(RoomField::Version).into(),
561 ("version", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
562
563 // :room version upgrade
564 ("version", "upgrade", Some(s)) => {
565 let version = RoomVersionId::from_str(&s).map_err(|e| {
566 CommandError::Error(format!("{s:?} is not a valid room version: {e}"))
567 })?;
568 let additional_creators = trailing
569 .iter()
570 .map(|u| {
571 OwnedUserId::from_str(u).map_err(|e| {
572 let msg = format!("{u:?} is not a valid user identifier: {e}");
573 CommandError::Error(msg)
574 })
575 })
576 .collect::<Result<Vec<_>, _>>()?;
577 RoomAction::Upgrade(version, additional_creators, desc.bang).into()
578 },
579 ("version", "upgrade", None) => return Result::Err(CommandError::InvalidArgument),
580
536581 // :room aliases show
537582 ("alias", "show", None) => RoomAction::Show(RoomField::Aliases).into(),
538583 ("alias", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument),
@@ -758,6 +803,16 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
758803 });
759804 cmds.add_command(ProgramCommand { name: "open".into(), aliases: vec![], f: iamb_open });
760805 cmds.add_command(ProgramCommand { name: "edit".into(), aliases: vec![], f: iamb_edit });
806 cmds.add_command(ProgramCommand {
807 name: "follow".into(),
808 aliases: vec![],
809 f: iamb_follow,
810 });
811 cmds.add_command(ProgramCommand {
812 name: "forget".into(),
813 aliases: vec![],
814 f: iamb_forget,
815 });
761816 cmds.add_command(ProgramCommand {
762817 name: "invite".into(),
763818 aliases: vec![],
@@ -770,11 +825,6 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) {
770825 aliases: vec![],
771826 f: iamb_leave,
772827 });
773 cmds.add_command(ProgramCommand {
774 name: "forget".into(),
775 aliases: vec![],
776 f: iamb_forget,
777 });
778828 cmds.add_command(ProgramCommand {
779829 name: "members".into(),
780830 aliases: vec![],
@@ -1460,4 +1510,48 @@ mod tests {
14601510 let res = cmds.input_cmd("keys import foo bar baz", ctx.clone());
14611511 assert_eq!(res, Err(CommandError::InvalidArgument));
14621512 }
1513
1514 #[test]
1515 fn test_cmd_multiple_trailing() {
1516 let mut cmds = setup_commands();
1517 let ctx = EditContext::default();
1518
1519 // Trailing arguments disallowed on commands that don't take any:
1520 let res = cmds.input_cmd("room version show foo", ctx.clone()).unwrap_err();
1521 let err = CommandError::InvalidArgument;
1522 assert_eq!(res, err);
1523
1524 // Trailing arguments allowed on commands that take them:
1525 let res = cmds.input_cmd("room version upgrade 12", ctx.clone()).unwrap();
1526 let act = IambAction::Room(RoomAction::Upgrade(RoomVersionId::V12, vec![], false));
1527 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1528
1529 let res = cmds
1530 .input_cmd("room version upgrade 12 @foo:example.com", ctx.clone())
1531 .unwrap();
1532 let act = IambAction::Room(RoomAction::Upgrade(
1533 RoomVersionId::V12,
1534 vec![user_id!("@foo:example.com").to_owned()],
1535 false,
1536 ));
1537 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1538
1539 let res = cmds
1540 .input_cmd("room version upgrade 12 @foo:example.com @bar:example.com", ctx.clone())
1541 .unwrap();
1542 let act = IambAction::Room(RoomAction::Upgrade(
1543 RoomVersionId::V12,
1544 vec![
1545 user_id!("@foo:example.com").to_owned(),
1546 user_id!("@bar:example.com").to_owned(),
1547 ],
1548 false,
1549 ));
1550 assert_eq!(res, vec![(act.into(), ctx.clone())]);
1551
1552 // But the command must take *some* arguments:
1553 let res = cmds.input_cmd("room version upgrade", ctx.clone()).unwrap_err();
1554 let err = CommandError::InvalidArgument;
1555 assert_eq!(res, err);
1556 }
14631557}
src/windows/room/chat.rs +19 −2
@@ -40,6 +40,7 @@ use matrix_sdk::{
4040use ratatui::{
4141 buffer::Buffer,
4242 layout::Rect,
43 prelude::Stylize,
4344 text::{Line, Span},
4445 widgets::{Paragraph, StatefulWidget, Widget},
4546};
@@ -1109,9 +1110,25 @@ impl StatefulWidget for Chat<'_> {
11091110 type State = ChatState;
11101111
11111112 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
1113 let settings = &self.store.application.settings;
1114
11121115 // Determine whether we have a description to show for the message bar.
11131116 let desc_spans = match (&state.editing, &state.reply_to, state.thread()) {
1114 (None, None, None) => None,
1117 (None, None, None) => {
1118 if state.room.is_tombstoned() {
1119 Some(
1120 Line::from(vec![
1121 Span::from("This room has been upgraded! ").bold(),
1122 Span::from("Use "),
1123 Span::from(":follow").bold(),
1124 Span::from(" to join everyone in the new room."),
1125 ])
1126 .centered(),
1127 )
1128 } else {
1129 None
1130 }
1131 },
11151132 (None, None, Some(_)) => Some(Line::from("Replying in thread")),
11161133 (Some(_), None, None) => Some(Line::from("Editing message")),
11171134 (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")),
@@ -1153,7 +1170,7 @@ impl StatefulWidget for Chat<'_> {
11531170 Paragraph::new(desc_spans).render(descarea, buf);
11541171 }
11551172
1156 let encryption_settings = &self.store.application.settings.tunables.encryption;
1173 let encryption_settings = &settings.tunables.encryption;
11571174 let encryption_indicator = encryption_settings
11581175 .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state());
11591176 let prompt = match (self.focused, encryption_indicator) {
src/windows/room/mod.rs +67 −1
@@ -1,7 +1,6 @@
11//! # Windows for Matrix rooms and spaces
22use std::collections::HashSet;
33
4use matrix_sdk::ruma::api::error::ErrorKind as ClientApiErrorKind;
54use matrix_sdk::{
65 RoomDisplayName,
76 RoomState as MatrixRoomState,
@@ -12,6 +11,10 @@ use matrix_sdk::{
1211 OwnedRoomAliasId,
1312 OwnedUserId,
1413 RoomId,
14 api::{
15 client::room::upgrade_room::v3::Request as UpgradeRoomRequest,
16 error::ErrorKind as ClientApiErrorKind,
17 },
1518 events::{
1619 room::{
1720 canonical_alias::RoomCanonicalAliasEventContent,
@@ -40,6 +43,7 @@ use modalkit::actions::{
4043 PromptAction,
4144 Promptable,
4245 Scrollable,
46 WindowAction,
4347};
4448use modalkit::errors::{EditResult, UIError};
4549use modalkit::prelude::*;
@@ -115,7 +119,32 @@ pub async fn room_command(
115119 ctx: ProgramContext,
116120 store: &mut ProgramStore,
117121) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
122 let worker = &store.application.worker;
123
118124 match act {
125 RoomAction::Follow(cmd, dir) => {
126 let room = worker.client.get_room(id).ok_or(IambError::NotJoined)?;
127 let room_id = match dir {
128 MoveDir1D::Next => {
129 let successor = room
130 .successor_room()
131 .ok_or_else(|| UIError::Failure("No successor room found".into()))?;
132 successor.room_id
133 },
134 MoveDir1D::Previous => {
135 let predecessor = room
136 .predecessor_room()
137 .ok_or_else(|| UIError::Failure("No predecessor room found".into()))?;
138 predecessor.room_id
139 },
140 };
141
142 let id = IambId::Room(room_id.to_owned(), None);
143 let target = OpenTarget::Application(id);
144 let act = cmd.switch(target);
145
146 Ok(vec![(act, cmd.context.clone())])
147 },
119148 RoomAction::InviteAccept => {
120149 if let Some(room) = store.application.worker.client.get_room(id) {
121150 room.join().await.map_err(IambError::from)?;
@@ -361,6 +390,9 @@ pub async fn room_command(
361390 RoomField::Id => {
362391 // This never happens, id is only used for showing
363392 },
393 RoomField::Version => {
394 // This never happens, version is only used for showing or upgrading.
395 },
364396 }
365397
366398 Ok(vec![])
@@ -457,6 +489,9 @@ pub async fn room_command(
457489 RoomField::Id => {
458490 // This never happens, id is only used for showing
459491 },
492 RoomField::Version => {
493 // This never happens, version is only used for showing or upgrading.
494 },
460495 }
461496
462497 Ok(vec![])
@@ -477,6 +512,11 @@ pub async fn room_command(
477512 let id = room.room_id();
478513 format!("Room identifier: {id}")
479514 },
515 RoomField::Version => {
516 let v = room.version();
517 let v = v.as_ref().map(|v| v.as_str()).unwrap_or("<version unknown>");
518 format!("Room version: {v}")
519 },
480520 RoomField::Name => {
481521 match room.name() {
482522 None => "Room has no name".into(),
@@ -533,6 +573,32 @@ pub async fn room_command(
533573
534574 Ok(vec![(act, ctx)])
535575 },
576 RoomAction::Upgrade(new_version, additional_creators, false) => {
577 let room = worker.client.get_room(id).ok_or(IambError::NotJoined)?;
578 let alias = room.canonical_alias();
579 let name = alias.as_ref().map(|c| c.as_str()).unwrap_or_else(|| id.as_str());
580 let msg = format!(
581 "Are you sure you want to upgrade {name} to version {new_version} with {} additional creators set?",
582 additional_creators.len()
583 );
584 let upgrade =
585 IambAction::Room(RoomAction::Upgrade(new_version, additional_creators, true));
586 let prompt = PromptYesNo::new(msg, vec![Action::from(upgrade)]);
587 let prompt = Box::new(prompt);
588
589 Err(UIError::NeedConfirm(prompt))
590 },
591 RoomAction::Upgrade(new_version, additional_creators, true) => {
592 let mut request = UpgradeRoomRequest::new(id.to_owned(), new_version);
593 request.additional_creators = additional_creators;
594
595 let response = worker.client.send(request).await.map_err(IambError::from)?;
596 let id = IambId::Room(response.replacement_room, None);
597 let target = OpenTarget::Application(id);
598 let act = WindowAction::Switch(target);
599
600 Ok(vec![(act.into(), ctx)])
601 },
536602 }
537603}
538604