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 = [
1600 1600
1601[[package]] 1601[[package]]
1602name = "modalkit" 1602name = "modalkit"
1603version = "0.0.7" 1603version = "0.0.8"
1604source = "registry+https://github.com/rust-lang/crates.io-index" 1604source = "registry+https://github.com/rust-lang/crates.io-index"
1605checksum = "dc4385b7136847cd063fbf093f0aa21a098398e26dc9213137fdd4e4f593d6bf" 1605checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba"
1606dependencies = [ 1606dependencies = [
1607 "anymap2", 1607 "anymap2",
1608 "bitflags", 1608 "bitflags",
Cargo.toml +1 −1
@@ -19,7 +19,7 @@ dirs = "4.0.0"
19futures = "0.3.21" 19futures = "0.3.21"
20gethostname = "0.4.1" 20gethostname = "0.4.1"
21matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]} 21matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]}
22modalkit = "0.0.7" 22modalkit = "0.0.8"
23regex = "^1.5" 23regex = "^1.5"
24rpassword = "^7.2" 24rpassword = "^7.2"
25serde = "^1.0" 25serde = "^1.0"
README.md +1 −1
@@ -42,7 +42,7 @@ two other TUI clients and Element Web:
42| Room tag showing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: | 42| Room tag showing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
43| Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: | 43| Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
44| Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: | 44| 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: |
46| Display Room Description | :x: ([#12]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 46| Display Room Description | :x: ([#12]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
47| Edit Room Description | :x: ([#12]) | :x: | :heavy_check_mark: | :heavy_check_mark: | 47| Edit Room Description | :x: ([#12]) | :x: | :heavy_check_mark: | :heavy_check_mark: |
48| Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 48| Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
src/base.rs +22 −1
@@ -26,7 +26,7 @@ use modalkit::{
26 store::Store, 26 store::Store,
27 }, 27 },
28 env::vim::{ 28 env::vim::{
29 command::{VimCommand, VimCommandMachine}, 29 command::{CommandContext, VimCommand, VimCommandMachine},
30 keybindings::VimMachine, 30 keybindings::VimMachine,
31 VimContext, 31 VimContext,
32 }, 32 },
@@ -59,8 +59,14 @@ pub enum VerifyAction {
59 Mismatch, 59 Mismatch,
60} 60}
61 61
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum RoomAction {
64 Members(Box<CommandContext<ProgramContext>>),
65}
66
62#[derive(Clone, Debug, Eq, PartialEq)] 67#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum IambAction { 68pub enum IambAction {
69 Room(RoomAction),
64 Verify(VerifyAction, String), 70 Verify(VerifyAction, String),
65 VerifyRequest(String), 71 VerifyRequest(String),
66 SendMessage(OwnedRoomId, String), 72 SendMessage(OwnedRoomId, String),
@@ -70,6 +76,7 @@ pub enum IambAction {
70impl ApplicationAction for IambAction { 76impl ApplicationAction for IambAction {
71 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { 77 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus {
72 match self { 78 match self {
79 IambAction::Room(..) => SequenceStatus::Break,
73 IambAction::SendMessage(..) => SequenceStatus::Break, 80 IambAction::SendMessage(..) => SequenceStatus::Break,
74 IambAction::ToggleScrollbackFocus => SequenceStatus::Break, 81 IambAction::ToggleScrollbackFocus => SequenceStatus::Break,
75 IambAction::Verify(..) => SequenceStatus::Break, 82 IambAction::Verify(..) => SequenceStatus::Break,
@@ -79,6 +86,7 @@ impl ApplicationAction for IambAction {
79 86
80 fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus { 87 fn is_last_action<C: EditContext>(&self, _: &C) -> SequenceStatus {
81 match self { 88 match self {
89 IambAction::Room(..) => SequenceStatus::Atom,
82 IambAction::SendMessage(..) => SequenceStatus::Atom, 90 IambAction::SendMessage(..) => SequenceStatus::Atom,
83 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, 91 IambAction::ToggleScrollbackFocus => SequenceStatus::Atom,
84 IambAction::Verify(..) => SequenceStatus::Atom, 92 IambAction::Verify(..) => SequenceStatus::Atom,
@@ -88,6 +96,7 @@ impl ApplicationAction for IambAction {
88 96
89 fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus { 97 fn is_last_selection<C: EditContext>(&self, _: &C) -> SequenceStatus {
90 match self { 98 match self {
99 IambAction::Room(..) => SequenceStatus::Ignore,
91 IambAction::SendMessage(..) => SequenceStatus::Ignore, 100 IambAction::SendMessage(..) => SequenceStatus::Ignore,
92 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, 101 IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore,
93 IambAction::Verify(..) => SequenceStatus::Ignore, 102 IambAction::Verify(..) => SequenceStatus::Ignore,
@@ -97,6 +106,7 @@ impl ApplicationAction for IambAction {
97 106
98 fn is_switchable<C: EditContext>(&self, _: &C) -> bool { 107 fn is_switchable<C: EditContext>(&self, _: &C) -> bool {
99 match self { 108 match self {
109 IambAction::Room(..) => false,
100 IambAction::SendMessage(..) => false, 110 IambAction::SendMessage(..) => false,
101 IambAction::ToggleScrollbackFocus => false, 111 IambAction::ToggleScrollbackFocus => false,
102 IambAction::Verify(..) => false, 112 IambAction::Verify(..) => false,
@@ -275,6 +285,14 @@ impl ChatStore {
275 } 285 }
276 } 286 }
277 287
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
278 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) { 296 pub fn mark_for_load(&mut self, room_id: OwnedRoomId) {
279 self.need_load.insert(room_id); 297 self.need_load.insert(room_id);
280 } 298 }
@@ -346,6 +364,7 @@ impl ApplicationStore for ChatStore {}
346pub enum IambId { 364pub enum IambId {
347 Room(OwnedRoomId), 365 Room(OwnedRoomId),
348 DirectList, 366 DirectList,
367 MemberList(OwnedRoomId),
349 RoomList, 368 RoomList,
350 SpaceList, 369 SpaceList,
351 VerifyList, 370 VerifyList,
@@ -375,6 +394,7 @@ pub enum IambBufferId {
375 Command, 394 Command,
376 Room(OwnedRoomId, RoomFocus), 395 Room(OwnedRoomId, RoomFocus),
377 DirectList, 396 DirectList,
397 MemberList(OwnedRoomId),
378 RoomList, 398 RoomList,
379 SpaceList, 399 SpaceList,
380 VerifyList, 400 VerifyList,
@@ -387,6 +407,7 @@ impl IambBufferId {
387 IambBufferId::Command => None, 407 IambBufferId::Command => None,
388 IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())), 408 IambBufferId::Room(room, _) => Some(IambId::Room(room.clone())),
389 IambBufferId::DirectList => Some(IambId::DirectList), 409 IambBufferId::DirectList => Some(IambId::DirectList),
410 IambBufferId::MemberList(room) => Some(IambId::MemberList(room.clone())),
390 IambBufferId::RoomList => Some(IambId::RoomList), 411 IambBufferId::RoomList => Some(IambId::RoomList),
391 IambBufferId::SpaceList => Some(IambId::SpaceList), 412 IambBufferId::SpaceList => Some(IambId::SpaceList),
392 IambBufferId::VerifyList => Some(IambId::VerifyList), 413 IambBufferId::VerifyList => Some(IambId::VerifyList),
src/commands.rs +27 −12
@@ -1,5 +1,5 @@
1use modalkit::{ 1use modalkit::{
2 editing::{action::WindowAction, base::OpenTarget}, 2 editing::base::OpenTarget,
3 env::vim::command::{CommandContext, CommandDescription}, 3 env::vim::command::{CommandContext, CommandDescription},
4 input::commands::{CommandError, CommandResult, CommandStep}, 4 input::commands::{CommandError, CommandResult, CommandStep},
5 input::InputContext, 5 input::InputContext,
@@ -11,6 +11,7 @@ use crate::base::{
11 ProgramCommand, 11 ProgramCommand,
12 ProgramCommands, 12 ProgramCommands,
13 ProgramContext, 13 ProgramContext,
14 RoomAction,
14 VerifyAction, 15 VerifyAction,
15}; 16};
16 17
@@ -22,8 +23,8 @@ fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
22 23
23 match args.len() { 24 match args.len() {
24 0 => { 25 0 => {
25 let open = WindowAction::Switch(OpenTarget::Application(IambId::VerifyList)); 26 let open = ctx.switch(OpenTarget::Application(IambId::VerifyList));
26 let step = CommandStep::Continue(open.into(), ctx.context.take()); 27 let step = CommandStep::Continue(open, ctx.context.take());
27 28
28 return Ok(step); 29 return Ok(step);
29 }, 30 },
@@ -61,7 +62,18 @@ fn iamb_dms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
61 return Result::Err(CommandError::InvalidArgument); 62 return Result::Err(CommandError::InvalidArgument);
62 } 63 }
63 64
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()));
65 let step = CommandStep::Continue(open.into(), ctx.context.take()); 77 let step = CommandStep::Continue(open.into(), ctx.context.take());
66 78
67 return Ok(step); 79 return Ok(step);
@@ -72,8 +84,8 @@ fn iamb_rooms(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
72 return Result::Err(CommandError::InvalidArgument); 84 return Result::Err(CommandError::InvalidArgument);
73 } 85 }
74 86
75 let open = WindowAction::Switch(OpenTarget::Application(IambId::RoomList)); 87 let open = ctx.switch(OpenTarget::Application(IambId::RoomList));
76 let step = CommandStep::Continue(open.into(), ctx.context.take()); 88 let step = CommandStep::Continue(open, ctx.context.take());
77 89
78 return Ok(step); 90 return Ok(step);
79} 91}
@@ -83,8 +95,8 @@ fn iamb_spaces(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
83 return Result::Err(CommandError::InvalidArgument); 95 return Result::Err(CommandError::InvalidArgument);
84 } 96 }
85 97
86 let open = WindowAction::Switch(OpenTarget::Application(IambId::SpaceList)); 98 let open = ctx.switch(OpenTarget::Application(IambId::SpaceList));
87 let step = CommandStep::Continue(open.into(), ctx.context.take()); 99 let step = CommandStep::Continue(open, ctx.context.take());
88 100
89 return Ok(step); 101 return Ok(step);
90} 102}
@@ -94,8 +106,8 @@ fn iamb_welcome(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
94 return Result::Err(CommandError::InvalidArgument); 106 return Result::Err(CommandError::InvalidArgument);
95 } 107 }
96 108
97 let open = WindowAction::Switch(OpenTarget::Application(IambId::Welcome)); 109 let open = ctx.switch(OpenTarget::Application(IambId::Welcome));
98 let step = CommandStep::Continue(open.into(), ctx.context.take()); 110 let step = CommandStep::Continue(open, ctx.context.take());
99 111
100 return Ok(step); 112 return Ok(step);
101} 113}
@@ -107,8 +119,8 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
107 return Result::Err(CommandError::InvalidArgument); 119 return Result::Err(CommandError::InvalidArgument);
108 } 120 }
109 121
110 let open = WindowAction::Switch(args.remove(0)); 122 let open = ctx.switch(args.remove(0));
111 let step = CommandStep::Continue(open.into(), ctx.context.take()); 123 let step = CommandStep::Continue(open, ctx.context.take());
112 124
113 return Ok(step); 125 return Ok(step);
114} 126}
@@ -116,6 +128,7 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
116fn add_iamb_commands(cmds: &mut ProgramCommands) { 128fn add_iamb_commands(cmds: &mut ProgramCommands) {
117 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); 129 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
118 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); 130 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
131 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
119 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); 132 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms });
120 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); 133 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
121 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); 134 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
@@ -133,6 +146,8 @@ pub fn setup_commands() -> ProgramCommands {
133#[cfg(test)] 146#[cfg(test)]
134mod tests { 147mod tests {
135 use super::*; 148 use super::*;
149 use modalkit::editing::action::WindowAction;
150
136 #[test] 151 #[test]
137 fn test_cmd_verify() { 152 fn test_cmd_verify() {
138 let mut cmds = setup_commands(); 153 let mut cmds = setup_commands();
src/main.rs +8 −1
@@ -317,7 +317,7 @@ impl Application {
317 fn iamb_run( 317 fn iamb_run(
318 &mut self, 318 &mut self,
319 action: IambAction, 319 action: IambAction,
320 _: ProgramContext, 320 ctx: ProgramContext,
321 store: &mut ProgramStore, 321 store: &mut ProgramStore,
322 ) -> IambResult<EditInfo> { 322 ) -> IambResult<EditInfo> {
323 let info = match action { 323 let info = match action {
@@ -327,6 +327,13 @@ impl Application {
327 None 327 None
328 }, 328 },
329 329
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
330 IambAction::SendMessage(room_id, msg) => { 337 IambAction::SendMessage(room_id, msg) => {
331 let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?; 338 let (event_id, msg) = self.worker.send_message(room_id.clone(), msg)?;
332 let user = store.application.settings.profile.user_id.clone(); 339 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;
3 3
4use matrix_sdk::{ 4use matrix_sdk::{
5 encryption::verification::{format_emojis, SasVerification}, 5 encryption::verification::{format_emojis, SasVerification},
6 room::Room as MatrixRoom, 6 room::{Room as MatrixRoom, RoomMember},
7 ruma::RoomId, 7 ruma::{events::room::member::MembershipState, OwnedRoomId, RoomId},
8 DisplayName, 8 DisplayName,
9}; 9};
10 10
11use modalkit::tui::{ 11use modalkit::tui::{
12 buffer::Buffer, 12 buffer::Buffer,
13 layout::Rect, 13 layout::{Alignment, Rect},
14 style::{Modifier as StyleModifier, Style}, 14 style::{Modifier as StyleModifier, Style},
15 text::{Span, Spans, Text}, 15 text::{Span, Spans, Text},
16 widgets::{Block, Borders, Widget}, 16 widgets::{Block, Borders, StatefulWidget, Widget},
17}; 17};
18 18
19use modalkit::{ 19use modalkit::{
20 editing::{ 20 editing::{
21 action::{ 21 action::{
22 Action,
22 EditError, 23 EditError,
23 EditInfo, 24 EditInfo,
24 EditResult, 25 EditResult,
@@ -42,7 +43,7 @@ use modalkit::{
42 }, 43 },
43 }, 44 },
44 widgets::{ 45 widgets::{
45 list::{ListCursor, ListItem, ListState}, 46 list::{List, ListCursor, ListItem, ListState},
46 TermOffset, 47 TermOffset,
47 TerminalCursor, 48 TerminalCursor,
48 Window, 49 Window,
@@ -50,15 +51,19 @@ use modalkit::{
50 }, 51 },
51}; 52};
52 53
53use super::base::{ 54use crate::{
54 ChatStore, 55 base::{
55 IambBufferId, 56 ChatStore,
56 IambId, 57 IambBufferId,
57 IambInfo, 58 IambId,
58 IambResult, 59 IambInfo,
59 ProgramAction, 60 IambResult,
60 ProgramContext, 61 ProgramAction,
61 ProgramStore, 62 ProgramContext,
63 ProgramStore,
64 RoomAction,
65 },
66 message::user_style,
62}; 67};
63 68
64use self::{room::RoomState, welcome::WelcomeState}; 69use self::{room::RoomState, welcome::WelcomeState};
@@ -120,6 +125,7 @@ macro_rules! delegate {
120 match $s { 125 match $s {
121 IambWindow::Room($id) => $e, 126 IambWindow::Room($id) => $e,
122 IambWindow::DirectList($id) => $e, 127 IambWindow::DirectList($id) => $e,
128 IambWindow::MemberList($id, _) => $e,
123 IambWindow::RoomList($id) => $e, 129 IambWindow::RoomList($id) => $e,
124 IambWindow::SpaceList($id) => $e, 130 IambWindow::SpaceList($id) => $e,
125 IambWindow::VerifyList($id) => $e, 131 IambWindow::VerifyList($id) => $e,
@@ -130,6 +136,7 @@ macro_rules! delegate {
130 136
131pub enum IambWindow { 137pub enum IambWindow {
132 DirectList(DirectListState), 138 DirectList(DirectListState),
139 MemberList(MemberListState, OwnedRoomId),
133 Room(RoomState), 140 Room(RoomState),
134 VerifyList(VerifyListState), 141 VerifyList(VerifyListState),
135 RoomList(RoomListState), 142 RoomList(RoomListState),
@@ -146,19 +153,41 @@ impl IambWindow {
146 } 153 }
147 } 154 }
148 155
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
149 pub fn get_title(&self, store: &mut ProgramStore) -> String { 172 pub fn get_title(&self, store: &mut ProgramStore) -> String {
150 match self { 173 match self {
151 IambWindow::Room(w) => w.get_title(store),
152 IambWindow::DirectList(_) => "Direct Messages".to_string(), 174 IambWindow::DirectList(_) => "Direct Messages".to_string(),
153 IambWindow::RoomList(_) => "Rooms".to_string(), 175 IambWindow::RoomList(_) => "Rooms".to_string(),
154 IambWindow::SpaceList(_) => "Spaces".to_string(), 176 IambWindow::SpaceList(_) => "Spaces".to_string(),
155 IambWindow::VerifyList(_) => "Verifications".to_string(), 177 IambWindow::VerifyList(_) => "Verifications".to_string(),
156 IambWindow::Welcome(_) => "Welcome to iamb".to_string(), 178 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 },
157 } 185 }
158 } 186 }
159} 187}
160 188
161pub type DirectListState = ListState<DirectItem, IambInfo>; 189pub type DirectListState = ListState<DirectItem, IambInfo>;
190pub type MemberListState = ListState<MemberItem, IambInfo>;
162pub type RoomListState = ListState<RoomItem, IambInfo>; 191pub type RoomListState = ListState<RoomItem, IambInfo>;
163pub type SpaceListState = ListState<SpaceItem, IambInfo>; 192pub type SpaceListState = ListState<SpaceItem, IambInfo>;
164pub type VerifyListState = ListState<VerifyItem, IambInfo>; 193pub type VerifyListState = ListState<VerifyItem, IambInfo>;
@@ -263,13 +292,35 @@ impl WindowOps<IambInfo> for IambWindow {
263 let dms = store.application.worker.direct_messages(); 292 let dms = store.application.worker.direct_messages();
264 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store)); 293 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store));
265 state.set(items.collect()); 294 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);
267 }, 313 },
268 IambWindow::RoomList(state) => { 314 IambWindow::RoomList(state) => {
269 let joined = store.application.worker.joined_rooms(); 315 let joined = store.application.worker.joined_rooms();
270 let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store)); 316 let items = joined.into_iter().map(|(id, name)| RoomItem::new(id, name, store));
271 state.set(items.collect()); 317 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);
273 }, 324 },
274 IambWindow::SpaceList(state) => { 325 IambWindow::SpaceList(state) => {
275 let spaces = store.application.worker.spaces(); 326 let spaces = store.application.worker.spaces();
@@ -277,6 +328,12 @@ impl WindowOps<IambInfo> for IambWindow {
277 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store)); 328 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store));
278 state.set(items.collect()); 329 state.set(items.collect());
279 state.draw(inner, buf, focused, store); 330 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);
280 }, 337 },
281 IambWindow::VerifyList(state) => { 338 IambWindow::VerifyList(state) => {
282 let verifications = &store.application.verifications; 339 let verifications = &store.application.verifications;
@@ -286,14 +343,29 @@ impl WindowOps<IambInfo> for IambWindow {
286 items.sort(); 343 items.sort();
287 344
288 state.set(items); 345 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);
290 }, 352 },
291 IambWindow::Welcome(state) => state.draw(inner, buf, focused, store), 353 IambWindow::Welcome(state) => state.draw(inner, buf, focused, store),
292 } 354 }
293 } 355 }
294 356
295 fn dup(&self, store: &mut ProgramStore) -> Self { 357 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 }
297 } 369 }
298 370
299 fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool { 371 fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
@@ -314,6 +386,7 @@ impl Window<IambInfo> for IambWindow {
314 match self { 386 match self {
315 IambWindow::Room(room) => IambId::Room(room.id().to_owned()), 387 IambWindow::Room(room) => IambId::Room(room.id().to_owned()),
316 IambWindow::DirectList(_) => IambId::DirectList, 388 IambWindow::DirectList(_) => IambId::DirectList,
389 IambWindow::MemberList(_, room_id) => IambId::MemberList(room_id.clone()),
317 IambWindow::RoomList(_) => IambId::RoomList, 390 IambWindow::RoomList(_) => IambId::RoomList,
318 IambWindow::SpaceList(_) => IambId::SpaceList, 391 IambWindow::SpaceList(_) => IambId::SpaceList,
319 IambWindow::VerifyList(_) => IambId::VerifyList, 392 IambWindow::VerifyList(_) => IambId::VerifyList,
@@ -334,6 +407,13 @@ impl Window<IambInfo> for IambWindow {
334 407
335 return Ok(list.into()); 408 return Ok(list.into());
336 }, 409 },
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 },
337 IambId::RoomList => { 417 IambId::RoomList => {
338 let list = RoomListState::new(IambBufferId::RoomList, vec![]); 418 let list = RoomListState::new(IambBufferId::RoomList, vec![]);
339 419
@@ -412,6 +492,10 @@ impl ListItem<IambInfo> for RoomItem {
412 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { 492 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
413 selected_text(self.name.as_str(), selected) 493 selected_text(self.name.as_str(), selected)
414 } 494 }
495
496 fn get_word(&self) -> Option<String> {
497 self.room.room_id().to_string().into()
498 }
415} 499}
416 500
417impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem { 501impl Promptable<ProgramContext, ProgramStore, IambInfo> for RoomItem {
@@ -451,6 +535,10 @@ impl ListItem<IambInfo> for DirectItem {
451 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { 535 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
452 selected_text(self.name.as_str(), selected) 536 selected_text(self.name.as_str(), selected)
453 } 537 }
538
539 fn get_word(&self) -> Option<String> {
540 self.room.room_id().to_string().into()
541 }
454} 542}
455 543
456impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem { 544impl Promptable<ProgramContext, ProgramStore, IambInfo> for DirectItem {
@@ -490,6 +578,10 @@ impl ListItem<IambInfo> for SpaceItem {
490 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text { 578 fn show(&self, selected: bool, _: &ViewportContext<ListCursor>, _: &mut ProgramStore) -> Text {
491 selected_text(self.name.as_str(), selected) 579 selected_text(self.name.as_str(), selected)
492 } 580 }
581
582 fn get_word(&self) -> Option<String> {
583 self.room.room_id().to_string().into()
584 }
493} 585}
494 586
495impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem { 587impl Promptable<ProgramContext, ProgramStore, IambInfo> for SpaceItem {
@@ -667,6 +759,10 @@ impl ListItem<IambInfo> for VerifyItem {
667 759
668 Text { lines } 760 Text { lines }
669 } 761 }
762
763 fn get_word(&self) -> Option<String> {
764 None
765 }
670} 766}
671 767
672impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem { 768impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem {
@@ -694,3 +790,77 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for VerifyItem {
694 } 790 }
695 } 791 }
696} 792}
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 {
94 return; 94 return;
95 } 95 }
96 96
97 if matches!(act, EditorAction::History(_)) {
98 return;
99 }
100
101 if !store.application.settings.tunables.typing_notice { 97 if !store.application.settings.tunables.typing_notice {
102 return; 98 return;
103 } 99 }
src/windows/room/mod.rs +42 −9
@@ -6,6 +6,7 @@ use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget};
6 6
7use modalkit::{ 7use modalkit::{
8 editing::action::{ 8 editing::action::{
9 Action,
9 EditInfo, 10 EditInfo,
10 EditResult, 11 EditResult,
11 Editable, 12 Editable,
@@ -15,11 +16,29 @@ use modalkit::{
15 Promptable, 16 Promptable,
16 Scrollable, 17 Scrollable,
17 }, 18 },
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,
19 widgets::{TermOffset, TerminalCursor, WindowOps}, 30 widgets::{TermOffset, TerminalCursor, WindowOps},
20}; 31};
21 32
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};
23 42
24use self::chat::ChatState; 43use self::chat::ChatState;
25use self::space::{Space, SpaceState}; 44use self::space::{Space, SpaceState};
@@ -67,14 +86,28 @@ impl RoomState {
67 } 86 }
68 } 87 }
69 88
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
70 pub fn get_title(&self, store: &mut ProgramStore) -> String { 109 pub fn get_title(&self, store: &mut ProgramStore) -> String {
71 store 110 store.application.get_room_title(self.id())
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())
78 } 111 }
79 112
80 pub fn focus_toggle(&mut self) { 113 pub fn focus_toggle(&mut self) {
src/windows/welcome.md +2 −1
@@ -3,8 +3,8 @@
3## Useful Keybindings 3## Useful Keybindings
4 4
5- `<Enter>` will send a typed message 5- `<Enter>` will send a typed message
6- `^V^J` can be used in Insert mode to enter a newline without submitting
6- `O`/`o` can be used to insert blank lines before and after the cursor line 7- `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
8- `^Wm` can be used to toggle whether the message bar or scrollback is selected 8- `^Wm` can be used to toggle whether the message bar or scrollback is selected
9- `^Wz` can be used to toggle whether the current window takes up the full screen 9- `^Wz` can be used to toggle whether the current window takes up the full screen
10 10
@@ -12,6 +12,7 @@
12 12
13- `:dms` will open a list of direct messages 13- `:dms` will open a list of direct messages
14- `:rooms` will open a list of joined rooms 14- `:rooms` will open a list of joined rooms
15- `:members` will open a list of members for the currently focused room or space
15- `:spaces` will open a list of joined spaces 16- `:spaces` will open a list of joined spaces
16- `:join` can be used to switch to join a new room or start a direct message 17- `:join` can be used to switch to join a new room or start a direct message
17- `:split` and `:vsplit` can be used to open rooms in a new window 18- `: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::{
15 encryption::verification::{SasVerification, Verification}, 15 encryption::verification::{SasVerification, Verification},
16 event_handler::Ctx, 16 event_handler::Ctx,
17 reqwest, 17 reqwest,
18 room::{Messages, MessagesOptions, Room as MatrixRoom}, 18 room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember},
19 ruma::{ 19 ruma::{
20 api::client::{ 20 api::client::{
21 room::create_room::v3::{Request as CreateRoomRequest, RoomPreset}, 21 room::create_room::v3::{Request as CreateRoomRequest, RoomPreset},
@@ -102,6 +102,7 @@ pub enum WorkerTask {
102 GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>), 102 GetRoom(OwnedRoomId, ClientReply<IambResult<(MatrixRoom, DisplayName)>>),
103 JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>), 103 JoinRoom(String, ClientReply<IambResult<OwnedRoomId>>),
104 JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>), 104 JoinedRooms(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
105 Members(OwnedRoomId, ClientReply<IambResult<Vec<RoomMember>>>),
105 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), 106 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>),
106 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), 107 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
107 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>), 108 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>),
@@ -187,6 +188,14 @@ impl Requester {
187 return response.recv(); 188 return response.recv();
188 } 189 }
189 190
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
190 pub fn space_members(&self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { 199 pub fn space_members(&self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
191 let (reply, response) = oneshot(); 200 let (reply, response) = oneshot();
192 201
@@ -327,6 +336,10 @@ impl ClientWorker {
327 assert!(self.initialized); 336 assert!(self.initialized);
328 reply.send(self.login_and_sync(style).await); 337 reply.send(self.login_and_sync(style).await);
329 }, 338 },
339 WorkerTask::Members(room_id, reply) => {
340 assert!(self.initialized);
341 reply.send(self.members(room_id).await);
342 },
330 WorkerTask::SpaceMembers(space, reply) => { 343 WorkerTask::SpaceMembers(space, reply) => {
331 assert!(self.initialized); 344 assert!(self.initialized);
332 reply.send(self.space_members(space).await); 345 reply.send(self.space_members(space).await);
@@ -744,6 +757,14 @@ impl ClientWorker {
744 } 757 }
745 } 758 }
746 759
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
747 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { 768 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
748 let mut req = SpaceHierarchyRequest::new(&space); 769 let mut req = SpaceHierarchyRequest::new(&space);
749 req.limit = Some(1000u32.into()); 770 req.limit = Some(1000u32.into());