Commit 93eff79f79
Unregistered key
Layout: unified · split
Cargo.lock +2 −2
| @@ -1882,9 +1882,9 @@ dependencies = [ | ||
| 1882 | 1882 | |
| 1883 | 1883 | [[package]] |
| 1884 | 1884 | name = "modalkit" |
| 1885 | version = "0.0.12" | |
| 1885 | version = "0.0.13" | |
| 1886 | 1886 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1887 | checksum = "9a4e5226a5d33a7bdf5b4fc067baa211c94f21aa6667af5eec8b357a8af5e4ba" | |
| 1887 | checksum = "038bb42efcd659fb123708bf8e4ea12ca9023f07d44514f9358b9334ea7ba80f" | |
| 1888 | 1888 | dependencies = [ |
| 1889 | 1889 | "anymap2", |
| 1890 | 1890 | "arboard", |
Cargo.toml +1 −1
| @@ -39,7 +39,7 @@ unicode-width = "0.1.10" | ||
| 39 | 39 | url = {version = "^2.2.2", features = ["serde"]} |
| 40 | 40 | |
| 41 | 41 | [dependencies.modalkit] |
| 42 | version = "0.0.12" | |
| 42 | version = "0.0.13" | |
| 43 | 43 | |
| 44 | 44 | [dependencies.matrix-sdk] |
| 45 | 45 | version = "0.6" |
src/base.rs +22
| @@ -135,6 +135,12 @@ pub enum MessageAction { | ||
| 135 | 135 | pub enum CreateRoomType { |
| 136 | 136 | /// A direct message room. |
| 137 | 137 | Direct(OwnedUserId), |
| 138 | ||
| 139 | /// A standard chat room. | |
| 140 | Room, | |
| 141 | ||
| 142 | /// A Matrix space. | |
| 143 | Space, | |
| 138 | 144 | } |
| 139 | 145 | |
| 140 | 146 | bitflags::bitflags! { |
| @@ -184,8 +190,14 @@ pub enum SendAction { | ||
| 184 | 190 | Upload(String), |
| 185 | 191 | } |
| 186 | 192 | |
| 193 | #[derive(Clone, Debug, Eq, PartialEq)] | |
| 194 | pub enum HomeserverAction { | |
| 195 | CreateRoom(Option<String>, CreateRoomType, CreateRoomFlags), | |
| 196 | } | |
| 197 | ||
| 187 | 198 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 188 | 199 | pub enum IambAction { |
| 200 | Homeserver(HomeserverAction), | |
| 189 | 201 | Message(MessageAction), |
| 190 | 202 | Room(RoomAction), |
| 191 | 203 | Send(SendAction), |
| @@ -194,6 +206,12 @@ pub enum IambAction { | ||
| 194 | 206 | ToggleScrollbackFocus, |
| 195 | 207 | } |
| 196 | 208 | |
| 209 | impl From<HomeserverAction> for IambAction { | |
| 210 | fn from(act: HomeserverAction) -> Self { | |
| 211 | IambAction::Homeserver(act) | |
| 212 | } | |
| 213 | } | |
| 214 | ||
| 197 | 215 | impl From<MessageAction> for IambAction { |
| 198 | 216 | fn from(act: MessageAction) -> Self { |
| 199 | 217 | IambAction::Message(act) |
| @@ -215,6 +233,7 @@ impl From<SendAction> for IambAction { | ||
| 215 | 233 | impl ApplicationAction for IambAction { |
| 216 | 234 | fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 217 | 235 | match self { |
| 236 | IambAction::Homeserver(..) => SequenceStatus::Break, | |
| 218 | 237 | IambAction::Message(..) => SequenceStatus::Break, |
| 219 | 238 | IambAction::Room(..) => SequenceStatus::Break, |
| 220 | 239 | IambAction::Send(..) => SequenceStatus::Break, |
| @@ -226,6 +245,7 @@ impl ApplicationAction for IambAction { | ||
| 226 | 245 | |
| 227 | 246 | fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 228 | 247 | match self { |
| 248 | IambAction::Homeserver(..) => SequenceStatus::Atom, | |
| 229 | 249 | IambAction::Message(..) => SequenceStatus::Atom, |
| 230 | 250 | IambAction::Room(..) => SequenceStatus::Atom, |
| 231 | 251 | IambAction::Send(..) => SequenceStatus::Atom, |
| @@ -237,6 +257,7 @@ impl ApplicationAction for IambAction { | ||
| 237 | 257 | |
| 238 | 258 | fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 239 | 259 | match self { |
| 260 | IambAction::Homeserver(..) => SequenceStatus::Ignore, | |
| 240 | 261 | IambAction::Message(..) => SequenceStatus::Ignore, |
| 241 | 262 | IambAction::Room(..) => SequenceStatus::Ignore, |
| 242 | 263 | IambAction::Send(..) => SequenceStatus::Ignore, |
| @@ -248,6 +269,7 @@ impl ApplicationAction for IambAction { | ||
| 248 | 269 | |
| 249 | 270 | fn is_switchable<C: EditContext>(&self, _: &C) -> bool { |
| 250 | 271 | match self { |
| 272 | IambAction::Homeserver(..) => false, | |
| 251 | 273 | IambAction::Message(..) => false, |
| 252 | 274 | IambAction::Room(..) => false, |
| 253 | 275 | IambAction::Send(..) => false, |
src/commands.rs +56 −1
| @@ -4,13 +4,16 @@ use matrix_sdk::ruma::{events::tag::TagName, OwnedUserId}; | ||
| 4 | 4 | |
| 5 | 5 | use modalkit::{ |
| 6 | 6 | editing::base::OpenTarget, |
| 7 | env::vim::command::{CommandContext, CommandDescription}, | |
| 7 | env::vim::command::{CommandContext, CommandDescription, OptionType}, | |
| 8 | 8 | input::commands::{CommandError, CommandResult, CommandStep}, |
| 9 | 9 | input::InputContext, |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | use crate::base::{ |
| 13 | CreateRoomFlags, | |
| 14 | CreateRoomType, | |
| 13 | 15 | DownloadFlags, |
| 16 | HomeserverAction, | |
| 14 | 17 | IambAction, |
| 15 | 18 | IambId, |
| 16 | 19 | MessageAction, |
| @@ -297,6 +300,53 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 297 | 300 | return Ok(step); |
| 298 | 301 | } |
| 299 | 302 | |
| 303 | fn iamb_create(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 304 | let args = desc.arg.options()?; | |
| 305 | let mut flags = CreateRoomFlags::NONE; | |
| 306 | let mut alias = None; | |
| 307 | let mut ct = CreateRoomType::Room; | |
| 308 | ||
| 309 | for arg in args { | |
| 310 | match arg { | |
| 311 | OptionType::Flag(name, Some(arg)) => { | |
| 312 | match name.as_str() { | |
| 313 | "alias" => { | |
| 314 | if alias.is_some() { | |
| 315 | let msg = "Multiple ++alias arguments are not allowed"; | |
| 316 | let err = CommandError::Error(msg.into()); | |
| 317 | ||
| 318 | return Err(err); | |
| 319 | } else { | |
| 320 | alias = Some(arg); | |
| 321 | } | |
| 322 | }, | |
| 323 | _ => return Err(CommandError::InvalidArgument), | |
| 324 | } | |
| 325 | }, | |
| 326 | OptionType::Flag(name, None) => { | |
| 327 | match name.as_str() { | |
| 328 | "public" => flags |= CreateRoomFlags::PUBLIC, | |
| 329 | "space" => ct = CreateRoomType::Space, | |
| 330 | "enc" | "encrypted" => flags |= CreateRoomFlags::ENCRYPTED, | |
| 331 | _ => return Err(CommandError::InvalidArgument), | |
| 332 | } | |
| 333 | }, | |
| 334 | OptionType::Positional(_) => { | |
| 335 | let msg = ":create doesn't take any positional arguments"; | |
| 336 | let err = CommandError::Error(msg.into()); | |
| 337 | ||
| 338 | return Err(err); | |
| 339 | }, | |
| 340 | } | |
| 341 | } | |
| 342 | ||
| 343 | let hact = HomeserverAction::CreateRoom(alias, ct, flags); | |
| 344 | let iact = IambAction::from(hact); | |
| 345 | let step = CommandStep::Continue(iact.into(), ctx.context.take()); | |
| 346 | ||
| 347 | return Ok(step); | |
| 348 | } | |
| 349 | ||
| 300 | 350 | fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 301 | 351 | let mut args = desc.arg.strings()?; |
| 302 | 352 | |
| @@ -400,6 +450,11 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 400 | 450 | aliases: vec![], |
| 401 | 451 | f: iamb_cancel, |
| 402 | 452 | }); |
| 453 | cmds.add_command(ProgramCommand { | |
| 454 | name: "create".into(), | |
| 455 | aliases: vec![], | |
| 456 | f: iamb_create, | |
| 457 | }); | |
| 403 | 458 | cmds.add_command(ProgramCommand { name: "dms".into(), aliases: vec![], f: iamb_dms }); |
| 404 | 459 | cmds.add_command(ProgramCommand { |
| 405 | 460 | name: "download".into(), |
src/main.rs +28 −2
| @@ -53,6 +53,7 @@ use crate::{ | ||
| 53 | 53 | base::{ |
| 54 | 54 | AsyncProgramStore, |
| 55 | 55 | ChatStore, |
| 56 | HomeserverAction, | |
| 56 | 57 | IambAction, |
| 57 | 58 | IambError, |
| 58 | 59 | IambId, |
| @@ -64,7 +65,7 @@ use crate::{ | ||
| 64 | 65 | }, |
| 65 | 66 | config::{ApplicationSettings, Iamb}, |
| 66 | 67 | windows::IambWindow, |
| 67 | worker::{ClientWorker, LoginStyle, Requester}, | |
| 68 | worker::{create_room, ClientWorker, LoginStyle, Requester}, | |
| 68 | 69 | }; |
| 69 | 70 | |
| 70 | 71 | use modalkit::{ |
| @@ -355,6 +356,12 @@ impl Application { | ||
| 355 | 356 | None |
| 356 | 357 | }, |
| 357 | 358 | |
| 359 | IambAction::Homeserver(act) => { | |
| 360 | let acts = self.homeserver_command(act, ctx, store).await?; | |
| 361 | self.action_prepend(acts); | |
| 362 | ||
| 363 | None | |
| 364 | }, | |
| 358 | 365 | IambAction::Message(act) => { |
| 359 | 366 | self.screen.current_window_mut()?.message_command(act, ctx, store).await? |
| 360 | 367 | }, |
| @@ -387,6 +394,25 @@ impl Application { | ||
| 387 | 394 | Ok(info) |
| 388 | 395 | } |
| 389 | 396 | |
| 397 | async fn homeserver_command( | |
| 398 | &mut self, | |
| 399 | action: HomeserverAction, | |
| 400 | ctx: ProgramContext, | |
| 401 | store: &mut ProgramStore, | |
| 402 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { | |
| 403 | match action { | |
| 404 | HomeserverAction::CreateRoom(alias, vis, flags) => { | |
| 405 | let client = &store.application.worker.client; | |
| 406 | let room_id = create_room(client, alias.as_deref(), vis, flags).await?; | |
| 407 | let room = IambId::Room(room_id); | |
| 408 | let target = OpenTarget::Application(room); | |
| 409 | let action = WindowAction::Switch(target); | |
| 410 | ||
| 411 | Ok(vec![(action.into(), ctx)]) | |
| 412 | }, | |
| 413 | } | |
| 414 | } | |
| 415 | ||
| 390 | 416 | pub async fn run(&mut self) -> Result<(), std::io::Error> { |
| 391 | 417 | self.terminal.clear()?; |
| 392 | 418 | |
| @@ -518,7 +544,7 @@ fn main() -> IambResult<()> { | ||
| 518 | 544 | |
| 519 | 545 | let subscriber = FmtSubscriber::builder() |
| 520 | 546 | .with_writer(appender) |
| 521 | .with_max_level(Level::TRACE) | |
| 547 | .with_max_level(Level::INFO) | |
| 522 | 548 | .finish(); |
| 523 | 549 | tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); |
| 524 | 550 | |
src/worker.rs +13 −4
| @@ -20,7 +20,7 @@ use matrix_sdk::{ | ||
| 20 | 20 | room::{Invited, Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, |
| 21 | 21 | ruma::{ |
| 22 | 22 | api::client::{ |
| 23 | room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, | |
| 23 | room::create_room::v3::{CreationContent, Request as CreateRoomRequest, RoomPreset}, | |
| 24 | 24 | room::Visibility, |
| 25 | 25 | space::get_hierarchy::v1::Request as SpaceHierarchyRequest, |
| 26 | 26 | }, |
| @@ -50,6 +50,7 @@ use matrix_sdk::{ | ||
| 50 | 50 | SyncMessageLikeEvent, |
| 51 | 51 | SyncStateEvent, |
| 52 | 52 | }, |
| 53 | room::RoomType, | |
| 53 | 54 | serde::Raw, |
| 54 | 55 | EventEncryptionAlgorithm, |
| 55 | 56 | OwnedRoomId, |
| @@ -93,10 +94,10 @@ pub async fn create_room( | ||
| 93 | 94 | rt: CreateRoomType, |
| 94 | 95 | flags: CreateRoomFlags, |
| 95 | 96 | ) -> IambResult<OwnedRoomId> { |
| 96 | let creation_content = None; | |
| 97 | let mut creation_content = None; | |
| 97 | 98 | let mut initial_state = vec![]; |
| 98 | let is_direct; | |
| 99 | let preset; | |
| 99 | let mut is_direct = false; | |
| 100 | let mut preset = None; | |
| 100 | 101 | let mut invite = vec![]; |
| 101 | 102 | |
| 102 | 103 | let visibility = if flags.contains(CreateRoomFlags::PUBLIC) { |
| @@ -111,6 +112,14 @@ pub async fn create_room( | ||
| 111 | 112 | is_direct = true; |
| 112 | 113 | preset = Some(RoomPreset::TrustedPrivateChat); |
| 113 | 114 | }, |
| 115 | CreateRoomType::Space => { | |
| 116 | let mut cc = CreationContent::new(); | |
| 117 | cc.room_type = Some(RoomType::Space); | |
| 118 | ||
| 119 | let raw_cc = Raw::new(&cc).map_err(IambError::from)?; | |
| 120 | creation_content = Some(raw_cc); | |
| 121 | }, | |
| 122 | CreateRoomType::Room => {}, | |
| 114 | 123 | } |
| 115 | 124 | |
| 116 | 125 | // Set up encryption. |