Commit 8ed037afca

8ed037afca200fe792907b12019880a3165f0211

parent: d038da6844

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-01-04 20:51 UTC

Support listing room members (#6)

Layout: unified · split

Cargo.lock +2 −2
@@ -1600,9 +1600,9 @@ dependencies = [
16001600
16011601[[package]]
16021602name = "modalkit"
1603version = "0.0.7"
1603version = "0.0.8"
16041604source = "registry+https://github.com/rust-lang/crates.io-index"
1605checksum = "dc4385b7136847cd063fbf093f0aa21a098398e26dc9213137fdd4e4f593d6bf"
1605checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba"
16061606dependencies = [
16071607 "anymap2",
16081608 "bitflags",
Cargo.toml +1 −1
@@ -19,7 +19,7 @@ dirs = "4.0.0"
1919futures = "0.3.21"
2020gethostname = "0.4.1"
2121matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]}
22modalkit = "0.0.7"
22modalkit = "0.0.8"
2323regex = "^1.5"
2424rpassword = "^7.2"
2525serde = "^1.0"
README.md +1 −1
@@ -42,7 +42,7 @@ two other TUI clients and Element Web:
4242| Room tag showing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
4343| Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
4444| Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
45| Room user list | :x: ([#6]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
45| Room user list | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
4646| Display Room Description | :x: ([#12]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
4747| Edit Room Description | :x: ([#12]) | :x: | :heavy_check_mark: | :heavy_check_mark: |
4848| Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
src/base.rs +22 −1
@@ -26,7 +26,7 @@ use modalkit::{
2626 store::Store,
2727 },
2828 env::vim::{
29 command::{VimCommand, VimCommandMachine},
29 command::{CommandContext, VimCommand, VimCommandMachine},
3030 keybindings::VimMachine,
3131 VimContext,
3232 },
@@ -59,8 +59,14 @@ pub enum VerifyAction {
5959 Mismatch,
6060}
6161
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum RoomAction {
64 Members(Box<CommandContext<ProgramContext>>),
65}
66
6267#[derive(Clone, Debug, Eq, PartialEq)]
6368pub enum IambAction {
69 Room(RoomAction),
6470 Verify(VerifyAction, String),
6571 VerifyRequest(String),
6672 SendMessage(OwnedRoomId, String),
@@ -70,6 +76,7 @@ pub enum IambAction {
7076impl ApplicationAction for IambAction {
7177 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus {
7278 match self {
79 IambAction::Room(..) => SequenceStatus::Break,
7380 IambAction::SendMessage(..) => SequenceStatus::Break,
7481 IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
7582 IambAction::Verify(..) => SequenceStatus::Break,
@@ -79,6 +86,7 @@ impl ApplicationAction for IambAction {
7986
8087 fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus {
8188 match self {
89 IambAction::Room(..) => SequenceStatus::Atom,
8290 IambAction::SendMessage(..) => SequenceStatus::Atom,
8391 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
8492 IambAction::Verify(..) => SequenceStatus::Atom,
@@ -88,6 +96,7 @@ impl ApplicationAction for IambAction {
8896
8997 fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus {
9098 match self {
99 IambAction::Room(..) => SequenceStatus::Ignore,
91100 IambAction::SendMessage(..) => SequenceStatus::Ignore,
92101 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
93102 IambAction::Verify(..) => SequenceStatus::Ignore,
@@ -97,6 +106,7 @@ impl ApplicationAction for IambAction {
97106
98107 fn is_switchable<C: EditContext>(&self, _: &C) -> bool {
99108 match self {
109 IambAction::Room(..) => false,
100110 IambAction::SendMessage(..) => false,
101111 IambAction::ToggleScrollbackFocus => false,
102112 IambAction::Verify(..) => false,
@@ -275,6 +285,14 @@ impl ChatStore {
275285 }
276286 }
277287
288 pub fn get_room_title(&self, room_id: &RoomId) -> String {
289 self.rooms
290 .get(room_id)
291 .and_then(|i| i.name.as_ref())
292 .map(String::from)
293 .unwrap_or_else(|| "Untitled Matrix Room".to_string())
294 }
295
278296 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) {
279297 self.need_load.insert(room_id);
280298 }
@@ -346,6 +364,7 @@ impl ApplicationStore for ChatStore {}
346364pub enum IambId {
347365 Room(OwnedRoomId),
348366 DirectList,
367 MemberList(OwnedRoomId),
349368 RoomList,
350369 SpaceList,
351370 VerifyList,
@@ -375,6 +394,7 @@ pub enum IambBufferId {
375394 Command,
376395 Room(OwnedRoomId, RoomFocus),
377396 DirectList,
397 MemberList(OwnedRoomId),
378398 RoomList,
379399 SpaceList,
380400 VerifyList,
@@ -387,6 +407,7 @@ impl IambBufferId {
387407 IambBufferId::Command => None,
388408 IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())),
389409 IambBufferId::DirectList => Some(IambId::DirectList),
410 IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())),
390411 IambBufferId::RoomList => Some(IambId::RoomList),
391412 IambBufferId::SpaceList => Some(IambId::SpaceList),
392413 IambBufferId::VerifyList => Some(IambId::VerifyList),
src/commands.rs +27 −12
@@ -1,5 +1,5 @@
11use modalkit::{
2 editing::{action::WindowAction, base::OpenTarget},
2 editing::base::OpenTarget,
33 env::vim::command::{CommandContext, CommandDescription},
44 input::commands::{CommandError, CommandResult, CommandStep},
55 input::InputContext,
@@ -11,6 +11,7 @@ use crate::base::{
1111 ProgramCommand,
1212 ProgramCommands,
1313 ProgramContext,
14 RoomAction,
1415 VerifyAction,
1516};
1617
@@ -22,8 +23,8 @@ fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
2223
2324 match args.len() {
2425 0 => {
25 let open = WindowAction::Switch(OpenTarget::Application(IambId::VerifyList));
26 let step = CommandStep::Continue(open.into(), ctx.context.take());
26 let open = ctx.switch(OpenTarget::Application(IambId::VerifyList));
27 let step = CommandStep::Continue(open, ctx.context.take());
2728
2829 return Ok(step);
2930 },
@@ -61,7 +62,18 @@ fn iamb_dms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
6162 return Result::Err(CommandError::InvalidArgument);
6263 }
6364
64 let open = WindowAction::Switch(OpenTarget::Application(IambId::DirectList));
65 let open = ctx.switch(OpenTarget::Application(IambId::DirectList));
66 let step = CommandStep::Continue(open, ctx.context.take());
67
68 return Ok(step);
69}
70
71fn iamb_members(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
72 if !desc.arg.text.is_empty() {
73 return Result::Err(CommandError::InvalidArgument);
74 }
75
76 let open = IambAction::Room(RoomAction::Members(ctx.clone().into()));
6577 let step = CommandStep::Continue(open.into(), ctx.context.take());
6678
6779 return Ok(step);
@@ -72,8 +84,8 @@ fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
7284 return Result::Err(CommandError::InvalidArgument);
7385 }
7486
75 let open = WindowAction::Switch(OpenTarget::Application(IambId::RoomList));
76 let step = CommandStep::Continue(open.into(), ctx.context.take());
87 let open = ctx.switch(OpenTarget::Application(IambId::RoomList));
88 let step = CommandStep::Continue(open, ctx.context.take());
7789
7890 return Ok(step);
7991}
@@ -83,8 +95,8 @@ fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
8395 return Result::Err(CommandError::InvalidArgument);
8496 }
8597
86 let open = WindowAction::Switch(OpenTarget::Application(IambId::SpaceList));
87 let step = CommandStep::Continue(open.into(), ctx.context.take());
98 let open = ctx.switch(OpenTarget::Application(IambId::SpaceList));
99 let step = CommandStep::Continue(open, ctx.context.take());
88100
89101 return Ok(step);
90102}
@@ -94,8 +106,8 @@ fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
94106 return Result::Err(CommandError::InvalidArgument);
95107 }
96108
97 let open = WindowAction::Switch(OpenTarget::Application(IambId::Welcome));
98 let step = CommandStep::Continue(open.into(), ctx.context.take());
109 let open = ctx.switch(OpenTarget::Application(IambId::Welcome));
110 let step = CommandStep::Continue(open, ctx.context.take());
99111
100112 return Ok(step);
101113}
@@ -107,8 +119,8 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
107119 return Result::Err(CommandError::InvalidArgument);
108120 }
109121
110 let open = WindowAction::Switch(args.remove(0));
111 let step = CommandStep::Continue(open.into(), ctx.context.take());
122 let open = ctx.switch(args.remove(0));
123 let step = CommandStep::Continue(open, ctx.context.take());
112124
113125 return Ok(step);
114126}
@@ -116,6 +128,7 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
116128fn add_iamb_commands(cmds: &mut ProgramCommands) {
117129 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
118130 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
131 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
119132 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms });
120133 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
121134 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
@@ -133,6 +146,8 @@ pub fn setup_commands() -> ProgramCommands {
133146#[cfg(test)]
134147mod tests {
135148 use super::*;
149 use modalkit::editing::action::WindowAction;
150
136151 #[test]
137152 fn test_cmd_verify() {
138153 let mut cmds = setup_commands();
src/main.rs +8 −1
@@ -317,7 +317,7 @@ impl Application {
317317 fn iamb_run(
318318 &mut self,
319319 action: IambAction,
320 _: ProgramContext,
320 ctx: ProgramContext,
321321 store: &mut ProgramStore,
322322 ) -> IambResult<EditInfo> {
323323 let info = match action {
@@ -327,6 +327,13 @@ impl Application {
327327 None
328328 },
329329
330 IambAction::Room(act) => {
331 let acts = self.screen.current_window_mut()?.room_command(act, ctx, store)?;
332 self.action_prepend(acts);
333
334 None
335 },
336
330337 IambAction::SendMessage(room_id, msg) => {
331338 let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?;
332339 let user = store.application.settings.profile.user_id.clone();
src/windows/mod.rs +189 −19
@@ -3,22 +3,23 @@ use std::collections::hash_map::Entry;
33
44use matrix_sdk::{
55 encryption::verification::{format_emojis, SasVerification},
6 room::Room as MatrixRoom,
7 ruma::RoomId,
6 room::{Room as MatrixRoom, RoomMember},
7 ruma::{events::room::member::MembershipState, OwnedRoomId, RoomId},
88 DisplayName,
99};
1010
1111use modalkit::tui::{
1212 buffer::Buffer,
13 layout::Rect,
13 layout::{Alignment, Rect},
1414 style::{Modifier as StyleModifier, Style},
1515 text::{Span, Spans, Text},
16 widgets::{Block, Borders, Widget},
16 widgets::{Block, Borders, StatefulWidget, Widget},
1717};
1818
1919use modalkit::{
2020 editing::{
2121 action::{
22 Action,
2223 EditError,
2324 EditInfo,
2425 EditResult,
@@ -42,7 +43,7 @@ use modalkit::{
4243 },
4344 },
4445 widgets::{
45 list::{ListCursor, ListItem, ListState},
46 list::{List, ListCursor, ListItem, ListState},
4647 TermOffset,
4748 TerminalCursor,
4849 Window,
@@ -50,15 +51,19 @@ use modalkit::{
5051 },
5152};
5253
53use super::base::{
54 ChatStore,
55 IambBufferId,
56 IambId,
57 IambInfo,
58 IambResult,
59 ProgramAction,
60 ProgramContext,
61 ProgramStore,
54use crate::{
55 base::{
56 ChatStore,
57 IambBufferId,
58 IambId,
59 IambInfo,
60 IambResult,
61 ProgramAction,
62 ProgramContext,
63 ProgramStore,
64 RoomAction,
65 },
66 message::user_style,
6267};
6368
6469use self::{room::RoomState, welcome::WelcomeState};
@@ -120,6 +125,7 @@ macro_rules! delegate {
120125 match $s {
121126 IambWindow::Room($id) => $e,
122127 IambWindow::DirectList($id) => $e,
128 IambWindow::MemberList($id, _) => $e,
123129 IambWindow::RoomList($id) => $e,
124130 IambWindow::SpaceList($id) => $e,
125131 IambWindow::VerifyList($id) => $e,
@@ -130,6 +136,7 @@ macro_rules! delegate {
130136
131137pub enum IambWindow {
132138 DirectList(DirectListState),
139 MemberList(MemberListState, OwnedRoomId),
133140 Room(RoomState),
134141 VerifyList(VerifyListState),
135142 RoomList(RoomListState),
@@ -146,19 +153,41 @@ impl IambWindow {
146153 }
147154 }
148155
156 pub fn room_command(
157 &mut self,
158 act: RoomAction,
159 ctx: ProgramContext,
160 store: &mut ProgramStore,
161 ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
162 if let IambWindow::Room(w) = self {
163 w.room_command(act, ctx, store)
164 } else {
165 let msg = "No room currently focused!";
166 let err = UIError::Failure(msg.into());
167
168 return Err(err);
169 }
170 }
171
149172 pub fn get_title(&self, store: &mut ProgramStore) -> String {
150173 match self {
151 IambWindow::Room(w) => w.get_title(store),
152174 IambWindow::DirectList(_) => "Direct Messages".to_string(),
153175 IambWindow::RoomList(_) => "Rooms".to_string(),
154176 IambWindow::SpaceList(_) => "Spaces".to_string(),
155177 IambWindow::VerifyList(_) => "Verifications".to_string(),
156178 IambWindow::Welcome(_) => "Welcome to iamb".to_string(),
179
180 IambWindow::Room(w) => w.get_title(store),
181 IambWindow::MemberList(_, room_id) => {
182 let title = store.application.get_room_title(room_id.as_ref());
183 format!("Room Members: {}", title)
184 },
157185 }
158186 }
159187}
160188
161189pub type DirectListState = ListState<DirectItem, IambInfo>;
190pub type MemberListState = ListState<MemberItem, IambInfo>;
162191pub type RoomListState = ListState<RoomItem, IambInfo>;
163192pub type SpaceListState = ListState<SpaceItem, IambInfo>;
164193pub type VerifyListState = ListState<VerifyItem, IambInfo>;
@@ -263,13 +292,35 @@ impl WindowOps<IambInfo> for IambWindow {
263292 let dms = store.application.worker.direct_messages();
264293 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store));
265294 state.set(items.collect());
266 state.draw(inner, buf, focused, store);
295
296 List::new(store)
297 .empty_message("No direct messages yet!")
298 .empty_alignment(Alignment::Center)
299 .focus(focused)
300 .render(inner, buf, state);
301 },
302 IambWindow::MemberList(state, room_id) => {
303 if let Ok(mems) = store.application.worker.members(room_id.clone()) {
304 let items = mems.into_iter().map(MemberItem::new);
305 state.set(items.collect());
306 }
307
308 List::new(store)
309 .empty_message("No users here yet!")
310 .empty_alignment(Alignment::Center)
311 .focus(focused)
312 .render(inner, buf, state);
267313 },
268314 IambWindow::RoomList(state) => {
269315 let joined = store.application.worker.joined_rooms();
270316 let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store));
271317 state.set(items.collect());
272 state.draw(inner, buf, focused, store);
318
319 List::new(store)
320 .empty_message("You haven't joined any rooms yet")
321 .empty_alignment(Alignment::Center)
322 .focus(focused)
323 .render(inner, buf, state);
273324 },
274325 IambWindow::SpaceList(state) => {
275326 let spaces = store.application.worker.spaces();
@@ -277,6 +328,12 @@ impl WindowOps<IambInfo> for IambWindow {
277328 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store));
278329 state.set(items.collect());
279330 state.draw(inner, buf, focused, store);
331
332 List::new(store)
333 .empty_message("You haven't joined any spaces yet")
334 .empty_alignment(Alignment::Center)
335 .focus(focused)
336 .render(inner, buf, state);
280337 },
281338 IambWindow::VerifyList(state) => {
282339 let verifications = &store.application.verifications;
@@ -286,14 +343,29 @@ impl WindowOps<IambInfo> for IambWindow {
286343 items.sort();
287344
288345 state.set(items);
289 state.draw(inner, buf, focused, store);
346
347 List::new(store)
348 .empty_message("No in-progress verifications")
349 .empty_alignment(Alignment::Center)
350 .focus(focused)
351 .render(inner, buf, state);
290352 },
291353 IambWindow::Welcome(state) => state.draw(inner, buf, focused, store),
292354 }
293355 }
294356
295357 fn dup(&self, store: &mut ProgramStore) -> Self {
296 delegate!(self, w => w.dup(store).into())
358 match self {
359 IambWindow::Room(w) => w.dup(store).into(),
360 IambWindow::DirectList(w) => w.dup(store).into(),
361 IambWindow::MemberList(w, room_id) => {
362 IambWindow::MemberList(w.dup(store), room_id.clone())
363 },
364 IambWindow::RoomList(w) => w.dup(store).into(),
365 IambWindow::SpaceList(w) => w.dup(store).into(),
366 IambWindow::VerifyList(w) => w.dup(store).into(),
367 IambWindow::Welcome(w) => w.dup(store).into(),
368 }
297369 }
298370
299371 fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
@@ -314,6 +386,7 @@ impl Window<IambInfo> for IambWindow {
314386 match self {
315387 IambWindow::Room(room) => IambId::Room(room.id().to_owned()),
316388 IambWindow::DirectList(_) => IambId::DirectList,
389 IambWindow::MemberList(_, room_id) => IambId::MemberList(room_id.clone()),
317390 IambWindow::RoomList(_) => IambId::RoomList,
318391 IambWindow::SpaceList(_) => IambId::SpaceList,
319392 IambWindow::VerifyList(_) => IambId::VerifyList,
@@ -334,6 +407,13 @@ impl Window<IambInfo> for IambWindow {
334407
335408 return Ok(list.into());
336409 },
410 IambId::MemberList(room_id) => {
411 let id = IambBufferId::MemberList(room_id.clone());
412 let list = MemberListState::new(id, vec![]);
413 let win = IambWindow::MemberList(list, room_id);
414
415 return Ok(win);
416 },
337417 IambId::RoomList => {
338418 let list = RoomListState::new(IambBufferId::RoomList, vec![]);
339419
@@ -412,6 +492,10 @@ impl ListItem<IambInfo> for RoomItem {
412492 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
413493 selected_text(self.name.as_str(), selected)
414494 }
495
496 fn get_word(&self) -> Option<String> {
497 self.room.room_id().to_string().into()
498 }
415499}
416500
417501impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem {
@@ -451,6 +535,10 @@ impl ListItem<IambInfo> for DirectItem {
451535 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
452536 selected_text(self.name.as_str(), selected)
453537 }
538
539 fn get_word(&self) -> Option<String> {
540 self.room.room_id().to_string().into()
541 }
454542}
455543
456544impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem {
@@ -490,6 +578,10 @@ impl ListItem<IambInfo> for SpaceItem {
490578 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
491579 selected_text(self.name.as_str(), selected)
492580 }
581
582 fn get_word(&self) -> Option<String> {
583 self.room.room_id().to_string().into()
584 }
493585}
494586
495587impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem {
@@ -667,6 +759,10 @@ impl ListItem<IambInfo> for VerifyItem {
667759
668760 Text { lines }
669761 }
762
763 fn get_word(&self) -> Option<String> {
764 None
765 }
670766}
671767
672768impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem {
@@ -694,3 +790,77 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem {
694790 }
695791 }
696792}
793
794#[derive(Clone)]
795pub struct MemberItem {
796 member: RoomMember,
797}
798
799impl MemberItem {
800 fn new(member: RoomMember) -> Self {
801 Self { member }
802 }
803}
804
805impl ToString for MemberItem {
806 fn to_string(&self) -> String {
807 self.member.user_id().to_string()
808 }
809}
810
811impl ListItem<IambInfo> for MemberItem {
812 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
813 let mut style = user_style(self.member.user_id().as_str());
814
815 if selected {
816 style = style.add_modifier(StyleModifier::REVERSED);
817 }
818
819 let user = Span::styled(self.to_string(), style);
820
821 let state = match self.member.membership() {
822 MembershipState::Ban => Span::raw(" (banned)").into(),
823 MembershipState::Invite => Span::raw(" (invited)").into(),
824 MembershipState::Knock => Span::raw(" (wants to join)").into(),
825 MembershipState::Leave => Span::raw(" (left)").into(),
826 MembershipState::Join => None,
827 _ => None,
828 };
829
830 if let Some(state) = state {
831 Spans(vec![user, state]).into()
832 } else {
833 user.into()
834 }
835 }
836
837 fn get_word(&self) -> Option<String> {
838 self.member.user_id().to_string().into()
839 }
840}
841
842impl Promptable<ProgramContext, ProgramStore, IambInfo> for MemberItem {
843 fn prompt(
844 &mut self,
845 act: &PromptAction,
846 _: &ProgramContext,
847 _: &mut ProgramStore,
848 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
849 match act {
850 PromptAction::Submit => Ok(vec![]),
851 PromptAction::Abort(_) => {
852 let msg = "Cannot abort entry inside a list";
853 let err = EditError::Failure(msg.into());
854
855 Err(err)
856 },
857 PromptAction::Recall(_, _) => {
858 let msg = "Cannot recall history inside a list";
859 let err = EditError::Failure(msg.into());
860
861 Err(err)
862 },
863 _ => Err(EditError::Unimplemented("unknown prompt action".to_string())),
864 }
865 }
866}
src/windows/room/chat.rs −4
@@ -94,10 +94,6 @@ impl ChatState {
9494 return;
9595 }
9696
97 if matches!(act, EditorAction::History(_)) {
98 return;
99 }
100
10197 if !store.application.settings.tunables.typing_notice {
10298 return;
10399 }
src/windows/room/mod.rs +42 −9
@@ -6,6 +6,7 @@ use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget};
66
77use modalkit::{
88 editing::action::{
9 Action,
910 EditInfo,
1011 EditResult,
1112 Editable,
@@ -15,11 +16,29 @@ use modalkit::{
1516 Promptable,
1617 Scrollable,
1718 },
18 editing::base::{CloseFlags, MoveDir1D, PositionList, ScrollStyle, WordStyle},
19 editing::base::{
20 Axis,
21 CloseFlags,
22 Count,
23 MoveDir1D,
24 OpenTarget,
25 PositionList,
26 ScrollStyle,
27 WordStyle,
28 },
29 input::InputContext,
1930 widgets::{TermOffset, TerminalCursor, WindowOps},
2031};
2132
22use crate::base::{IambInfo, IambResult, ProgramAction, ProgramContext, ProgramStore};
33use crate::base::{
34 IambId,
35 IambInfo,
36 IambResult,
37 ProgramAction,
38 ProgramContext,
39 ProgramStore,
40 RoomAction,
41};
2342
2443use self::chat::ChatState;
2544use self::space::{Space, SpaceState};
@@ -67,14 +86,28 @@ impl RoomState {
6786 }
6887 }
6988
89 pub fn room_command(
90 &mut self,
91 act: RoomAction,
92 _: ProgramContext,
93 _: &mut ProgramStore,
94 ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
95 match act {
96 RoomAction::Members(mut cmd) => {
97 let width = Count::Exact(30);
98 let act =
99 cmd.default_axis(Axis::Vertical).default_relation(MoveDir1D::Next).window(
100 OpenTarget::Application(IambId::MemberList(self.id().to_owned())),
101 width.into(),
102 );
103
104 Ok(vec![(act, cmd.context.take())])
105 },
106 }
107 }
108
70109 pub fn get_title(&self, store: &mut ProgramStore) -> String {
71 store
72 .application
73 .rooms
74 .get(self.id())
75 .and_then(|i| i.name.as_ref())
76 .map(String::from)
77 .unwrap_or_else(|| "Untitled Matrix Room".to_string())
110 store.application.get_room_title(self.id())
78111 }
79112
80113 pub fn focus_toggle(&mut self) {
src/windows/welcome.md +2 −1
@@ -3,8 +3,8 @@
33## Useful Keybindings
44
55- `<Enter>` will send a typed message
6- `^V^J` can be used in Insert mode to enter a newline without submitting
67- `O`/`o` can be used to insert blank lines before and after the cursor line
7- `^O` can be used in Insert mode to enter a single Normal mode keybinding sequence
88- `^Wm` can be used to toggle whether the message bar or scrollback is selected
99- `^Wz` can be used to toggle whether the current window takes up the full screen
1010
@@ -12,6 +12,7 @@
1212
1313- `:dms` will open a list of direct messages
1414- `:rooms` will open a list of joined rooms
15- `:members` will open a list of members for the currently focused room or space
1516- `:spaces` will open a list of joined spaces
1617- `:join` can be used to switch to join a new room or start a direct message
1718- `:split` and `:vsplit` can be used to open rooms in a new window
src/worker.rs +22 −1
@@ -15,7 +15,7 @@ use matrix_sdk::{
1515 encryption::verification::{SasVerification, Verification},
1616 event_handler::Ctx,
1717 reqwest,
18 room::{Messages, MessagesOptions, Room as MatrixRoom},
18 room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember},
1919 ruma::{
2020 api::client::{
2121 room::create_room::v3::{Request as CreateRoomRequest, RoomPreset},
@@ -102,6 +102,7 @@ pub enum WorkerTask {
102102 GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>),
103103 JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>),
104104 JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
105 Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>),
105106 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>),
106107 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
107108 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>),
@@ -187,6 +188,14 @@ impl Requester {
187188 return response.recv();
188189 }
189190
191 pub fn members(&self, room_id: OwnedRoomId) -> IambResult<Vec<RoomMember>> {
192 let (reply, response) = oneshot();
193
194 self.tx.send(WorkerTask::Members(room_id, reply)).unwrap();
195
196 return response.recv();
197 }
198
190199 pub fn space_members(&self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
191200 let (reply, response) = oneshot();
192201
@@ -327,6 +336,10 @@ impl ClientWorker {
327336 assert!(self.initialized);
328337 reply.send(self.login_and_sync(style).await);
329338 },
339 WorkerTask::Members(room_id, reply) => {
340 assert!(self.initialized);
341 reply.send(self.members(room_id).await);
342 },
330343 WorkerTask::SpaceMembers(space, reply) => {
331344 assert!(self.initialized);
332345 reply.send(self.space_members(space).await);
@@ -744,6 +757,14 @@ impl ClientWorker {
744757 }
745758 }
746759
760 async fn members(&mut self, room_id: OwnedRoomId) -> IambResult<Vec<RoomMember>> {
761 if let Some(room) = self.client.get_room(room_id.as_ref()) {
762 Ok(room.active_members().await.map_err(IambError::from)?)
763 } else {
764 Err(IambError::UnknownRoom(room_id).into())
765 }
766 }
767
747768 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
748769 let mut req = SpaceHierarchyRequest::new(&space);
749770 req.limit = Some(1000u32.into());