Commit 65399063e5
Unregistered key
Layout: unified · split
docs/iamb.1 +9 −1
| @@ -72,7 +72,6 @@ View the startup Welcome window. | |||
| 72 | .It Sy ":forget" | 72 | .It Sy ":forget" |
| 73 | Remove all left rooms from the internal database. | 73 | Remove all left rooms from the internal database. |
| 74 | .El | 74 | .El |
| 75 | |||
| 76 | .Sh "E2EE COMMANDS" | 75 | .Sh "E2EE COMMANDS" |
| 77 | .Bl -tag -width Ds | 76 | .Bl -tag -width Ds |
| 78 | .It Sy ":keys export [path] [passphrase]" | 77 | .It Sy ":keys export [path] [passphrase]" |
| @@ -133,6 +132,10 @@ Create a new room. Arguments can be | |||
| 133 | .Dq ++space , | 132 | .Dq ++space , |
| 134 | and | 133 | and |
| 135 | .Dq ++encrypted . | 134 | .Dq ++encrypted . |
| 135 | .It Sy ":follow next" | ||
| 136 | Follow the tombstone information to the upgraded room. | ||
| 137 | .It Sy ":follow previous" | ||
| 138 | Follow the room creation information to the pre-upgraded room. | ||
| 136 | .It Sy ":invite accept" | 139 | .It Sy ":invite accept" |
| 137 | Accept an invitation to the currently focused room. | 140 | Accept an invitation to the currently focused room. |
| 138 | .It Sy ":invite reject" | 141 | .It Sy ":invite reject" |
| @@ -160,6 +163,11 @@ Mark the currently focused room as read. | |||
| 160 | .It Sy ":room unread clear" | 163 | .It Sy ":room unread clear" |
| 161 | Alias for | 164 | Alias for |
| 162 | .Sy :room unread unset . | 165 | .Sy :room unread unset . |
| 166 | .It Sy ":room version show" | ||
| 167 | Show the Matrix version for this room. | ||
| 168 | .It Sy ":room version upgrade [version] [additional creators...]" | ||
| 169 | Upgrade the Matrix version for this room to the specified version. | ||
| 170 | Note that room upgrading in Matrix works by creating a new room that everyone else will then need to join. | ||
| 163 | .It Sy ":room notify set [level]" | 171 | .It Sy ":room notify set [level]" |
| 164 | Set a notification level for the currently focused room. | 172 | Set a notification level for the currently focused room. |
| 165 | Valid levels are | 173 | Valid levels are |
src/base.rs +11 −2
| @@ -14,10 +14,10 @@ use std::time::{Duration, Instant}; | |||
| 14 | use emojis::Emoji; | 14 | use emojis::Emoji; |
| 15 | 15 | ||
| 16 | use matrix_sdk::ruma::OwnedMxcUri; | 16 | use matrix_sdk::ruma::OwnedMxcUri; |
| 17 | use matrix_sdk::ruma::OwnedTransactionId; | ||
| 18 | use matrix_sdk::ruma::events::receipt::ReceiptThread; | 17 | use matrix_sdk::ruma::events::receipt::ReceiptThread; |
| 19 | use matrix_sdk::ruma::events::room::MediaSource; | 18 | use matrix_sdk::ruma::events::room::MediaSource; |
| 20 | use matrix_sdk::ruma::events::sticker::StickerEvent; | 19 | use matrix_sdk::ruma::events::sticker::StickerEvent; |
| 20 | use matrix_sdk::ruma::{OwnedTransactionId, RoomVersionId}; | ||
| 21 | use ratatui::{ | 21 | use ratatui::{ |
| 22 | buffer::Buffer, | 22 | buffer::Buffer, |
| 23 | layout::{Alignment, Rect}, | 23 | layout::{Alignment, Rect}, |
| @@ -91,7 +91,7 @@ use modalkit::{ | |||
| 91 | errors::{UIError, UIResult}, | 91 | errors::{UIError, UIResult}, |
| 92 | key::TerminalKey, | 92 | key::TerminalKey, |
| 93 | keybindings::SequenceStatus, | 93 | keybindings::SequenceStatus, |
| 94 | prelude::{CommandType, WordStyle}, | 94 | prelude::{CommandType, MoveDir1D, WordStyle}, |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | use crate::config::ImagePreviewSize; | 97 | use crate::config::ImagePreviewSize; |
| @@ -407,6 +407,9 @@ pub enum RoomField { | |||
| 407 | /// The room name. | 407 | /// The room name. |
| 408 | Name, | 408 | Name, |
| 409 | 409 | ||
| 410 | /// The room version. | ||
| 411 | Version, | ||
| 412 | |||
| 410 | /// The room id. | 413 | /// The room id. |
| 411 | Id, | 414 | Id, |
| 412 | 415 | ||
| @@ -450,6 +453,9 @@ impl Display for MemberUpdateAction { | |||
| 450 | /// An action that operates on a focused room. | 453 | /// An action that operates on a focused room. |
| 451 | #[derive(Clone, Debug, Eq, PartialEq)] | 454 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 452 | pub enum RoomAction { | 455 | pub enum RoomAction { |
| 456 | /// Follow the room upgrade information. | ||
| 457 | Follow(Box<CommandContext>, MoveDir1D), | ||
| 458 | |||
| 453 | /// Accept an invitation to join this room. | 459 | /// Accept an invitation to join this room. |
| 454 | InviteAccept, | 460 | InviteAccept, |
| 455 | 461 | ||
| @@ -477,6 +483,9 @@ pub enum RoomAction { | |||
| 477 | /// Unset a room property. | 483 | /// Unset a room property. |
| 478 | Unset(RoomField), | 484 | Unset(RoomField), |
| 479 | 485 | ||
| 486 | /// Upgrade the version of a room. | ||
| 487 | Upgrade(RoomVersionId, Vec<OwnedUserId>, bool), | ||
| 488 | |||
| 480 | /// List the values in a list room property. | 489 | /// List the values in a list room property. |
| 481 | Show(RoomField), | 490 | Show(RoomField), |
| 482 | 491 | ||
src/commands.rs +113 −19
| @@ -4,12 +4,12 @@ | |||
| 4 | //! [modalkit::env::vim::command] for additional Vim commands we pull in. | 4 | //! [modalkit::env::vim::command] for additional Vim commands we pull in. |
| 5 | use std::{convert::TryFrom, str::FromStr as _}; | 5 | use std::{convert::TryFrom, str::FromStr as _}; |
| 6 | 6 | ||
| 7 | use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId, events::tag::TagName}; | 7 | use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId, RoomVersionId, events::tag::TagName}; |
| 8 | 8 | ||
| 9 | use modalkit::{ | 9 | use modalkit::{ |
| 10 | commands::{CommandError, CommandResult, CommandStep}, | 10 | commands::{CommandError, CommandResult, CommandStep}, |
| 11 | env::vim::command::{CommandContext, CommandDescription, OptionType}, | 11 | env::vim::command::{CommandContext, CommandDescription, OptionType}, |
| 12 | prelude::OpenTarget, | 12 | prelude::{MoveDir1D, OpenTarget}, |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | use crate::base::{ | 15 | use crate::base::{ |
| @@ -200,6 +200,27 @@ fn iamb_leave(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |||
| 200 | return Ok(step); | 200 | return Ok(step); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | fn 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 | |||
| 203 | fn iamb_forget(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | 224 | fn iamb_forget(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 204 | if !desc.arg.text.is_empty() { | 225 | if !desc.arg.text.is_empty() { |
| 205 | return Result::Err(CommandError::InvalidArgument); | 226 | return Result::Err(CommandError::InvalidArgument); |
| @@ -448,20 +469,22 @@ fn iamb_create(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |||
| 448 | } | 469 | } |
| 449 | 470 | ||
| 450 | fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | 471 | fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 451 | let mut args = desc.arg.strings()?; | 472 | let mut iter = desc.arg.strings()?.into_iter(); |
| 452 | 473 | let field = iter.next().ok_or(CommandError::InvalidArgument)?; | |
| 453 | if args.len() < 2 { | 474 | let action = iter.next().ok_or(CommandError::InvalidArgument)?; |
| 454 | return Result::Err(CommandError::InvalidArgument); | 475 | let arg = iter.next(); |
| 455 | } | 476 | let trailing = iter.collect::<Vec<_>>(); |
| 456 | 477 | ||
| 457 | let field = args.remove(0); | 478 | match (field.as_str(), action.as_str()) { |
| 458 | let action = args.remove(0); | 479 | // Skip check for commands that takes a variable number of arguments: |
| 459 | 480 | ("version", "upgrade") => (), | |
| 460 | if args.len() > 1 { | 481 | |
| 461 | return Result::Err(CommandError::InvalidArgument); | 482 | // Reject if we have any trailing arguments: |
| 483 | (_, _) if !trailing.is_empty() => return Result::Err(CommandError::InvalidArgument), | ||
| 484 | (_, _) => (), | ||
| 462 | } | 485 | } |
| 463 | 486 | ||
| 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) { |
| 465 | // :room dm set | 488 | // :room dm set |
| 466 | ("dm", "set", None) => RoomAction::SetDirect(true).into(), | 489 | ("dm", "set", None) => RoomAction::SetDirect(true).into(), |
| 467 | ("dm", "set", Some(_)) => return Result::Err(CommandError::InvalidArgument), | 490 | ("dm", "set", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| @@ -533,6 +556,28 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |||
| 533 | ("notify", "show", None) => RoomAction::Show(RoomField::NotificationMode).into(), | 556 | ("notify", "show", None) => RoomAction::Show(RoomField::NotificationMode).into(), |
| 534 | ("notify", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), | 557 | ("notify", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| 535 | 558 | ||
| 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 | |||
| 536 | // :room aliases show | 581 | // :room aliases show |
| 537 | ("alias", "show", None) => RoomAction::Show(RoomField::Aliases).into(), | 582 | ("alias", "show", None) => RoomAction::Show(RoomField::Aliases).into(), |
| 538 | ("alias", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), | 583 | ("alias", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| @@ -758,6 +803,16 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | |||
| 758 | }); | 803 | }); |
| 759 | cmds.add_command(ProgramCommand { name: "open".into(), aliases: vec![], f: iamb_open }); | 804 | cmds.add_command(ProgramCommand { name: "open".into(), aliases: vec![], f: iamb_open }); |
| 760 | cmds.add_command(ProgramCommand { name: "edit".into(), aliases: vec![], f: iamb_edit }); | 805 | 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 | }); | ||
| 761 | cmds.add_command(ProgramCommand { | 816 | cmds.add_command(ProgramCommand { |
| 762 | name: "invite".into(), | 817 | name: "invite".into(), |
| 763 | aliases: vec![], | 818 | aliases: vec![], |
| @@ -770,11 +825,6 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | |||
| 770 | aliases: vec![], | 825 | aliases: vec![], |
| 771 | f: iamb_leave, | 826 | f: iamb_leave, |
| 772 | }); | 827 | }); |
| 773 | cmds.add_command(ProgramCommand { | ||
| 774 | name: "forget".into(), | ||
| 775 | aliases: vec![], | ||
| 776 | f: iamb_forget, | ||
| 777 | }); | ||
| 778 | cmds.add_command(ProgramCommand { | 828 | cmds.add_command(ProgramCommand { |
| 779 | name: "members".into(), | 829 | name: "members".into(), |
| 780 | aliases: vec![], | 830 | aliases: vec![], |
| @@ -1460,4 +1510,48 @@ mod tests { | |||
| 1460 | let res = cmds.input_cmd("keys import foo bar baz", ctx.clone()); | 1510 | let res = cmds.input_cmd("keys import foo bar baz", ctx.clone()); |
| 1461 | assert_eq!(res, Err(CommandError::InvalidArgument)); | 1511 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 1462 | } | 1512 | } |
| 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 | } | ||
| 1463 | } | 1557 | } |
src/windows/room/chat.rs +19 −2
| @@ -40,6 +40,7 @@ use matrix_sdk::{ | |||
| 40 | use ratatui::{ | 40 | use ratatui::{ |
| 41 | buffer::Buffer, | 41 | buffer::Buffer, |
| 42 | layout::Rect, | 42 | layout::Rect, |
| 43 | prelude::Stylize, | ||
| 43 | text::{Line, Span}, | 44 | text::{Line, Span}, |
| 44 | widgets::{Paragraph, StatefulWidget, Widget}, | 45 | widgets::{Paragraph, StatefulWidget, Widget}, |
| 45 | }; | 46 | }; |
| @@ -1109,9 +1110,25 @@ impl StatefulWidget for Chat<'_> { | |||
| 1109 | type State = ChatState; | 1110 | type State = ChatState; |
| 1110 | 1111 | ||
| 1111 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | 1112 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { |
| 1113 | let settings = &self.store.application.settings; | ||
| 1114 | |||
| 1112 | // Determine whether we have a description to show for the message bar. | 1115 | // Determine whether we have a description to show for the message bar. |
| 1113 | let desc_spans = match (&state.editing, &state.reply_to, state.thread()) { | 1116 | 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 | }, | ||
| 1115 | (None, None, Some(_)) => Some(Line::from("Replying in thread")), | 1132 | (None, None, Some(_)) => Some(Line::from("Replying in thread")), |
| 1116 | (Some(_), None, None) => Some(Line::from("Editing message")), | 1133 | (Some(_), None, None) => Some(Line::from("Editing message")), |
| 1117 | (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")), | 1134 | (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")), |
| @@ -1153,7 +1170,7 @@ impl StatefulWidget for Chat<'_> { | |||
| 1153 | Paragraph::new(desc_spans).render(descarea, buf); | 1170 | Paragraph::new(desc_spans).render(descarea, buf); |
| 1154 | } | 1171 | } |
| 1155 | 1172 | ||
| 1156 | let encryption_settings = &self.store.application.settings.tunables.encryption; | 1173 | let encryption_settings = &settings.tunables.encryption; |
| 1157 | let encryption_indicator = encryption_settings | 1174 | let encryption_indicator = encryption_settings |
| 1158 | .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state()); | 1175 | .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state()); |
| 1159 | let prompt = match (self.focused, encryption_indicator) { | 1176 | let prompt = match (self.focused, encryption_indicator) { |
src/windows/room/mod.rs +67 −1
| @@ -1,7 +1,6 @@ | |||
| 1 | //! # Windows for Matrix rooms and spaces | 1 | //! # Windows for Matrix rooms and spaces |
| 2 | use std::collections::HashSet; | 2 | use std::collections::HashSet; |
| 3 | 3 | ||
| 4 | use matrix_sdk::ruma::api::error::ErrorKind as ClientApiErrorKind; | ||
| 5 | use matrix_sdk::{ | 4 | use matrix_sdk::{ |
| 6 | RoomDisplayName, | 5 | RoomDisplayName, |
| 7 | RoomState as MatrixRoomState, | 6 | RoomState as MatrixRoomState, |
| @@ -12,6 +11,10 @@ use matrix_sdk::{ | |||
| 12 | OwnedRoomAliasId, | 11 | OwnedRoomAliasId, |
| 13 | OwnedUserId, | 12 | OwnedUserId, |
| 14 | RoomId, | 13 | RoomId, |
| 14 | api::{ | ||
| 15 | client::room::upgrade_room::v3::Request as UpgradeRoomRequest, | ||
| 16 | error::ErrorKind as ClientApiErrorKind, | ||
| 17 | }, | ||
| 15 | events::{ | 18 | events::{ |
| 16 | room::{ | 19 | room::{ |
| 17 | canonical_alias::RoomCanonicalAliasEventContent, | 20 | canonical_alias::RoomCanonicalAliasEventContent, |
| @@ -40,6 +43,7 @@ use modalkit::actions::{ | |||
| 40 | PromptAction, | 43 | PromptAction, |
| 41 | Promptable, | 44 | Promptable, |
| 42 | Scrollable, | 45 | Scrollable, |
| 46 | WindowAction, | ||
| 43 | }; | 47 | }; |
| 44 | use modalkit::errors::{EditResult, UIError}; | 48 | use modalkit::errors::{EditResult, UIError}; |
| 45 | use modalkit::prelude::*; | 49 | use modalkit::prelude::*; |
| @@ -115,7 +119,32 @@ pub async fn room_command( | |||
| 115 | ctx: ProgramContext, | 119 | ctx: ProgramContext, |
| 116 | store: &mut ProgramStore, | 120 | store: &mut ProgramStore, |
| 117 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { | 121 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { |
| 122 | let worker = &store.application.worker; | ||
| 123 | |||
| 118 | match act { | 124 | 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 | }, | ||
| 119 | RoomAction::InviteAccept => { | 148 | RoomAction::InviteAccept => { |
| 120 | if let Some(room) = store.application.worker.client.get_room(id) { | 149 | if let Some(room) = store.application.worker.client.get_room(id) { |
| 121 | room.join().await.map_err(IambError::from)?; | 150 | room.join().await.map_err(IambError::from)?; |
| @@ -361,6 +390,9 @@ pub async fn room_command( | |||
| 361 | RoomField::Id => { | 390 | RoomField::Id => { |
| 362 | // This never happens, id is only used for showing | 391 | // This never happens, id is only used for showing |
| 363 | }, | 392 | }, |
| 393 | RoomField::Version => { | ||
| 394 | // This never happens, version is only used for showing or upgrading. | ||
| 395 | }, | ||
| 364 | } | 396 | } |
| 365 | 397 | ||
| 366 | Ok(vec![]) | 398 | Ok(vec![]) |
| @@ -457,6 +489,9 @@ pub async fn room_command( | |||
| 457 | RoomField::Id => { | 489 | RoomField::Id => { |
| 458 | // This never happens, id is only used for showing | 490 | // This never happens, id is only used for showing |
| 459 | }, | 491 | }, |
| 492 | RoomField::Version => { | ||
| 493 | // This never happens, version is only used for showing or upgrading. | ||
| 494 | }, | ||
| 460 | } | 495 | } |
| 461 | 496 | ||
| 462 | Ok(vec![]) | 497 | Ok(vec![]) |
| @@ -477,6 +512,11 @@ pub async fn room_command( | |||
| 477 | let id = room.room_id(); | 512 | let id = room.room_id(); |
| 478 | format!("Room identifier: {id}") | 513 | format!("Room identifier: {id}") |
| 479 | }, | 514 | }, |
| 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 | }, | ||
| 480 | RoomField::Name => { | 520 | RoomField::Name => { |
| 481 | match room.name() { | 521 | match room.name() { |
| 482 | None => "Room has no name".into(), | 522 | None => "Room has no name".into(), |
| @@ -533,6 +573,32 @@ pub async fn room_command( | |||
| 533 | 573 | ||
| 534 | Ok(vec![(act, ctx)]) | 574 | Ok(vec![(act, ctx)]) |
| 535 | }, | 575 | }, |
| 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 | }, | ||
| 536 | } | 602 | } |
| 537 | } | 603 | } |
| 538 | 604 | ||