Commit a6888bbc93
Unregistered key
Layout: unified · split
README.md +1 −1
| @@ -49,7 +49,7 @@ two other TUI clients and Element Web: | ||
| 49 | 49 | | --------------------------------------- | :---------- | :------: | :--------------: | :-----------------: | |
| 50 | 50 | | Room directory | ❌ ([#14]) | ❌ | ✔️ | ✔️ | |
| 51 | 51 | | Room tag showing | ❌ ([#15]) | ✔️ | ❌ | ✔️ | |
| 52 | | Room tag editing | ❌ ([#15]) | ✔️ | ❌ | ✔️ | | |
| 52 | | Room tag editing | ✔️ | ✔️ | ❌ | ✔️ | | |
| 53 | 53 | | Search joined rooms | ❌ ([#16]) | ✔️ | ❌ | ✔️ | |
| 54 | 54 | | Room user list | ✔️ | ✔️ | ✔️ | ✔️ | |
| 55 | 55 | | Display Room Description | ✔️ | ✔️ | ✔️ | ✔️ | |
src/base.rs +19 −10
| @@ -8,6 +8,7 @@ use tracing::warn; | ||
| 8 | 8 | |
| 9 | 9 | use matrix_sdk::{ |
| 10 | 10 | encryption::verification::SasVerification, |
| 11 | room::Joined, | |
| 11 | 12 | ruma::{ |
| 12 | 13 | events::room::message::{ |
| 13 | 14 | OriginalRoomMessageEvent, |
| @@ -16,6 +17,7 @@ use matrix_sdk::{ | ||
| 16 | 17 | RoomMessageEvent, |
| 17 | 18 | RoomMessageEventContent, |
| 18 | 19 | }, |
| 20 | events::tag::{TagName, Tags}, | |
| 19 | 21 | EventId, |
| 20 | 22 | OwnedEventId, |
| 21 | 23 | OwnedRoomId, |
| @@ -94,9 +96,10 @@ pub enum MessageAction { | ||
| 94 | 96 | } |
| 95 | 97 | |
| 96 | 98 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 97 | pub enum SetRoomField { | |
| 98 | Name(String), | |
| 99 | Topic(String), | |
| 99 | pub enum RoomField { | |
| 100 | Name, | |
| 101 | Tag(TagName), | |
| 102 | Topic, | |
| 100 | 103 | } |
| 101 | 104 | |
| 102 | 105 | #[derive(Clone, Debug, Eq, PartialEq)] |
| @@ -105,13 +108,8 @@ pub enum RoomAction { | ||
| 105 | 108 | InviteReject, |
| 106 | 109 | InviteSend(OwnedUserId), |
| 107 | 110 | Members(Box<CommandContext<ProgramContext>>), |
| 108 | Set(SetRoomField), | |
| 109 | } | |
| 110 | ||
| 111 | impl From<SetRoomField> for RoomAction { | |
| 112 | fn from(act: SetRoomField) -> Self { | |
| 113 | RoomAction::Set(act) | |
| 114 | } | |
| 111 | Set(RoomField, String), | |
| 112 | Unset(RoomField), | |
| 115 | 113 | } |
| 116 | 114 | |
| 117 | 115 | #[derive(Clone, Debug, Eq, PartialEq)] |
| @@ -194,6 +192,12 @@ impl ApplicationAction for IambAction { | ||
| 194 | 192 | } |
| 195 | 193 | } |
| 196 | 194 | |
| 195 | impl From<RoomAction> for ProgramAction { | |
| 196 | fn from(act: RoomAction) -> Self { | |
| 197 | IambAction::from(act).into() | |
| 198 | } | |
| 199 | } | |
| 200 | ||
| 197 | 201 | impl From<IambAction> for ProgramAction { |
| 198 | 202 | fn from(act: IambAction) -> Self { |
| 199 | 203 | Action::Application(act) |
| @@ -277,6 +281,7 @@ pub enum RoomFetchStatus { | ||
| 277 | 281 | #[derive(Default)] |
| 278 | 282 | pub struct RoomInfo { |
| 279 | 283 | pub name: Option<String>, |
| 284 | pub tags: Option<Tags>, | |
| 280 | 285 | |
| 281 | 286 | pub keys: HashMap<OwnedEventId, MessageKey>, |
| 282 | 287 | pub messages: Messages, |
| @@ -437,6 +442,10 @@ impl ChatStore { | ||
| 437 | 442 | } |
| 438 | 443 | } |
| 439 | 444 | |
| 445 | pub fn get_joined_room(&self, room_id: &RoomId) -> Option<Joined> { | |
| 446 | self.worker.client.get_joined_room(room_id) | |
| 447 | } | |
| 448 | ||
| 440 | 449 | pub fn get_room_title(&self, room_id: &RoomId) -> String { |
| 441 | 450 | self.rooms |
| 442 | 451 | .get(room_id) |
src/commands.rs +255 −27
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::convert::TryFrom; |
| 2 | 2 | |
| 3 | use matrix_sdk::ruma::OwnedUserId; | |
| 3 | use matrix_sdk::ruma::{events::tag::TagName, OwnedUserId}; | |
| 4 | 4 | |
| 5 | 5 | use modalkit::{ |
| 6 | 6 | editing::base::OpenTarget, |
| @@ -17,14 +17,38 @@ use crate::base::{ | ||
| 17 | 17 | ProgramCommands, |
| 18 | 18 | ProgramContext, |
| 19 | 19 | RoomAction, |
| 20 | RoomField, | |
| 20 | 21 | SendAction, |
| 21 | SetRoomField, | |
| 22 | 22 | VerifyAction, |
| 23 | 23 | }; |
| 24 | 24 | |
| 25 | 25 | type ProgContext = CommandContext<ProgramContext>; |
| 26 | 26 | type ProgResult = CommandResult<ProgramCommand>; |
| 27 | 27 | |
| 28 | /// Convert strings the user types into a tag name. | |
| 29 | fn tag_name(name: String) -> Result<TagName, CommandError> { | |
| 30 | let tag = match name.as_str() { | |
| 31 | "fav" | "favorite" | "favourite" | "m.favourite" => TagName::Favorite, | |
| 32 | "low" | "lowpriority" | "low_priority" | "low-priority" | "m.lowpriority" => { | |
| 33 | TagName::LowPriority | |
| 34 | }, | |
| 35 | "servernotice" | "server_notice" | "server-notice" | "m.server_notice" => { | |
| 36 | TagName::ServerNotice | |
| 37 | }, | |
| 38 | _ => { | |
| 39 | if let Ok(tag) = name.parse() { | |
| 40 | TagName::User(tag) | |
| 41 | } else { | |
| 42 | let msg = format!("Invalid user tag name: {}", name); | |
| 43 | ||
| 44 | return Err(CommandError::Error(msg)); | |
| 45 | } | |
| 46 | }, | |
| 47 | }; | |
| 48 | ||
| 49 | Ok(tag) | |
| 50 | } | |
| 51 | ||
| 28 | 52 | fn iamb_invite(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 29 | 53 | let args = desc.arg.strings()?; |
| 30 | 54 | |
| @@ -225,22 +249,46 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 225 | 249 | return Ok(step); |
| 226 | 250 | } |
| 227 | 251 | |
| 228 | fn iamb_set(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 252 | fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 229 | 253 | let mut args = desc.arg.strings()?; |
| 230 | 254 | |
| 231 | if args.len() != 2 { | |
| 255 | if args.len() < 2 { | |
| 232 | 256 | return Result::Err(CommandError::InvalidArgument); |
| 233 | 257 | } |
| 234 | 258 | |
| 235 | 259 | let field = args.remove(0); |
| 236 | let value = args.remove(0); | |
| 260 | let action = args.remove(0); | |
| 237 | 261 | |
| 238 | let act: IambAction = match field.as_str() { | |
| 239 | "room.name" => RoomAction::Set(SetRoomField::Name(value)).into(), | |
| 240 | "room.topic" => RoomAction::Set(SetRoomField::Topic(value)).into(), | |
| 241 | _ => { | |
| 242 | return Result::Err(CommandError::InvalidArgument); | |
| 243 | }, | |
| 262 | if args.len() > 1 { | |
| 263 | return Result::Err(CommandError::InvalidArgument); | |
| 264 | } | |
| 265 | ||
| 266 | let act: IambAction = match (field.as_str(), action.as_str(), args.pop()) { | |
| 267 | // :room name set <room-name> | |
| 268 | ("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(), | |
| 269 | ("name", "set", None) => return Result::Err(CommandError::InvalidArgument), | |
| 270 | ||
| 271 | // :room name unset | |
| 272 | ("name", "unset", None) => RoomAction::Unset(RoomField::Name).into(), | |
| 273 | ("name", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), | |
| 274 | ||
| 275 | // :room topic set <topic> | |
| 276 | ("topic", "set", Some(s)) => RoomAction::Set(RoomField::Topic, s).into(), | |
| 277 | ("topic", "set", None) => return Result::Err(CommandError::InvalidArgument), | |
| 278 | ||
| 279 | // :room topic unset | |
| 280 | ("topic", "unset", None) => RoomAction::Unset(RoomField::Topic).into(), | |
| 281 | ("topic", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), | |
| 282 | ||
| 283 | // :room tag set <tag-name> | |
| 284 | ("tag", "set", Some(s)) => RoomAction::Set(RoomField::Tag(tag_name(s)?), "".into()).into(), | |
| 285 | ("tag", "set", None) => return Result::Err(CommandError::InvalidArgument), | |
| 286 | ||
| 287 | // :room tag unset <tag-name> | |
| 288 | ("tag", "unset", Some(s)) => RoomAction::Unset(RoomField::Tag(tag_name(s)?)).into(), | |
| 289 | ("tag", "unset", None) => return Result::Err(CommandError::InvalidArgument), | |
| 290 | ||
| 291 | _ => return Result::Err(CommandError::InvalidArgument), | |
| 244 | 292 | }; |
| 245 | 293 | |
| 246 | 294 | let step = CommandStep::Continue(act.into(), ctx.context.take()); |
| @@ -287,7 +335,7 @@ fn add_iamb_commands(cmds: &mut ProgramCommands) { | ||
| 287 | 335 | cmds.add_command(ProgramCommand { names: vec!["redact".into()], f: iamb_redact }); |
| 288 | 336 | cmds.add_command(ProgramCommand { names: vec!["reply".into()], f: iamb_reply }); |
| 289 | 337 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); |
| 290 | cmds.add_command(ProgramCommand { names: vec!["set".into()], f: iamb_set }); | |
| 338 | cmds.add_command(ProgramCommand { names: vec!["room".into()], f: iamb_room }); | |
| 291 | 339 | cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); |
| 292 | 340 | cmds.add_command(ProgramCommand { names: vec!["upload".into()], f: iamb_upload }); |
| 293 | 341 | cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); |
| @@ -376,47 +424,227 @@ mod tests { | ||
| 376 | 424 | } |
| 377 | 425 | |
| 378 | 426 | #[test] |
| 379 | fn test_cmd_set() { | |
| 427 | fn test_cmd_room_invalid() { | |
| 428 | let mut cmds = setup_commands(); | |
| 429 | let ctx = ProgramContext::default(); | |
| 430 | ||
| 431 | let res = cmds.input_cmd("room", ctx.clone()); | |
| 432 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 433 | ||
| 434 | let res = cmds.input_cmd("room foo", ctx.clone()); | |
| 435 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 436 | ||
| 437 | let res = cmds.input_cmd("room set topic", ctx.clone()); | |
| 438 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 439 | } | |
| 440 | ||
| 441 | #[test] | |
| 442 | fn test_cmd_room_topic_set() { | |
| 380 | 443 | let mut cmds = setup_commands(); |
| 381 | 444 | let ctx = ProgramContext::default(); |
| 382 | 445 | |
| 383 | 446 | let res = cmds |
| 384 | .input_cmd("set room.topic \"Lots of fun discussion!\"", ctx.clone()) | |
| 447 | .input_cmd("room topic set \"Lots of fun discussion!\"", ctx.clone()) | |
| 385 | 448 | .unwrap(); |
| 386 | let act = IambAction::Room(SetRoomField::Topic("Lots of fun discussion!".into()).into()); | |
| 449 | let act = RoomAction::Set(RoomField::Topic, "Lots of fun discussion!".into()); | |
| 387 | 450 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 388 | 451 | |
| 389 | 452 | let res = cmds |
| 390 | .input_cmd("set room.topic The\\ Discussion\\ Room", ctx.clone()) | |
| 453 | .input_cmd("room topic set The\\ Discussion\\ Room", ctx.clone()) | |
| 391 | 454 | .unwrap(); |
| 392 | let act = IambAction::Room(SetRoomField::Topic("The Discussion Room".into()).into()); | |
| 455 | let act = RoomAction::Set(RoomField::Topic, "The Discussion Room".into()); | |
| 393 | 456 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 394 | 457 | |
| 395 | let res = cmds.input_cmd("set room.topic Development", ctx.clone()).unwrap(); | |
| 396 | let act = IambAction::Room(SetRoomField::Topic("Development".into()).into()); | |
| 458 | let res = cmds.input_cmd("room topic set Development", ctx.clone()).unwrap(); | |
| 459 | let act = RoomAction::Set(RoomField::Topic, "Development".into()); | |
| 397 | 460 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 398 | 461 | |
| 399 | let res = cmds.input_cmd("set room.name Development", ctx.clone()).unwrap(); | |
| 400 | let act = IambAction::Room(SetRoomField::Name("Development".into()).into()); | |
| 462 | let res = cmds.input_cmd("room topic", ctx.clone()); | |
| 463 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 464 | ||
| 465 | let res = cmds.input_cmd("room topic set", ctx.clone()); | |
| 466 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 467 | ||
| 468 | let res = cmds.input_cmd("room topic set A B C", ctx.clone()); | |
| 469 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 470 | } | |
| 471 | ||
| 472 | #[test] | |
| 473 | fn test_cmd_room_name_invalid() { | |
| 474 | let mut cmds = setup_commands(); | |
| 475 | let ctx = ProgramContext::default(); | |
| 476 | ||
| 477 | let res = cmds.input_cmd("room name", ctx.clone()); | |
| 478 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 479 | ||
| 480 | let res = cmds.input_cmd("room name foo", ctx.clone()); | |
| 481 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 482 | } | |
| 483 | ||
| 484 | #[test] | |
| 485 | fn test_cmd_room_name_set() { | |
| 486 | let mut cmds = setup_commands(); | |
| 487 | let ctx = ProgramContext::default(); | |
| 488 | ||
| 489 | let res = cmds.input_cmd("room name set Development", ctx.clone()).unwrap(); | |
| 490 | let act = RoomAction::Set(RoomField::Name, "Development".into()); | |
| 401 | 491 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 402 | 492 | |
| 403 | 493 | let res = cmds |
| 404 | .input_cmd("set room.name \"Application Development\"", ctx.clone()) | |
| 494 | .input_cmd("room name set \"Application Development\"", ctx.clone()) | |
| 405 | 495 | .unwrap(); |
| 406 | let act = IambAction::Room(SetRoomField::Name("Application Development".into()).into()); | |
| 496 | let act = RoomAction::Set(RoomField::Name, "Application Development".into()); | |
| 407 | 497 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 408 | 498 | |
| 409 | let res = cmds.input_cmd("set", ctx.clone()); | |
| 499 | let res = cmds.input_cmd("room name set", ctx.clone()); | |
| 410 | 500 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 501 | } | |
| 411 | 502 | |
| 412 | let res = cmds.input_cmd("set room.name", ctx.clone()); | |
| 503 | #[test] | |
| 504 | fn test_cmd_room_name_unset() { | |
| 505 | let mut cmds = setup_commands(); | |
| 506 | let ctx = ProgramContext::default(); | |
| 507 | ||
| 508 | let res = cmds.input_cmd("room name unset", ctx.clone()).unwrap(); | |
| 509 | let act = RoomAction::Unset(RoomField::Name); | |
| 510 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 511 | ||
| 512 | let res = cmds.input_cmd("room name unset foo", ctx.clone()); | |
| 413 | 513 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 514 | } | |
| 414 | 515 | |
| 415 | let res = cmds.input_cmd("set room.topic", ctx.clone()); | |
| 516 | #[test] | |
| 517 | fn test_cmd_room_tag_set() { | |
| 518 | let mut cmds = setup_commands(); | |
| 519 | let ctx = ProgramContext::default(); | |
| 520 | ||
| 521 | let res = cmds.input_cmd("room tag set favourite", ctx.clone()).unwrap(); | |
| 522 | let act = RoomAction::Set(RoomField::Tag(TagName::Favorite), "".into()); | |
| 523 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 524 | ||
| 525 | let res = cmds.input_cmd("room tag set favorite", ctx.clone()).unwrap(); | |
| 526 | let act = RoomAction::Set(RoomField::Tag(TagName::Favorite), "".into()); | |
| 527 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 528 | ||
| 529 | let res = cmds.input_cmd("room tag set fav", ctx.clone()).unwrap(); | |
| 530 | let act = RoomAction::Set(RoomField::Tag(TagName::Favorite), "".into()); | |
| 531 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 532 | ||
| 533 | let res = cmds.input_cmd("room tag set low_priority", ctx.clone()).unwrap(); | |
| 534 | let act = RoomAction::Set(RoomField::Tag(TagName::LowPriority), "".into()); | |
| 535 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 536 | ||
| 537 | let res = cmds.input_cmd("room tag set low-priority", ctx.clone()).unwrap(); | |
| 538 | let act = RoomAction::Set(RoomField::Tag(TagName::LowPriority), "".into()); | |
| 539 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 540 | ||
| 541 | let res = cmds.input_cmd("room tag set low", ctx.clone()).unwrap(); | |
| 542 | let act = RoomAction::Set(RoomField::Tag(TagName::LowPriority), "".into()); | |
| 543 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 544 | ||
| 545 | let res = cmds.input_cmd("room tag set servernotice", ctx.clone()).unwrap(); | |
| 546 | let act = RoomAction::Set(RoomField::Tag(TagName::ServerNotice), "".into()); | |
| 547 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 548 | ||
| 549 | let res = cmds.input_cmd("room tag set server_notice", ctx.clone()).unwrap(); | |
| 550 | let act = RoomAction::Set(RoomField::Tag(TagName::ServerNotice), "".into()); | |
| 551 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 552 | ||
| 553 | let res = cmds.input_cmd("room tag set server_notice", ctx.clone()).unwrap(); | |
| 554 | let act = RoomAction::Set(RoomField::Tag(TagName::ServerNotice), "".into()); | |
| 555 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 556 | ||
| 557 | let res = cmds.input_cmd("room tag set u.custom-tag", ctx.clone()).unwrap(); | |
| 558 | let act = RoomAction::Set( | |
| 559 | RoomField::Tag(TagName::User("u.custom-tag".parse().unwrap())), | |
| 560 | "".into(), | |
| 561 | ); | |
| 562 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 563 | ||
| 564 | let res = cmds.input_cmd("room tag set u.irc", ctx.clone()).unwrap(); | |
| 565 | let act = | |
| 566 | RoomAction::Set(RoomField::Tag(TagName::User("u.irc".parse().unwrap())), "".into()); | |
| 567 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 568 | ||
| 569 | let res = cmds.input_cmd("room tag", ctx.clone()); | |
| 570 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 571 | ||
| 572 | let res = cmds.input_cmd("room tag set", ctx.clone()); | |
| 573 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 574 | ||
| 575 | let res = cmds.input_cmd("room tag set unknown", ctx.clone()); | |
| 576 | assert_eq!(res, Err(CommandError::Error("Invalid user tag name: unknown".into()))); | |
| 577 | ||
| 578 | let res = cmds.input_cmd("room tag set needs-leading-u-dot", ctx.clone()); | |
| 579 | assert_eq!( | |
| 580 | res, | |
| 581 | Err(CommandError::Error("Invalid user tag name: needs-leading-u-dot".into())) | |
| 582 | ); | |
| 583 | } | |
| 584 | ||
| 585 | #[test] | |
| 586 | fn test_cmd_room_tag_unset() { | |
| 587 | let mut cmds = setup_commands(); | |
| 588 | let ctx = ProgramContext::default(); | |
| 589 | ||
| 590 | let res = cmds.input_cmd("room tag unset favourite", ctx.clone()).unwrap(); | |
| 591 | let act = RoomAction::Unset(RoomField::Tag(TagName::Favorite)); | |
| 592 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 593 | ||
| 594 | let res = cmds.input_cmd("room tag unset favorite", ctx.clone()).unwrap(); | |
| 595 | let act = RoomAction::Unset(RoomField::Tag(TagName::Favorite)); | |
| 596 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 597 | ||
| 598 | let res = cmds.input_cmd("room tag unset fav", ctx.clone()).unwrap(); | |
| 599 | let act = RoomAction::Unset(RoomField::Tag(TagName::Favorite)); | |
| 600 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 601 | ||
| 602 | let res = cmds.input_cmd("room tag unset low_priority", ctx.clone()).unwrap(); | |
| 603 | let act = RoomAction::Unset(RoomField::Tag(TagName::LowPriority)); | |
| 604 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 605 | ||
| 606 | let res = cmds.input_cmd("room tag unset low-priority", ctx.clone()).unwrap(); | |
| 607 | let act = RoomAction::Unset(RoomField::Tag(TagName::LowPriority)); | |
| 608 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 609 | ||
| 610 | let res = cmds.input_cmd("room tag unset low", ctx.clone()).unwrap(); | |
| 611 | let act = RoomAction::Unset(RoomField::Tag(TagName::LowPriority)); | |
| 612 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 613 | ||
| 614 | let res = cmds.input_cmd("room tag unset servernotice", ctx.clone()).unwrap(); | |
| 615 | let act = RoomAction::Unset(RoomField::Tag(TagName::ServerNotice)); | |
| 616 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 617 | ||
| 618 | let res = cmds.input_cmd("room tag unset server_notice", ctx.clone()).unwrap(); | |
| 619 | let act = RoomAction::Unset(RoomField::Tag(TagName::ServerNotice)); | |
| 620 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 621 | ||
| 622 | let res = cmds.input_cmd("room tag unset server_notice", ctx.clone()).unwrap(); | |
| 623 | let act = RoomAction::Unset(RoomField::Tag(TagName::ServerNotice)); | |
| 624 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 625 | ||
| 626 | let res = cmds.input_cmd("room tag unset u.custom-tag", ctx.clone()).unwrap(); | |
| 627 | let act = RoomAction::Unset(RoomField::Tag(TagName::User("u.custom-tag".parse().unwrap()))); | |
| 628 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 629 | ||
| 630 | let res = cmds.input_cmd("room tag unset u.irc", ctx.clone()).unwrap(); | |
| 631 | let act = RoomAction::Unset(RoomField::Tag(TagName::User("u.irc".parse().unwrap()))); | |
| 632 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 633 | ||
| 634 | let res = cmds.input_cmd("room tag", ctx.clone()); | |
| 416 | 635 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 417 | 636 | |
| 418 | let res = cmds.input_cmd("set room.topic A B C", ctx.clone()); | |
| 637 | let res = cmds.input_cmd("room tag set", ctx.clone()); | |
| 419 | 638 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 639 | ||
| 640 | let res = cmds.input_cmd("room tag unset unknown", ctx.clone()); | |
| 641 | assert_eq!(res, Err(CommandError::Error("Invalid user tag name: unknown".into()))); | |
| 642 | ||
| 643 | let res = cmds.input_cmd("room tag unset needs-leading-u-dot", ctx.clone()); | |
| 644 | assert_eq!( | |
| 645 | res, | |
| 646 | Err(CommandError::Error("Invalid user tag name: needs-leading-u-dot".into())) | |
| 647 | ); | |
| 420 | 648 | } |
| 421 | 649 | |
| 422 | 650 | #[test] |
src/tests.rs +1
| @@ -141,6 +141,7 @@ pub fn mock_room() -> RoomInfo { | ||
| 141 | 141 | |
| 142 | 142 | keys: mock_keys(), |
| 143 | 143 | messages: mock_messages(), |
| 144 | tags: None, | |
| 144 | 145 | |
| 145 | 146 | fetch_id: RoomFetchStatus::NotStarted, |
| 146 | 147 | fetch_last: None, |
src/windows/mod.rs +78 −11
| @@ -4,7 +4,12 @@ use std::collections::hash_map::Entry; | ||
| 4 | 4 | use matrix_sdk::{ |
| 5 | 5 | encryption::verification::{format_emojis, SasVerification}, |
| 6 | 6 | room::{Room as MatrixRoom, RoomMember}, |
| 7 | ruma::{events::room::member::MembershipState, OwnedRoomId, RoomId}, | |
| 7 | ruma::{ | |
| 8 | events::room::member::MembershipState, | |
| 9 | events::tag::{TagName, Tags}, | |
| 10 | OwnedRoomId, | |
| 11 | RoomId, | |
| 12 | }, | |
| 8 | 13 | DisplayName, |
| 9 | 14 | }; |
| 10 | 15 | |
| @@ -346,7 +351,7 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 346 | 351 | let joined = store.application.worker.active_rooms(); |
| 347 | 352 | let mut items = joined |
| 348 | 353 | .into_iter() |
| 349 | .map(|(room, name)| RoomItem::new(room, name, store)) | |
| 354 | .map(|(room, name, tags)| RoomItem::new(room, name, tags, store)) | |
| 350 | 355 | .collect::<Vec<_>>(); |
| 351 | 356 | items.sort(); |
| 352 | 357 | |
| @@ -471,8 +476,8 @@ impl Window<IambInfo> for IambWindow { | ||
| 471 | 476 | fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> { |
| 472 | 477 | match id { |
| 473 | 478 | IambId::Room(room_id) => { |
| 474 | let (room, name) = store.application.worker.get_room(room_id)?; | |
| 475 | let room = RoomState::new(room, name, store); | |
| 479 | let (room, name, tags) = store.application.worker.get_room(room_id)?; | |
| 480 | let room = RoomState::new(room, name, tags, store); | |
| 476 | 481 | |
| 477 | 482 | return Ok(room.into()); |
| 478 | 483 | }, |
| @@ -519,8 +524,8 @@ impl Window<IambInfo> for IambWindow { | ||
| 519 | 524 | let room_id = worker.join_room(v.key().to_string())?; |
| 520 | 525 | v.insert(room_id.clone()); |
| 521 | 526 | |
| 522 | let (room, name) = store.application.worker.get_room(room_id)?; | |
| 523 | let room = RoomState::new(room, name, store); | |
| 527 | let (room, name, tags) = store.application.worker.get_room(room_id)?; | |
| 528 | let room = RoomState::new(room, name, tags, store); | |
| 524 | 529 | |
| 525 | 530 | Ok(room.into()) |
| 526 | 531 | }, |
| @@ -547,16 +552,24 @@ impl Window<IambInfo> for IambWindow { | ||
| 547 | 552 | #[derive(Clone)] |
| 548 | 553 | pub struct RoomItem { |
| 549 | 554 | room: MatrixRoom, |
| 555 | tags: Option<Tags>, | |
| 550 | 556 | name: String, |
| 551 | 557 | } |
| 552 | 558 | |
| 553 | 559 | impl RoomItem { |
| 554 | fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | |
| 560 | fn new( | |
| 561 | room: MatrixRoom, | |
| 562 | name: DisplayName, | |
| 563 | tags: Option<Tags>, | |
| 564 | store: &mut ProgramStore, | |
| 565 | ) -> Self { | |
| 555 | 566 | let name = name.to_string(); |
| 556 | 567 | |
| 557 | store.application.set_room_name(room.room_id(), name.as_str()); | |
| 568 | let info = store.application.get_room_info(room.room_id().to_owned()); | |
| 569 | info.name = name.clone().into(); | |
| 570 | info.tags = tags.clone(); | |
| 558 | 571 | |
| 559 | RoomItem { room, name } | |
| 572 | RoomItem { room, tags, name } | |
| 560 | 573 | } |
| 561 | 574 | } |
| 562 | 575 | |
| @@ -570,7 +583,29 @@ impl Eq for RoomItem {} | ||
| 570 | 583 | |
| 571 | 584 | impl Ord for RoomItem { |
| 572 | 585 | fn cmp(&self, other: &Self) -> Ordering { |
| 573 | room_cmp(&self.room, &other.room) | |
| 586 | let (fava, lowa) = self | |
| 587 | .tags | |
| 588 | .as_ref() | |
| 589 | .map(|tags| { | |
| 590 | (tags.contains_key(&TagName::Favorite), tags.contains_key(&TagName::LowPriority)) | |
| 591 | }) | |
| 592 | .unwrap_or((false, false)); | |
| 593 | ||
| 594 | let (favb, lowb) = other | |
| 595 | .tags | |
| 596 | .as_ref() | |
| 597 | .map(|tags| { | |
| 598 | (tags.contains_key(&TagName::Favorite), tags.contains_key(&TagName::LowPriority)) | |
| 599 | }) | |
| 600 | .unwrap_or((false, false)); | |
| 601 | ||
| 602 | // If self has Favorite and other doesn't, it should sort earlier in room list. | |
| 603 | let cmpf = favb.cmp(&fava); | |
| 604 | ||
| 605 | // If self has LowPriority and other doesn't, it should sort later in room list. | |
| 606 | let cmpl = lowa.cmp(&lowb); | |
| 607 | ||
| 608 | cmpl.then(cmpf).then_with(|| room_cmp(&self.room, &other.room)) | |
| 574 | 609 | } |
| 575 | 610 | } |
| 576 | 611 | |
| @@ -588,7 +623,39 @@ impl ToString for RoomItem { | ||
| 588 | 623 | |
| 589 | 624 | impl ListItem<IambInfo> for RoomItem { |
| 590 | 625 | fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { |
| 591 | selected_text(self.name.as_str(), selected) | |
| 626 | if let Some(tags) = &self.tags { | |
| 627 | let style = selected_style(selected); | |
| 628 | let mut spans = vec![Span::styled(self.name.as_str(), style)]; | |
| 629 | ||
| 630 | if tags.is_empty() { | |
| 631 | return Text::from(Spans(spans)); | |
| 632 | } | |
| 633 | ||
| 634 | spans.push(Span::styled(" (", style)); | |
| 635 | ||
| 636 | for (i, tag) in tags.keys().enumerate() { | |
| 637 | if i > 0 { | |
| 638 | spans.push(Span::styled(", ", style)); | |
| 639 | } | |
| 640 | ||
| 641 | match tag { | |
| 642 | TagName::Favorite => spans.push(Span::styled("Favorite", style)), | |
| 643 | TagName::LowPriority => spans.push(Span::styled("Low Priority", style)), | |
| 644 | TagName::ServerNotice => spans.push(Span::styled("Server Notice", style)), | |
| 645 | TagName::User(tag) => { | |
| 646 | spans.push(Span::styled("User Tag: ", style)); | |
| 647 | spans.push(Span::styled(tag.as_ref(), style)); | |
| 648 | }, | |
| 649 | tag => spans.push(Span::styled(format!("{:?}", tag), style)), | |
| 650 | } | |
| 651 | } | |
| 652 | ||
| 653 | spans.push(Span::styled(")", style)); | |
| 654 | ||
| 655 | Text::from(Spans(spans)) | |
| 656 | } else { | |
| 657 | selected_text(self.name.as_str(), selected) | |
| 658 | } | |
| 592 | 659 | } |
| 593 | 660 | |
| 594 | 661 | fn get_word(&self) -> Option<String> { |
src/windows/room/mod.rs +60 −4
| @@ -1,6 +1,12 @@ | ||
| 1 | 1 | use matrix_sdk::{ |
| 2 | 2 | room::{Invited, Room as MatrixRoom}, |
| 3 | ruma::RoomId, | |
| 3 | ruma::{ | |
| 4 | events::{ | |
| 5 | room::{name::RoomNameEventContent, topic::RoomTopicEventContent}, | |
| 6 | tag::{TagInfo, Tags}, | |
| 7 | }, | |
| 8 | RoomId, | |
| 9 | }, | |
| 4 | 10 | DisplayName, |
| 5 | 11 | }; |
| 6 | 12 | |
| @@ -23,6 +29,7 @@ use modalkit::{ | ||
| 23 | 29 | PromptAction, |
| 24 | 30 | Promptable, |
| 25 | 31 | Scrollable, |
| 32 | UIError, | |
| 26 | 33 | }, |
| 27 | 34 | editing::base::{ |
| 28 | 35 | Axis, |
| @@ -48,6 +55,7 @@ use crate::base::{ | ||
| 48 | 55 | ProgramContext, |
| 49 | 56 | ProgramStore, |
| 50 | 57 | RoomAction, |
| 58 | RoomField, | |
| 51 | 59 | SendAction, |
| 52 | 60 | }; |
| 53 | 61 | |
| @@ -85,10 +93,16 @@ impl From<SpaceState> for RoomState { | ||
| 85 | 93 | } |
| 86 | 94 | |
| 87 | 95 | impl RoomState { |
| 88 | pub fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { | |
| 96 | pub fn new( | |
| 97 | room: MatrixRoom, | |
| 98 | name: DisplayName, | |
| 99 | tags: Option<Tags>, | |
| 100 | store: &mut ProgramStore, | |
| 101 | ) -> Self { | |
| 89 | 102 | let room_id = room.room_id().to_owned(); |
| 90 | 103 | let info = store.application.get_room_info(room_id); |
| 91 | 104 | info.name = name.to_string().into(); |
| 105 | info.tags = tags; | |
| 92 | 106 | |
| 93 | 107 | if room.is_space() { |
| 94 | 108 | SpaceState::new(room).into() |
| @@ -207,8 +221,50 @@ impl RoomState { | ||
| 207 | 221 | |
| 208 | 222 | Ok(vec![(act, cmd.context.take())]) |
| 209 | 223 | }, |
| 210 | RoomAction::Set(field) => { | |
| 211 | store.application.worker.set_room(self.id().to_owned(), field)?; | |
| 224 | RoomAction::Set(field, value) => { | |
| 225 | let room = store | |
| 226 | .application | |
| 227 | .get_joined_room(self.id()) | |
| 228 | .ok_or(UIError::Application(IambError::NotJoined))?; | |
| 229 | ||
| 230 | match field { | |
| 231 | RoomField::Name => { | |
| 232 | let ev = RoomNameEventContent::new(value.into()); | |
| 233 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 234 | }, | |
| 235 | RoomField::Tag(tag) => { | |
| 236 | let mut info = TagInfo::new(); | |
| 237 | info.order = Some(1.0); | |
| 238 | ||
| 239 | let _ = room.set_tag(tag, info).await.map_err(IambError::from)?; | |
| 240 | }, | |
| 241 | RoomField::Topic => { | |
| 242 | let ev = RoomTopicEventContent::new(value); | |
| 243 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 244 | }, | |
| 245 | } | |
| 246 | ||
| 247 | Ok(vec![]) | |
| 248 | }, | |
| 249 | RoomAction::Unset(field) => { | |
| 250 | let room = store | |
| 251 | .application | |
| 252 | .get_joined_room(self.id()) | |
| 253 | .ok_or(UIError::Application(IambError::NotJoined))?; | |
| 254 | ||
| 255 | match field { | |
| 256 | RoomField::Name => { | |
| 257 | let ev = RoomNameEventContent::new(None); | |
| 258 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 259 | }, | |
| 260 | RoomField::Tag(tag) => { | |
| 261 | let _ = room.remove_tag(tag).await.map_err(IambError::from)?; | |
| 262 | }, | |
| 263 | RoomField::Topic => { | |
| 264 | let ev = RoomTopicEventContent::new("".into()); | |
| 265 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 266 | }, | |
| 267 | } | |
| 212 | 268 | |
| 213 | 269 | Ok(vec![]) |
| 214 | 270 | }, |
src/windows/room/space.rs +2 −2
| @@ -104,10 +104,10 @@ impl<'a> StatefulWidget for Space<'a> { | ||
| 104 | 104 | let items = members |
| 105 | 105 | .into_iter() |
| 106 | 106 | .filter_map(|id| { |
| 107 | let (room, name) = self.store.application.worker.get_room(id.clone()).ok()?; | |
| 107 | let (room, name, tags) = self.store.application.worker.get_room(id.clone()).ok()?; | |
| 108 | 108 | |
| 109 | 109 | if id != state.room_id { |
| 110 | Some(RoomItem::new(room, name, self.store)) | |
| 110 | Some(RoomItem::new(room, name, tags, self.store)) | |
| 111 | 111 | } else { |
| 112 | 112 | None |
| 113 | 113 | } |
src/worker.rs +27 −54
| @@ -36,8 +36,8 @@ use matrix_sdk::{ | ||
| 36 | 36 | message::{MessageType, RoomMessageEventContent}, |
| 37 | 37 | name::RoomNameEventContent, |
| 38 | 38 | redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, |
| 39 | topic::RoomTopicEventContent, | |
| 40 | 39 | }, |
| 40 | tag::Tags, | |
| 41 | 41 | typing::SyncTypingEvent, |
| 42 | 42 | AnyMessageLikeEvent, |
| 43 | 43 | AnyTimelineEvent, |
| @@ -57,7 +57,7 @@ use matrix_sdk::{ | ||
| 57 | 57 | use modalkit::editing::action::{EditInfo, InfoMessage, UIError}; |
| 58 | 58 | |
| 59 | 59 | use crate::{ |
| 60 | base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction}, | |
| 60 | base::{AsyncProgramStore, IambError, IambResult, VerifyAction}, | |
| 61 | 61 | message::MessageFetchResult, |
| 62 | 62 | ApplicationSettings, |
| 63 | 63 | }; |
| @@ -100,18 +100,17 @@ fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) { | ||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | pub enum WorkerTask { |
| 103 | ActiveRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), | |
| 103 | ActiveRooms(ClientReply<Vec<(MatrixRoom, DisplayName, Option<Tags>)>>), | |
| 104 | 104 | DirectMessages(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 105 | 105 | Init(AsyncProgramStore, ClientReply<()>), |
| 106 | 106 | LoadOlder(OwnedRoomId, Option<String>, u32, ClientReply<MessageFetchResult>), |
| 107 | 107 | Login(LoginStyle, ClientReply<IambResult<EditInfo>>), |
| 108 | 108 | GetInviter(Invited, ClientReply<IambResult<Option<RoomMember>>>), |
| 109 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), | |
| 109 | GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName, Option<Tags>)>>), | |
| 110 | 110 | JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), |
| 111 | 111 | Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>), |
| 112 | 112 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), |
| 113 | 113 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 114 | SetRoom(OwnedRoomId, SetRoomField, ClientReply<IambResult<()>>), | |
| 115 | 114 | TypingNotice(OwnedRoomId), |
| 116 | 115 | Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>), |
| 117 | 116 | VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>), |
| @@ -178,13 +177,6 @@ impl Debug for WorkerTask { | ||
| 178 | 177 | WorkerTask::Spaces(_) => { |
| 179 | 178 | f.debug_tuple("WorkerTask::Spaces").field(&format_args!("_")).finish() |
| 180 | 179 | }, |
| 181 | WorkerTask::SetRoom(room_id, field, _) => { | |
| 182 | f.debug_tuple("WorkerTask::SetRoom") | |
| 183 | .field(room_id) | |
| 184 | .field(field) | |
| 185 | .field(&format_args!("_")) | |
| 186 | .finish() | |
| 187 | }, | |
| 188 | 180 | WorkerTask::TypingNotice(room_id) => { |
| 189 | 181 | f.debug_tuple("WorkerTask::TypingNotice").field(room_id).finish() |
| 190 | 182 | }, |
| @@ -259,7 +251,10 @@ impl Requester { | ||
| 259 | 251 | return response.recv(); |
| 260 | 252 | } |
| 261 | 253 | |
| 262 | pub fn get_room(&self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | |
| 254 | pub fn get_room( | |
| 255 | &self, | |
| 256 | room_id: OwnedRoomId, | |
| 257 | ) -> IambResult<(MatrixRoom, DisplayName, Option<Tags>)> { | |
| 263 | 258 | let (reply, response) = oneshot(); |
| 264 | 259 | |
| 265 | 260 | self.tx.send(WorkerTask::GetRoom(room_id, reply)).unwrap(); |
| @@ -275,7 +270,7 @@ impl Requester { | ||
| 275 | 270 | return response.recv(); |
| 276 | 271 | } |
| 277 | 272 | |
| 278 | pub fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { | |
| 273 | pub fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName, Option<Tags>)> { | |
| 279 | 274 | let (reply, response) = oneshot(); |
| 280 | 275 | |
| 281 | 276 | self.tx.send(WorkerTask::ActiveRooms(reply)).unwrap(); |
| @@ -299,14 +294,6 @@ impl Requester { | ||
| 299 | 294 | return response.recv(); |
| 300 | 295 | } |
| 301 | 296 | |
| 302 | pub fn set_room(&self, room_id: OwnedRoomId, ev: SetRoomField) -> IambResult<()> { | |
| 303 | let (reply, response) = oneshot(); | |
| 304 | ||
| 305 | self.tx.send(WorkerTask::SetRoom(room_id, ev, reply)).unwrap(); | |
| 306 | ||
| 307 | return response.recv(); | |
| 308 | } | |
| 309 | ||
| 310 | 297 | pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 311 | 298 | let (reply, response) = oneshot(); |
| 312 | 299 | |
| @@ -444,10 +431,6 @@ impl ClientWorker { | ||
| 444 | 431 | assert!(self.initialized); |
| 445 | 432 | reply.send(self.members(room_id).await); |
| 446 | 433 | }, |
| 447 | WorkerTask::SetRoom(room_id, field, reply) => { | |
| 448 | assert!(self.initialized); | |
| 449 | reply.send(self.set_room(room_id, field).await); | |
| 450 | }, | |
| 451 | 434 | WorkerTask::SpaceMembers(space, reply) => { |
| 452 | 435 | assert!(self.initialized); |
| 453 | 436 | reply.send(self.space_members(space).await); |
| @@ -721,10 +704,15 @@ impl ClientWorker { | ||
| 721 | 704 | Ok(Some(InfoMessage::from("Successfully logged in!"))) |
| 722 | 705 | } |
| 723 | 706 | |
| 724 | async fn direct_message(&mut self, user: OwnedUserId) -> IambResult<(MatrixRoom, DisplayName)> { | |
| 707 | async fn direct_message( | |
| 708 | &mut self, | |
| 709 | user: OwnedUserId, | |
| 710 | ) -> IambResult<(MatrixRoom, DisplayName, Option<Tags>)> { | |
| 725 | 711 | for (room, name) in self.direct_messages().await { |
| 726 | 712 | if room.get_member(user.as_ref()).await.map_err(IambError::from)?.is_some() { |
| 727 | return Ok((room, name)); | |
| 713 | let tags = room.tags().await.map_err(IambError::from)?; | |
| 714 | ||
| 715 | return Ok((room, name, tags)); | |
| 728 | 716 | } |
| 729 | 717 | } |
| 730 | 718 | |
| @@ -758,11 +746,15 @@ impl ClientWorker { | ||
| 758 | 746 | Ok(details.inviter) |
| 759 | 747 | } |
| 760 | 748 | |
| 761 | async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<(MatrixRoom, DisplayName)> { | |
| 749 | async fn get_room( | |
| 750 | &mut self, | |
| 751 | room_id: OwnedRoomId, | |
| 752 | ) -> IambResult<(MatrixRoom, DisplayName, Option<Tags>)> { | |
| 762 | 753 | if let Some(room) = self.client.get_room(&room_id) { |
| 763 | 754 | let name = room.display_name().await.map_err(IambError::from)?; |
| 755 | let tags = room.tags().await.map_err(IambError::from)?; | |
| 764 | 756 | |
| 765 | Ok((room, name)) | |
| 757 | Ok((room, name, tags)) | |
| 766 | 758 | } else { |
| 767 | 759 | Err(IambError::UnknownRoom(room_id).into()) |
| 768 | 760 | } |
| @@ -817,7 +809,7 @@ impl ClientWorker { | ||
| 817 | 809 | return rooms; |
| 818 | 810 | } |
| 819 | 811 | |
| 820 | async fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName)> { | |
| 812 | async fn active_rooms(&self) -> Vec<(MatrixRoom, DisplayName, Option<Tags>)> { | |
| 821 | 813 | let mut rooms = vec![]; |
| 822 | 814 | |
| 823 | 815 | for room in self.client.invited_rooms().into_iter() { |
| @@ -826,8 +818,9 @@ impl ClientWorker { | ||
| 826 | 818 | } |
| 827 | 819 | |
| 828 | 820 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); |
| 821 | let tags = room.tags().await.unwrap_or_default(); | |
| 829 | 822 | |
| 830 | rooms.push((room.into(), name)); | |
| 823 | rooms.push((room.into(), name, tags)); | |
| 831 | 824 | } |
| 832 | 825 | |
| 833 | 826 | for room in self.client.joined_rooms().into_iter() { |
| @@ -836,8 +829,9 @@ impl ClientWorker { | ||
| 836 | 829 | } |
| 837 | 830 | |
| 838 | 831 | let name = room.display_name().await.unwrap_or(DisplayName::Empty); |
| 832 | let tags = room.tags().await.unwrap_or_default(); | |
| 839 | 833 | |
| 840 | rooms.push((room.into(), name)); | |
| 834 | rooms.push((room.into(), name, tags)); | |
| 841 | 835 | } |
| 842 | 836 | |
| 843 | 837 | return rooms; |
| @@ -886,27 +880,6 @@ impl ClientWorker { | ||
| 886 | 880 | } |
| 887 | 881 | } |
| 888 | 882 | |
| 889 | async fn set_room(&mut self, room_id: OwnedRoomId, field: SetRoomField) -> IambResult<()> { | |
| 890 | let room = if let Some(r) = self.client.get_joined_room(&room_id) { | |
| 891 | r | |
| 892 | } else { | |
| 893 | return Err(IambError::UnknownRoom(room_id).into()); | |
| 894 | }; | |
| 895 | ||
| 896 | match field { | |
| 897 | SetRoomField::Name(name) => { | |
| 898 | let ev = RoomNameEventContent::new(name.into()); | |
| 899 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 900 | }, | |
| 901 | SetRoomField::Topic(topic) => { | |
| 902 | let ev = RoomTopicEventContent::new(topic); | |
| 903 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 904 | }, | |
| 905 | } | |
| 906 | ||
| 907 | Ok(()) | |
| 908 | } | |
| 909 | ||
| 910 | 883 | async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { |
| 911 | 884 | let mut req = SpaceHierarchyRequest::new(&space); |
| 912 | 885 | req.limit = Some(1000u32.into()); |