Commit 0ed1d53946

0ed1d53946e421cd8037e0bda92606fa5ea00399

parent: e3be8c16cb

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-03-02 02:46 UTC

Support completing commands, usernames, and room names (#44)

Layout: unified · split

Cargo.lock +30 −3
@@ -860,6 +860,12 @@ dependencies = [
860 "cfg-if", 860 "cfg-if",
861] 861]
862 862
863[[package]]
864name = "endian-type"
865version = "0.1.2"
866source = "registry+https://github.com/rust-lang/crates.io-index"
867checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
868
863[[package]] 869[[package]]
864name = "errno" 870name = "errno"
865version = "0.2.8" 871version = "0.2.8"
@@ -1302,7 +1308,7 @@ dependencies = [
1302 1308
1303[[package]] 1309[[package]]
1304name = "iamb" 1310name = "iamb"
1305version = "0.0.4" 1311version = "0.0.5"
1306dependencies = [ 1312dependencies = [
1307 "bitflags", 1313 "bitflags",
1308 "chrono", 1314 "chrono",
@@ -1876,9 +1882,9 @@ dependencies = [
1876 1882
1877[[package]] 1883[[package]]
1878name = "modalkit" 1884name = "modalkit"
1879version = "0.0.11" 1885version = "0.0.12"
1880source = "registry+https://github.com/rust-lang/crates.io-index" 1886source = "registry+https://github.com/rust-lang/crates.io-index"
1881checksum = "bd7bd7d02d65842dab4cea53016cf29c16cde197131dd6d9eea95662deb77778" 1887checksum = "9a4e5226a5d33a7bdf5b4fc067baa211c94f21aa6667af5eec8b357a8af5e4ba"
1882dependencies = [ 1888dependencies = [
1883 "anymap2", 1889 "anymap2",
1884 "arboard", 1890 "arboard",
@@ -1888,10 +1894,12 @@ dependencies = [
1888 "intervaltree", 1894 "intervaltree",
1889 "libc", 1895 "libc",
1890 "nom", 1896 "nom",
1897 "radix_trie",
1891 "regex", 1898 "regex",
1892 "ropey", 1899 "ropey",
1893 "thiserror", 1900 "thiserror",
1894 "tui", 1901 "tui",
1902 "unicode-segmentation",
1895] 1903]
1896 1904
1897[[package]] 1905[[package]]
@@ -1900,6 +1908,15 @@ version = "1.0.4"
1900source = "registry+https://github.com/rust-lang/crates.io-index" 1908source = "registry+https://github.com/rust-lang/crates.io-index"
1901checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" 1909checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
1902 1910
1911[[package]]
1912name = "nibble_vec"
1913version = "0.1.0"
1914source = "registry+https://github.com/rust-lang/crates.io-index"
1915checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43"
1916dependencies = [
1917 "smallvec",
1918]
1919
1903[[package]] 1920[[package]]
1904name = "nix" 1921name = "nix"
1905version = "0.24.3" 1922version = "0.24.3"
@@ -2344,6 +2361,16 @@ dependencies = [
2344 "proc-macro2", 2361 "proc-macro2",
2345] 2362]
2346 2363
2364[[package]]
2365name = "radix_trie"
2366version = "0.2.1"
2367source = "registry+https://github.com/rust-lang/crates.io-index"
2368checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd"
2369dependencies = [
2370 "endian-type",
2371 "nibble_vec",
2372]
2373
2347[[package]] 2374[[package]]
2348name = "rand" 2375name = "rand"
2349version = "0.7.3" 2376version = "0.7.3"
Cargo.toml +1 −1
@@ -39,7 +39,7 @@ unicode-width = "0.1.10"
39url = {version = "^2.2.2", features = ["serde"]} 39url = {version = "^2.2.2", features = ["serde"]}
40 40
41[dependencies.modalkit] 41[dependencies.modalkit]
42version = "0.0.11" 42version = "0.0.12"
43 43
44[dependencies.matrix-sdk] 44[dependencies.matrix-sdk]
45version = "0.6" 45version = "0.6"
src/base.rs +219 −9
@@ -1,8 +1,11 @@
1use std::borrow::Cow;
1use std::collections::{HashMap, HashSet}; 2use std::collections::{HashMap, HashSet};
2use std::hash::Hash; 3use std::hash::Hash;
4use std::str::FromStr;
3use std::sync::Arc; 5use std::sync::Arc;
4use std::time::{Duration, Instant}; 6use std::time::{Duration, Instant};
5 7
8use emojis::Emoji;
6use tokio::sync::Mutex as AsyncMutex; 9use tokio::sync::Mutex as AsyncMutex;
7use tracing::warn; 10use tracing::warn;
8 11
@@ -23,6 +26,7 @@ use matrix_sdk::{
23 AnyMessageLikeEvent, 26 AnyMessageLikeEvent,
24 MessageLikeEvent, 27 MessageLikeEvent,
25 }, 28 },
29 presence::PresenceState,
26 EventId, 30 EventId,
27 OwnedEventId, 31 OwnedEventId,
28 OwnedRoomId, 32 OwnedRoomId,
@@ -42,11 +46,15 @@ use modalkit::{
42 ApplicationStore, 46 ApplicationStore,
43 ApplicationWindowId, 47 ApplicationWindowId,
44 }, 48 },
49 base::{CommandType, WordStyle},
50 completion::{complete_path, CompletionMap},
45 context::EditContext, 51 context::EditContext,
52 cursor::Cursor,
53 rope::EditRope,
46 store::Store, 54 store::Store,
47 }, 55 },
48 env::vim::{ 56 env::vim::{
49 command::{CommandContext, VimCommand, VimCommandMachine}, 57 command::{CommandContext, CommandDescription, VimCommand, VimCommandMachine},
50 keybindings::VimMachine, 58 keybindings::VimMachine,
51 VimContext, 59 VimContext,
52 }, 60 },
@@ -66,6 +74,20 @@ use crate::{
66 ApplicationSettings, 74 ApplicationSettings,
67}; 75};
68 76
77pub const MATRIX_ID_WORD: WordStyle = WordStyle::CharSet(is_mxid_char);
78
79/// Find the boundaries for a Matrix username, room alias, or room ID.
80///
81/// Technically "[" and "]" should be here since IPv6 addresses are allowed
82/// in the server name, but in practice that should be uncommon, and people
83/// can just use `gf` and friends in Visual mode instead.
84fn is_mxid_char(c: char) -> bool {
85 return c >= 'a' && c <= 'z' ||
86 c >= 'A' && c <= 'Z' ||
87 c >= '0' && c <= '9' ||
88 ":-./@_#!".contains(c);
89}
90
69const ROOM_FETCH_DEBOUNCE: Duration = Duration::from_secs(2); 91const ROOM_FETCH_DEBOUNCE: Duration = Duration::from_secs(2);
70 92
71#[derive(Clone, Debug, Eq, PartialEq)] 93#[derive(Clone, Debug, Eq, PartialEq)]
@@ -528,13 +550,28 @@ impl RoomInfo {
528 } 550 }
529} 551}
530 552
553fn emoji_map() -> CompletionMap<String, &'static Emoji> {
554 let mut emojis = CompletionMap::default();
555
556 for emoji in emojis::iter() {
557 for shortcode in emoji.shortcodes() {
558 emojis.insert(shortcode.to_string(), emoji);
559 }
560 }
561
562 return emojis;
563}
564
531pub struct ChatStore { 565pub struct ChatStore {
566 pub cmds: ProgramCommands,
532 pub worker: Requester, 567 pub worker: Requester,
533 pub rooms: HashMap<OwnedRoomId, RoomInfo>, 568 pub rooms: CompletionMap<OwnedRoomId, RoomInfo>,
534 pub names: HashMap<String, OwnedRoomId>, 569 pub names: CompletionMap<String, OwnedRoomId>,
570 pub presences: CompletionMap<OwnedUserId, PresenceState>,
535 pub verifications: HashMap<String, SasVerification>, 571 pub verifications: HashMap<String, SasVerification>,
536 pub settings: ApplicationSettings, 572 pub settings: ApplicationSettings,
537 pub need_load: HashSet<OwnedRoomId>, 573 pub need_load: HashSet<OwnedRoomId>,
574 pub emojis: CompletionMap<String, &'static Emoji>,
538} 575}
539 576
540impl ChatStore { 577impl ChatStore {
@@ -543,10 +580,13 @@ impl ChatStore {
543 worker, 580 worker,
544 settings, 581 settings,
545 582
583 cmds: crate::commands::setup_commands(),
546 names: Default::default(), 584 names: Default::default(),
547 rooms: Default::default(), 585 rooms: Default::default(),
586 presences: Default::default(),
548 verifications: Default::default(), 587 verifications: Default::default(),
549 need_load: Default::default(), 588 need_load: Default::default(),
589 emojis: emoji_map(),
550 } 590 }
551 } 591 }
552 592
@@ -587,10 +627,10 @@ impl ChatStore {
587 } 627 }
588 628
589 pub fn load_older(&mut self, limit: u32) { 629 pub fn load_older(&mut self, limit: u32) {
590 let ChatStore { need_load, rooms, worker, .. } = self; 630 let ChatStore { need_load, presences, rooms, worker, .. } = self;
591 631
592 for room_id in std::mem::take(need_load).into_iter() { 632 for room_id in std::mem::take(need_load).into_iter() {
593 let info = rooms.entry(room_id.clone()).or_default(); 633 let info = rooms.get_or_default(room_id.clone());
594 634
595 if info.recently_fetched() { 635 if info.recently_fetched() {
596 need_load.insert(room_id); 636 need_load.insert(room_id);
@@ -610,6 +650,9 @@ impl ChatStore {
610 match res { 650 match res {
611 Ok((fetch_id, msgs)) => { 651 Ok((fetch_id, msgs)) => {
612 for msg in msgs.into_iter() { 652 for msg in msgs.into_iter() {
653 let sender = msg.sender().to_owned();
654 let _ = presences.get_or_default(sender);
655
613 match msg { 656 match msg {
614 AnyMessageLikeEvent::RoomMessage(msg) => { 657 AnyMessageLikeEvent::RoomMessage(msg) => {
615 info.insert(msg); 658 info.insert(msg);
@@ -639,11 +682,11 @@ impl ChatStore {
639 } 682 }
640 683
641 pub fn get_room_info(&mut self, room_id: OwnedRoomId) -> &mut RoomInfo { 684 pub fn get_room_info(&mut self, room_id: OwnedRoomId) -> &mut RoomInfo {
642 self.rooms.entry(room_id).or_default() 685 self.rooms.get_or_default(room_id)
643 } 686 }
644 687
645 pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) { 688 pub fn set_room_name(&mut self, room_id: &RoomId, name: &str) {
646 self.rooms.entry(room_id.to_owned()).or_default().name = name.to_string().into(); 689 self.rooms.get_or_default(room_id.to_owned()).name = name.to_string().into();
647 } 690 }
648 691
649 pub fn insert_sas(&mut self, sas: SasVerification) { 692 pub fn insert_sas(&mut self, sas: SasVerification) {
@@ -686,7 +729,7 @@ impl RoomFocus {
686 729
687#[derive(Clone, Debug, Eq, Hash, PartialEq)] 730#[derive(Clone, Debug, Eq, Hash, PartialEq)]
688pub enum IambBufferId { 731pub enum IambBufferId {
689 Command, 732 Command(CommandType),
690 Room(OwnedRoomId, RoomFocus), 733 Room(OwnedRoomId, RoomFocus),
691 DirectList, 734 DirectList,
692 MemberList(OwnedRoomId), 735 MemberList(OwnedRoomId),
@@ -699,7 +742,7 @@ pub enum IambBufferId {
699impl IambBufferId { 742impl IambBufferId {
700 pub fn to_window(&self) -> Option<IambId> { 743 pub fn to_window(&self) -> Option<IambId> {
701 match self { 744 match self {
702 IambBufferId::Command => None, 745 IambBufferId::Command(_) => None,
703 IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())), 746 IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())),
704 IambBufferId::DirectList => Some(IambId::DirectList), 747 IambBufferId::DirectList => Some(IambId::DirectList),
705 IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())), 748 IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())),
@@ -719,6 +762,133 @@ impl ApplicationInfo for IambInfo {
719 type Action = IambAction; 762 type Action = IambAction;
720 type WindowId = IambId; 763 type WindowId = IambId;
721 type ContentId = IambBufferId; 764 type ContentId = IambBufferId;
765
766 fn complete(
767 text: &EditRope,
768 cursor: &mut Cursor,
769 content: &IambBufferId,
770 store: &mut ProgramStore,
771 ) -> Vec<String> {
772 match content {
773 IambBufferId::Command(CommandType::Command) => complete_cmdbar(text, cursor, store),
774 IambBufferId::Command(CommandType::Search) => vec![],
775
776 IambBufferId::Room(_, RoomFocus::MessageBar) => {
777 complete_matrix_names(text, cursor, store)
778 },
779 IambBufferId::Room(_, RoomFocus::Scrollback) => vec![],
780
781 IambBufferId::DirectList => vec![],
782 IambBufferId::MemberList(_) => vec![],
783 IambBufferId::RoomList => vec![],
784 IambBufferId::SpaceList => vec![],
785 IambBufferId::VerifyList => vec![],
786 IambBufferId::Welcome => vec![],
787 }
788 }
789
790 fn content_of_command(ct: CommandType) -> IambBufferId {
791 IambBufferId::Command(ct)
792 }
793}
794
795fn complete_users(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
796 let id = text
797 .get_prefix_word_mut(cursor, &MATRIX_ID_WORD)
798 .unwrap_or_else(EditRope::empty);
799 let id = Cow::from(&id);
800
801 store
802 .application
803 .presences
804 .complete(id.as_ref())
805 .into_iter()
806 .map(|i| i.to_string())
807 .collect()
808}
809
810fn complete_matrix_names(
811 text: &EditRope,
812 cursor: &mut Cursor,
813 store: &ProgramStore,
814) -> Vec<String> {
815 let id = text
816 .get_prefix_word_mut(cursor, &MATRIX_ID_WORD)
817 .unwrap_or_else(EditRope::empty);
818 let id = Cow::from(&id);
819
820 let list = store.application.names.complete(id.as_ref());
821 if !list.is_empty() {
822 return list;
823 }
824
825 let list = store.application.presences.complete(id.as_ref());
826 if !list.is_empty() {
827 return list.into_iter().map(|i| i.to_string()).collect();
828 }
829
830 store
831 .application
832 .rooms
833 .complete(id.as_ref())
834 .into_iter()
835 .map(|i| i.to_string())
836 .collect()
837}
838
839fn complete_emoji(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
840 let sc = text.get_prefix_word_mut(cursor, &WordStyle::Little);
841 let sc = sc.unwrap_or_else(EditRope::empty);
842 let sc = Cow::from(&sc);
843
844 store.application.emojis.complete(sc.as_ref())
845}
846
847fn complete_cmdarg(
848 desc: CommandDescription,
849 text: &EditRope,
850 cursor: &mut Cursor,
851 store: &ProgramStore,
852) -> Vec<String> {
853 let cmd = match store.application.cmds.get(desc.command.as_str()) {
854 Ok(cmd) => cmd,
855 Err(_) => return vec![],
856 };
857
858 match cmd.name.as_str() {
859 "cancel" | "dms" | "edit" | "redact" | "reply" => vec![],
860 "members" | "rooms" | "spaces" | "welcome" => vec![],
861 "download" | "open" | "upload" => complete_path(text, cursor),
862 "react" | "unreact" => complete_emoji(text, cursor, store),
863
864 "invite" => complete_users(text, cursor, store),
865 "join" => complete_matrix_names(text, cursor, store),
866 "room" => vec![],
867 "verify" => vec![],
868 _ => panic!("unknown command {}", cmd.name.as_str()),
869 }
870}
871
872fn complete_cmdbar(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> {
873 let eo = text.cursor_to_offset(cursor);
874 let slice = text.slice(0.into(), eo, false);
875 let cow = Cow::from(&slice);
876
877 match CommandDescription::from_str(cow.as_ref()) {
878 Ok(desc) => {
879 if desc.arg.untrimmed.is_empty() {
880 // Complete command name and set cursor position.
881 let _ = text.get_prefix_word_mut(cursor, &WordStyle::Little);
882 store.application.cmds.complete_name(desc.command.as_str())
883 } else {
884 // Complete command argument.
885 complete_cmdarg(desc, text, cursor, store)
886 }
887 },
888
889 // Can't parse command text, so return zero completions.
890 Err(_) => vec![],
891 }
722} 892}
723 893
724#[cfg(test)] 894#[cfg(test)]
@@ -804,4 +974,44 @@ pub mod tests {
804 ]) 974 ])
805 ); 975 );
806 } 976 }
977
978 #[tokio::test]
979 async fn test_complete_cmdbar() {
980 let store = mock_store().await;
981
982 let text = EditRope::from("invite ");
983 let mut cursor = Cursor::new(0, 7);
984 let id = text
985 .get_prefix_word_mut(&mut cursor, &MATRIX_ID_WORD)
986 .unwrap_or_else(EditRope::empty);
987 assert_eq!(id.to_string(), "");
988 assert_eq!(cursor, Cursor::new(0, 7));
989
990 let text = EditRope::from("invite ");
991 let mut cursor = Cursor::new(0, 7);
992 let res = complete_cmdbar(&text, &mut cursor, &store);
993 assert_eq!(res, vec![
994 "@user1:example.com",
995 "@user2:example.com",
996 "@user3:example.com",
997 "@user4:example.com",
998 "@user5:example.com"
999 ]);
1000
1001 let text = EditRope::from("invite ignored");
1002 let mut cursor = Cursor::new(0, 7);
1003 let res = complete_cmdbar(&text, &mut cursor, &store);
1004 assert_eq!(res, vec![
1005 "@user1:example.com",
1006 "@user2:example.com",
1007 "@user3:example.com",
1008 "@user4:example.com",
1009 "@user5:example.com"
1010 ]);
1011
1012 let text = EditRope::from("invite @user1ignored");
1013 let mut cursor = Cursor::new(0, 13);
1014 let res = complete_cmdbar(&text, &mut cursor, &store);
1015 assert_eq!(res, vec!["@user1:example.com"]);
1016 }
807} 1017}
src/commands.rs +70 −18
@@ -395,24 +395,76 @@ fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
395} 395}
396 396
397fn add_iamb_commands(cmds: &mut ProgramCommands) { 397fn add_iamb_commands(cmds: &mut ProgramCommands) {
398 cmds.add_command(ProgramCommand { names: vec!["cancel".into()], f: iamb_cancel }); 398 cmds.add_command(ProgramCommand {
399 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); 399 name: "cancel".into(),
400 cmds.add_command(ProgramCommand { names: vec!["download".into()], f: iamb_download }); 400 aliases: vec![],
401 cmds.add_command(ProgramCommand { names: vec!["open".into()], f: iamb_open }); 401 f: iamb_cancel,
402 cmds.add_command(ProgramCommand { names: vec!["edit".into()], f: iamb_edit }); 402 });
403 cmds.add_command(ProgramCommand { names: vec!["invite".into()], f: iamb_invite }); 403 cmds.add_command(ProgramCommand { name: "dms".into(), aliases: vec![], f: iamb_dms });
404 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); 404 cmds.add_command(ProgramCommand {
405 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); 405 name: "download".into(),
406 cmds.add_command(ProgramCommand { names: vec!["react".into()], f: iamb_react }); 406 aliases: vec![],
407 cmds.add_command(ProgramCommand { names: vec!["redact".into()], f: iamb_redact }); 407 f: iamb_download,
408 cmds.add_command(ProgramCommand { names: vec!["reply".into()], f: iamb_reply }); 408 });
409 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); 409 cmds.add_command(ProgramCommand { name: "open".into(), aliases: vec![], f: iamb_open });
410 cmds.add_command(ProgramCommand { names: vec!["room".into()], f: iamb_room }); 410 cmds.add_command(ProgramCommand { name: "edit".into(), aliases: vec![], f: iamb_edit });
411 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); 411 cmds.add_command(ProgramCommand {
412 cmds.add_command(ProgramCommand { names: vec!["unreact".into()], f: iamb_unreact }); 412 name: "invite".into(),
413 cmds.add_command(ProgramCommand { names: vec!["upload".into()], f: iamb_upload }); 413 aliases: vec![],
414 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); 414 f: iamb_invite,
415 cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome }); 415 });
416 cmds.add_command(ProgramCommand { name: "join".into(), aliases: vec![], f: iamb_join });
417 cmds.add_command(ProgramCommand {
418 name: "members".into(),
419 aliases: vec![],
420 f: iamb_members,
421 });
422 cmds.add_command(ProgramCommand {
423 name: "react".into(),
424 aliases: vec![],
425 f: iamb_react,
426 });
427 cmds.add_command(ProgramCommand {
428 name: "redact".into(),
429 aliases: vec![],
430 f: iamb_redact,
431 });
432 cmds.add_command(ProgramCommand {
433 name: "reply".into(),
434 aliases: vec![],
435 f: iamb_reply,
436 });
437 cmds.add_command(ProgramCommand {
438 name: "rooms".into(),
439 aliases: vec![],
440 f: iamb_rooms,
441 });
442 cmds.add_command(ProgramCommand { name: "room".into(), aliases: vec![], f: iamb_room });
443 cmds.add_command(ProgramCommand {
444 name: "spaces".into(),
445 aliases: vec![],
446 f: iamb_spaces,
447 });
448 cmds.add_command(ProgramCommand {
449 name: "unreact".into(),
450 aliases: vec![],
451 f: iamb_unreact,
452 });
453 cmds.add_command(ProgramCommand {
454 name: "upload".into(),
455 aliases: vec![],
456 f: iamb_upload,
457 });
458 cmds.add_command(ProgramCommand {
459 name: "verify".into(),
460 aliases: vec![],
461 f: iamb_verify,
462 });
463 cmds.add_command(ProgramCommand {
464 name: "welcome".into(),
465 aliases: vec![],
466 f: iamb_welcome,
467 });
416} 468}
417 469
418pub fn setup_commands() -> ProgramCommands { 470pub fn setup_commands() -> ProgramCommands {
src/keybindings.rs +2 −15
@@ -1,34 +1,21 @@
1use modalkit::{ 1use modalkit::{
2 editing::action::WindowAction, 2 editing::action::WindowAction,
3 editing::base::WordStyle,
4 env::vim::keybindings::{InputStep, VimBindings}, 3 env::vim::keybindings::{InputStep, VimBindings},
5 env::vim::VimMode, 4 env::vim::VimMode,
6 input::bindings::{EdgeEvent, EdgeRepeat, InputBindings}, 5 input::bindings::{EdgeEvent, EdgeRepeat, InputBindings},
7 input::key::TerminalKey, 6 input::key::TerminalKey,
8}; 7};
9 8
10use crate::base::{IambAction, IambInfo, Keybindings}; 9use crate::base::{IambAction, IambInfo, Keybindings, MATRIX_ID_WORD};
11 10
12type IambStep = InputStep<IambInfo>; 11type IambStep = InputStep<IambInfo>;
13 12
14/// Find the boundaries for a Matrix username, room alias, or room ID.
15///
16/// Technically "[" and "]" should be here since IPv6 addresses are allowed
17/// in the server name, but in practice that should be uncommon, and people
18/// can just use `gf` and friends in Visual mode instead.
19fn is_mxid_char(c: char) -> bool {
20 return c >= 'a' && c <= 'z' ||
21 c >= 'A' && c <= 'Z' ||
22 c >= '0' && c <= '9' ||
23 ":-./@_#!".contains(c);
24}
25
26pub fn setup_keybindings() -> Keybindings { 13pub fn setup_keybindings() -> Keybindings {
27 let mut ism = Keybindings::empty(); 14 let mut ism = Keybindings::empty();
28 15
29 let vim = VimBindings::default() 16 let vim = VimBindings::default()
30 .submit_on_enter() 17 .submit_on_enter()
31 .cursor_open(WordStyle::CharSet(is_mxid_char)); 18 .cursor_open(MATRIX_ID_WORD.clone());
32 19
33 vim.setup(&mut ism); 20 vim.setup(&mut ism);
34 21
src/main.rs +2 −7
@@ -54,13 +54,11 @@ use crate::{
54 AsyncProgramStore, 54 AsyncProgramStore,
55 ChatStore, 55 ChatStore,
56 IambAction, 56 IambAction,
57 IambBufferId,
58 IambError, 57 IambError,
59 IambId, 58 IambId,
60 IambInfo, 59 IambInfo,
61 IambResult, 60 IambResult,
62 ProgramAction, 61 ProgramAction,
63 ProgramCommands,
64 ProgramContext, 62 ProgramContext,
65 ProgramStore, 63 ProgramStore,
66 }, 64 },
@@ -116,7 +114,6 @@ struct Application {
116 terminal: Terminal<CrosstermBackend<Stdout>>, 114 terminal: Terminal<CrosstermBackend<Stdout>>,
117 bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>, 115 bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>,
118 actstack: VecDeque<(ProgramAction, ProgramContext)>, 116 actstack: VecDeque<(ProgramAction, ProgramContext)>,
119 cmds: ProgramCommands,
120 screen: ScreenState<IambWindow, IambInfo>, 117 screen: ScreenState<IambWindow, IambInfo>,
121} 118}
122 119
@@ -138,7 +135,6 @@ impl Application {
138 135
139 let bindings = crate::keybindings::setup_keybindings(); 136 let bindings = crate::keybindings::setup_keybindings();
140 let bindings = KeyManager::new(bindings); 137 let bindings = KeyManager::new(bindings);
141 let cmds = crate::commands::setup_commands();
142 138
143 let mut locked = store.lock().await; 139 let mut locked = store.lock().await;
144 140
@@ -149,7 +145,7 @@ impl Application {
149 .or_else(|| IambWindow::open(IambId::Welcome, locked.deref_mut()).ok()) 145 .or_else(|| IambWindow::open(IambId::Welcome, locked.deref_mut()).ok())
150 .unwrap(); 146 .unwrap();
151 147
152 let cmd = CommandBarState::new(IambBufferId::Command, locked.deref_mut()); 148 let cmd = CommandBarState::new(locked.deref_mut());
153 let screen = ScreenState::new(win, cmd); 149 let screen = ScreenState::new(win, cmd);
154 150
155 let worker = locked.application.worker.clone(); 151 let worker = locked.application.worker.clone();
@@ -163,7 +159,6 @@ impl Application {
163 terminal, 159 terminal,
164 bindings, 160 bindings,
165 actstack, 161 actstack,
166 cmds,
167 screen, 162 screen,
168 }) 163 })
169 } 164 }
@@ -321,7 +316,7 @@ impl Application {
321 None 316 None
322 }, 317 },
323 Action::Command(act) => { 318 Action::Command(act) => {
324 let acts = self.cmds.command(&act, &ctx)?; 319 let acts = store.application.cmds.command(&act, &ctx)?;
325 self.action_prepend(acts); 320 self.action_prepend(acts);
326 321
327 None 322 None
src/tests.rs +8
@@ -208,6 +208,14 @@ pub async fn mock_store() -> ProgramStore {
208 let worker = Requester { tx, client }; 208 let worker = Requester { tx, client };
209 209
210 let mut store = ChatStore::new(worker, mock_settings()); 210 let mut store = ChatStore::new(worker, mock_settings());
211
212 // Add presence information.
213 store.presences.get_or_default(TEST_USER1.clone());
214 store.presences.get_or_default(TEST_USER2.clone());
215 store.presences.get_or_default(TEST_USER3.clone());
216 store.presences.get_or_default(TEST_USER4.clone());
217 store.presences.get_or_default(TEST_USER5.clone());
218
211 let room_id = TEST_ROOM1_ID.clone(); 219 let room_id = TEST_ROOM1_ID.clone();
212 let info = mock_room(); 220 let info = mock_room();
213 221
src/windows/mod.rs +36 −15
@@ -1,5 +1,4 @@
1use std::cmp::{Ord, Ordering, PartialOrd}; 1use std::cmp::{Ord, Ordering, PartialOrd};
2use std::collections::hash_map::Entry;
3 2
4use matrix_sdk::{ 3use matrix_sdk::{
5 encryption::verification::{format_emojis, SasVerification}, 4 encryption::verification::{format_emojis, SasVerification},
@@ -45,7 +44,9 @@ use modalkit::{
45 ScrollStyle, 44 ScrollStyle,
46 ViewportContext, 45 ViewportContext,
47 WordStyle, 46 WordStyle,
47 WriteFlags,
48 }, 48 },
49 completion::CompletionList,
49 }, 50 },
50 widgets::{ 51 widgets::{
51 list::{List, ListCursor, ListItem, ListState}, 52 list::{List, ListCursor, ListItem, ListState},
@@ -469,6 +470,19 @@ impl WindowOps<IambInfo> for IambWindow {
469 delegate!(self, w => w.close(flags, store)) 470 delegate!(self, w => w.close(flags, store))
470 } 471 }
471 472
473 fn write(
474 &mut self,
475 path: Option<&str>,
476 flags: WriteFlags,
477 store: &mut ProgramStore,
478 ) -> IambResult<EditInfo> {
479 delegate!(self, w => w.write(path, flags, store))
480 }
481
482 fn get_completions(&self) -> Option<CompletionList> {
483 delegate!(self, w => w.get_completions())
484 }
485
472 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { 486 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
473 delegate!(self, w => w.get_cursor_word(style)) 487 delegate!(self, w => w.get_cursor_word(style))
474 } 488 }
@@ -575,21 +589,18 @@ impl Window<IambInfo> for IambWindow {
575 fn find(name: String, store: &mut ProgramStore) -> IambResult<Self> { 589 fn find(name: String, store: &mut ProgramStore) -> IambResult<Self> {
576 let ChatStore { names, worker, .. } = &mut store.application; 590 let ChatStore { names, worker, .. } = &mut store.application;
577 591
578 match names.entry(name) { 592 if let Some(room) = names.get_mut(&name) {
579 Entry::Vacant(v) => { 593 let id = IambId::Room(room.clone());
580 let room_id = worker.join_room(v.key().to_string())?;
581 v.insert(room_id.clone());
582 594
583 let (room, name, tags) = store.application.worker.get_room(room_id)?; 595 IambWindow::open(id, store)
584 let room = RoomState::new(room, name, tags, store); 596 } else {
597 let room_id = worker.join_room(name.clone())?;
598 names.insert(name, room_id.clone());
585 599
586 Ok(room.into()) 600 let (room, name, tags) = store.application.worker.get_room(room_id)?;
587 }, 601 let room = RoomState::new(room, name, tags, store);
588 Entry::Occupied(o) => {
589 let id = IambId::Room(o.get().clone());
590 602
591 IambWindow::open(id, store) 603 Ok(room.into())
592 },
593 } 604 }
594 } 605 }
595 606
@@ -620,11 +631,16 @@ impl RoomItem {
620 store: &mut ProgramStore, 631 store: &mut ProgramStore,
621 ) -> Self { 632 ) -> Self {
622 let name = name.to_string(); 633 let name = name.to_string();
634 let room_id = room.room_id();
623 635
624 let info = store.application.get_room_info(room.room_id().to_owned()); 636 let info = store.application.get_room_info(room_id.to_owned());
625 info.name = name.clone().into(); 637 info.name = name.clone().into();
626 info.tags = tags.clone(); 638 info.tags = tags.clone();
627 639
640 if let Some(alias) = room.canonical_alias() {
641 store.application.names.insert(alias.to_string(), room_id.to_owned());
642 }
643
628 RoomItem { room, tags, name } 644 RoomItem { room, tags, name }
629 } 645 }
630} 646}
@@ -772,8 +788,13 @@ pub struct SpaceItem {
772impl SpaceItem { 788impl SpaceItem {
773 fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self { 789 fn new(room: MatrixRoom, name: DisplayName, store: &mut ProgramStore) -> Self {
774 let name = name.to_string(); 790 let name = name.to_string();
791 let room_id = room.room_id();
775 792
776 store.application.set_room_name(room.room_id(), name.as_str()); 793 store.application.set_room_name(room_id, name.as_str());
794
795 if let Some(alias) = room.canonical_alias() {
796 store.application.names.insert(alias.to_string(), room_id.to_owned());
797 }
777 798
778 SpaceItem { room, name } 799 SpaceItem { room, name }
779 } 800 }
src/windows/room/chat.rs +19 −3
@@ -52,7 +52,8 @@ use modalkit::editing::{
52 Scrollable, 52 Scrollable,
53 UIError, 53 UIError,
54 }, 54 },
55 base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle}, 55 base::{CloseFlags, Count, MoveDir1D, PositionList, ScrollStyle, WordStyle, WriteFlags},
56 completion::CompletionList,
56 context::Resolve, 57 context::Resolve,
57 history::{self, HistoryList}, 58 history::{self, HistoryList},
58 rope::EditRope, 59 rope::EditRope,
@@ -154,7 +155,7 @@ impl ChatState {
154 let client = &store.application.worker.client; 155 let client = &store.application.worker.client;
155 156
156 let settings = &store.application.settings; 157 let settings = &store.application.settings;
157 let info = store.application.rooms.entry(self.room_id.clone()).or_default(); 158 let info = store.application.rooms.get_or_default(self.room_id.clone());
158 159
159 let msg = self 160 let msg = self
160 .scrollback 161 .scrollback
@@ -389,7 +390,7 @@ impl ChatState {
389 .client 390 .client
390 .get_joined_room(self.id()) 391 .get_joined_room(self.id())
391 .ok_or(IambError::NotJoined)?; 392 .ok_or(IambError::NotJoined)?;
392 let info = store.application.rooms.entry(self.id().to_owned()).or_default(); 393 let info = store.application.rooms.get_or_default(self.id().to_owned());
393 let mut show_echo = true; 394 let mut show_echo = true;
394 395
395 let (event_id, msg) = match act { 396 let (event_id, msg) = match act {
@@ -550,6 +551,21 @@ impl WindowOps<IambInfo> for ChatState {
550 true 551 true
551 } 552 }
552 553
554 fn write(
555 &mut self,
556 _: Option<&str>,
557 _: WriteFlags,
558 _: &mut ProgramStore,
559 ) -> IambResult<EditInfo> {
560 // XXX: what's the right writing behaviour for a room?
561 // Should write send a message?
562 Ok(None)
563 }
564
565 fn get_completions(&self) -> Option<CompletionList> {
566 delegate!(self, w => w.get_completions())
567 }
568
553 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { 569 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
554 delegate!(self, w => w.get_cursor_word(style)) 570 delegate!(self, w => w.get_cursor_word(style))
555 } 571 }
src/windows/room/mod.rs +26 −4
@@ -40,7 +40,9 @@ use modalkit::{
40 PositionList, 40 PositionList,
41 ScrollStyle, 41 ScrollStyle,
42 WordStyle, 42 WordStyle,
43 WriteFlags,
43 }, 44 },
45 editing::completion::CompletionList,
44 input::InputContext, 46 input::InputContext,
45 widgets::{TermOffset, TerminalCursor, WindowOps}, 47 widgets::{TermOffset, TerminalCursor, WindowOps},
46}; 48};
@@ -383,10 +385,30 @@ impl WindowOps<IambInfo> for RoomState {
383 } 385 }
384 } 386 }
385 387
386 fn close(&mut self, _: CloseFlags, _: &mut ProgramStore) -> bool { 388 fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
387 // XXX: what's the right closing behaviour for a room? 389 match self {
388 // Should write send a message? 390 RoomState::Chat(chat) => chat.close(flags, store),
389 true 391 RoomState::Space(space) => space.close(flags, store),
392 }
393 }
394
395 fn write(
396 &mut self,
397 path: Option<&str>,
398 flags: WriteFlags,
399 store: &mut ProgramStore,
400 ) -> IambResult<EditInfo> {
401 match self {
402 RoomState::Chat(chat) => chat.write(path, flags, store),
403 RoomState::Space(space) => space.write(path, flags, store),
404 }
405 }
406
407 fn get_completions(&self) -> Option<CompletionList> {
408 match self {
409 RoomState::Chat(chat) => chat.get_completions(),
410 RoomState::Space(space) => space.get_completions(),
411 }
390 } 412 }
391 413
392 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { 414 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
src/windows/room/scrollback.rs +41 −8
@@ -32,6 +32,9 @@ use modalkit::editing::{
32 base::{ 32 base::{
33 Axis, 33 Axis,
34 CloseFlags, 34 CloseFlags,
35 CompletionDisplay,
36 CompletionSelection,
37 CompletionType,
35 Count, 38 Count,
36 EditRange, 39 EditRange,
37 EditTarget, 40 EditTarget,
@@ -51,7 +54,9 @@ use modalkit::editing::{
51 TargetShape, 54 TargetShape,
52 ViewportContext, 55 ViewportContext,
53 WordStyle, 56 WordStyle,
57 WriteFlags,
54 }, 58 },
59 completion::CompletionList,
55 context::{EditContext, Resolve}, 60 context::{EditContext, Resolve},
56 cursor::{CursorGroup, CursorState}, 61 cursor::{CursorGroup, CursorState},
57 history::HistoryList, 62 history::HistoryList,
@@ -60,7 +65,7 @@ use modalkit::editing::{
60}; 65};
61 66
62use crate::{ 67use crate::{
63 base::{IambBufferId, IambInfo, ProgramContext, ProgramStore, RoomFocus, RoomInfo}, 68 base::{IambBufferId, IambInfo, IambResult, ProgramContext, ProgramStore, RoomFocus, RoomInfo},
64 config::ApplicationSettings, 69 config::ApplicationSettings,
65 message::{Message, MessageCursor, MessageKey, Messages}, 70 message::{Message, MessageCursor, MessageKey, Messages},
66}; 71};
@@ -515,6 +520,23 @@ impl WindowOps<IambInfo> for ScrollbackState {
515 true 520 true
516 } 521 }
517 522
523 fn write(
524 &mut self,
525 _: Option<&str>,
526 flags: WriteFlags,
527 _: &mut ProgramStore,
528 ) -> IambResult<EditInfo> {
529 if flags.contains(WriteFlags::FORCE) {
530 Ok(None)
531 } else {
532 Err(EditError::ReadOnly.into())
533 }
534 }
535
536 fn get_completions(&self) -> Option<CompletionList> {
537 None
538 }
539
518 fn get_cursor_word(&self, _: &WordStyle) -> Option<String> { 540 fn get_cursor_word(&self, _: &WordStyle) -> Option<String> {
519 None 541 None
520 } 542 }
@@ -532,7 +554,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
532 ctx: &ProgramContext, 554 ctx: &ProgramContext,
533 store: &mut ProgramStore, 555 store: &mut ProgramStore,
534 ) -> EditResult<EditInfo, IambInfo> { 556 ) -> EditResult<EditInfo, IambInfo> {
535 let info = store.application.rooms.entry(self.room_id.clone()).or_default(); 557 let info = store.application.rooms.get_or_default(self.room_id.clone());
536 let key = if let Some(k) = self.cursor.to_key(info) { 558 let key = if let Some(k) = self.cursor.to_key(info) {
537 k.clone() 559 k.clone()
538 } else { 560 } else {
@@ -762,6 +784,17 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
762 } 784 }
763 } 785 }
764 786
787 fn complete(
788 &mut self,
789 _: &CompletionType,
790 _: &CompletionSelection,
791 _: &CompletionDisplay,
792 _: &ProgramContext,
793 _: &mut ProgramStore,
794 ) -> EditResult<EditInfo, IambInfo> {
795 Err(EditError::ReadOnly)
796 }
797
765 fn insert_text( 798 fn insert_text(
766 &mut self, 799 &mut self,
767 _: &InsertTextAction, 800 _: &InsertTextAction,
@@ -867,9 +900,9 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
867 EditorAction::Mark(name) => self.mark(ctx.resolve(name), ctx, store), 900 EditorAction::Mark(name) => self.mark(ctx.resolve(name), ctx, store),
868 EditorAction::Selection(act) => self.selection_command(act, ctx, store), 901 EditorAction::Selection(act) => self.selection_command(act, ctx, store),
869 902
870 EditorAction::Complete(_, _) => { 903 EditorAction::Complete(_, _, _) => {
871 let msg = ""; 904 let msg = "Nothing to complete in message scrollback";
872 let err = EditError::Unimplemented(msg.into()); 905 let err = EditError::Failure(msg.into());
873 906
874 Err(err) 907 Err(err)
875 }, 908 },
@@ -991,7 +1024,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
991 ctx: &ProgramContext, 1024 ctx: &ProgramContext,
992 store: &mut ProgramStore, 1025 store: &mut ProgramStore,
993 ) -> EditResult<EditInfo, IambInfo> { 1026 ) -> EditResult<EditInfo, IambInfo> {
994 let info = store.application.rooms.entry(self.room_id.clone()).or_default(); 1027 let info = store.application.rooms.get_or_default(self.room_id.clone());
995 let settings = &store.application.settings; 1028 let settings = &store.application.settings;
996 let mut corner = self.viewctx.corner.clone(); 1029 let mut corner = self.viewctx.corner.clone();
997 1030
@@ -1105,7 +1138,7 @@ impl ScrollActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
1105 Err(err) 1138 Err(err)
1106 }, 1139 },
1107 Axis::Vertical => { 1140 Axis::Vertical => {
1108 let info = store.application.rooms.entry(self.room_id.clone()).or_default(); 1141 let info = store.application.rooms.get_or_default(self.room_id.clone());
1109 let settings = &store.application.settings; 1142 let settings = &store.application.settings;
1110 1143
1111 if let Some(key) = self.cursor.to_key(info).cloned() { 1144 if let Some(key) = self.cursor.to_key(info).cloned() {
@@ -1193,7 +1226,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
1193 type State = ScrollbackState; 1226 type State = ScrollbackState;
1194 1227
1195 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { 1228 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
1196 let info = self.store.application.rooms.entry(state.room_id.clone()).or_default(); 1229 let info = self.store.application.rooms.get_or_default(state.room_id.clone());
1197 let settings = &self.store.application.settings; 1230 let settings = &self.store.application.settings;
1198 let area = info.render_typing(area, buf, &self.store.application.settings); 1231 let area = info.render_typing(area, buf, &self.store.application.settings);
1199 1232
src/windows/welcome.rs +17 −2
@@ -8,9 +8,11 @@ use modalkit::{
8 widgets::{TermOffset, TerminalCursor}, 8 widgets::{TermOffset, TerminalCursor},
9}; 9};
10 10
11use modalkit::editing::base::{CloseFlags, WordStyle}; 11use modalkit::editing::action::EditInfo;
12use modalkit::editing::base::{CloseFlags, WordStyle, WriteFlags};
13use modalkit::editing::completion::CompletionList;
12 14
13use crate::base::{IambBufferId, IambInfo, ProgramStore}; 15use crate::base::{IambBufferId, IambInfo, IambResult, ProgramStore};
14 16
15const WELCOME_TEXT: &str = include_str!("welcome.md"); 17const WELCOME_TEXT: &str = include_str!("welcome.md");
16 18
@@ -63,6 +65,19 @@ impl WindowOps<IambInfo> for WelcomeState {
63 self.tbox.close(flags, store) 65 self.tbox.close(flags, store)
64 } 66 }
65 67
68 fn write(
69 &mut self,
70 path: Option<&str>,
71 flags: WriteFlags,
72 store: &mut ProgramStore,
73 ) -> IambResult<EditInfo> {
74 self.tbox.write(path, flags, store)
75 }
76
77 fn get_completions(&self) -> Option<CompletionList> {
78 self.tbox.get_completions()
79 }
80
66 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> { 81 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
67 self.tbox.get_cursor_word(style) 82 self.tbox.get_cursor_word(style)
68 } 83 }
src/worker.rs +20 −6
@@ -32,6 +32,7 @@ use matrix_sdk::{
32 start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, 32 start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
33 VerificationMethod, 33 VerificationMethod,
34 }, 34 },
35 presence::PresenceEvent,
35 reaction::ReactionEventContent, 36 reaction::ReactionEventContent,
36 room::{ 37 room::{
37 message::{MessageType, RoomMessageEventContent}, 38 message::{MessageType, RoomMessageEventContent},
@@ -503,6 +504,15 @@ impl ClientWorker {
503 }, 504 },
504 ); 505 );
505 506
507 let _ =
508 self.client
509 .add_event_handler(|ev: PresenceEvent, store: Ctx<AsyncProgramStore>| {
510 async move {
511 let mut locked = store.lock().await;
512 locked.application.presences.insert(ev.sender, ev.content.presence);
513 }
514 });
515
506 let _ = self.client.add_event_handler( 516 let _ = self.client.add_event_handler(
507 |ev: SyncStateEvent<RoomNameEventContent>, 517 |ev: SyncStateEvent<RoomNameEventContent>,
508 room: MatrixRoom, 518 room: MatrixRoom,
@@ -513,8 +523,7 @@ impl ClientWorker {
513 let room_id = room.room_id().to_owned(); 523 let room_id = room.room_id().to_owned();
514 let room_name = Some(room_name.to_string()); 524 let room_name = Some(room_name.to_string());
515 let mut locked = store.lock().await; 525 let mut locked = store.lock().await;
516 let mut info = 526 let mut info = locked.application.rooms.get_or_default(room_id.clone());
517 locked.application.rooms.entry(room_id.to_owned()).or_default();
518 info.name = room_name; 527 info.name = room_name;
519 } 528 }
520 } 529 }
@@ -529,8 +538,6 @@ impl ClientWorker {
529 store: Ctx<AsyncProgramStore>| { 538 store: Ctx<AsyncProgramStore>| {
530 async move { 539 async move {
531 let room_id = room.room_id(); 540 let room_id = room.room_id();
532 let room_name = room.display_name().await.ok();
533 let room_name = room_name.as_ref().map(ToString::to_string);
534 541
535 if let Some(msg) = ev.as_original() { 542 if let Some(msg) = ev.as_original() {
536 if let MessageType::VerificationRequest(_) = msg.content.msgtype { 543 if let MessageType::VerificationRequest(_) = msg.content.msgtype {
@@ -545,8 +552,11 @@ impl ClientWorker {
545 } 552 }
546 553
547 let mut locked = store.lock().await; 554 let mut locked = store.lock().await;
548 let mut info = locked.application.get_room_info(room_id.to_owned()); 555
549 info.name = room_name; 556 let sender = ev.sender().to_owned();
557 let _ = locked.application.presences.get_or_default(sender);
558
559 let info = locked.application.get_room_info(room_id.to_owned());
550 info.insert(ev.into_full_event(room_id.to_owned())); 560 info.insert(ev.into_full_event(room_id.to_owned()));
551 } 561 }
552 }, 562 },
@@ -560,6 +570,10 @@ impl ClientWorker {
560 let room_id = room.room_id(); 570 let room_id = room.room_id();
561 571
562 let mut locked = store.lock().await; 572 let mut locked = store.lock().await;
573
574 let sender = ev.sender().to_owned();
575 let _ = locked.application.presences.get_or_default(sender);
576
563 let info = locked.application.get_room_info(room_id.to_owned()); 577 let info = locked.application.get_room_info(room_id.to_owned());
564 info.insert_reaction(ev.into_full_event(room_id.to_owned())); 578 info.insert_reaction(ev.into_full_event(room_id.to_owned()));
565 } 579 }