Commit 38f4795886
Unregistered key
Layout: unified · split
Cargo.lock +2 −2
| @@ -1600,9 +1600,9 @@ dependencies = [ | ||
| 1600 | 1600 | |
| 1601 | 1601 | [[package]] |
| 1602 | 1602 | name = "modalkit" |
| 1603 | version = "0.0.8" | |
| 1603 | version = "0.0.9" | |
| 1604 | 1604 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1605 | checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba" | |
| 1605 | checksum = "28a676fc7ab6a9fd329ff82d9d291370aafcf904ac3ff9f72397f64529cb1b2d" | |
| 1606 | 1606 | dependencies = [ |
| 1607 | 1607 | "anymap2", |
| 1608 | 1608 | "bitflags", |
Cargo.toml +1 −1
| @@ -19,7 +19,7 @@ dirs = "4.0.0" | ||
| 19 | 19 | futures = "0.3.21" |
| 20 | 20 | gethostname = "0.4.1" |
| 21 | 21 | matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]} |
| 22 | modalkit = "0.0.8" | |
| 22 | modalkit = "0.0.9" | |
| 23 | 23 | regex = "^1.5" |
| 24 | 24 | rpassword = "^7.2" |
| 25 | 25 | serde = "^1.0" |
README.md +2 −2
| @@ -43,8 +43,8 @@ two other TUI clients and Element Web: | ||
| 43 | 43 | | Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 44 | 44 | | Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 45 | 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: | | |
| 47 | | Edit Room Description | :x: ([#12]) | :x: | :heavy_check_mark: | :heavy_check_mark: | | |
| 46 | | Display Room Description | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | |
| 47 | | Edit Room Description | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | | |
| 48 | 48 | | Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
| 49 | 49 | | Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | |
| 50 | 50 | | Send read markers | :x: ([#11]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
src/base.rs +19
| @@ -59,9 +59,22 @@ pub enum VerifyAction { | ||
| 59 | 59 | Mismatch, |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | #[derive(Clone, Debug, Eq, PartialEq)] | |
| 63 | pub enum SetRoomField { | |
| 64 | Name(String), | |
| 65 | Topic(String), | |
| 66 | } | |
| 67 | ||
| 62 | 68 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 63 | 69 | pub enum RoomAction { |
| 64 | 70 | Members(Box<CommandContext<ProgramContext>>), |
| 71 | Set(SetRoomField), | |
| 72 | } | |
| 73 | ||
| 74 | impl From<SetRoomField> for RoomAction { | |
| 75 | fn from(act: SetRoomField) -> Self { | |
| 76 | RoomAction::Set(act) | |
| 77 | } | |
| 65 | 78 | } |
| 66 | 79 | |
| 67 | 80 | #[derive(Clone, Debug, Eq, PartialEq)] |
| @@ -73,6 +86,12 @@ pub enum IambAction { | ||
| 73 | 86 | ToggleScrollbackFocus, |
| 74 | 87 | } |
| 75 | 88 | |
| 89 | impl From<RoomAction> for IambAction { | |
| 90 | fn from(act: RoomAction) -> Self { | |
| 91 | IambAction::Room(act) | |
| 92 | } | |
| 93 | } | |
| 94 | ||
| 76 | 95 | impl ApplicationAction for IambAction { |
| 77 | 96 | fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { |
| 78 | 97 | match self { |
src/commands.rs +69
| @@ -12,6 +12,7 @@ use crate::base::{ | ||
| 12 | 12 | ProgramCommands, |
| 13 | 13 | ProgramContext, |
| 14 | 14 | RoomAction, |
| 15 | SetRoomField, | |
| 15 | 16 | VerifyAction, |
| 16 | 17 | }; |
| 17 | 18 | |
| @@ -125,11 +126,35 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 125 | 126 | return Ok(step); |
| 126 | 127 | } |
| 127 | 128 | |
| 129 | fn iamb_set(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |
| 130 | let mut args = desc.arg.strings()?; | |
| 131 | ||
| 132 | if args.len() != 2 { | |
| 133 | return Result::Err(CommandError::InvalidArgument); | |
| 134 | } | |
| 135 | ||
| 136 | let field = args.remove(0); | |
| 137 | let value = args.remove(0); | |
| 138 | ||
| 139 | let act: IambAction = match field.as_str() { | |
| 140 | "room.name" => RoomAction::Set(SetRoomField::Name(value)).into(), | |
| 141 | "room.topic" => RoomAction::Set(SetRoomField::Topic(value)).into(), | |
| 142 | _ => { | |
| 143 | return Result::Err(CommandError::InvalidArgument); | |
| 144 | }, | |
| 145 | }; | |
| 146 | ||
| 147 | let step = CommandStep::Continue(act.into(), ctx.context.take()); | |
| 148 | ||
| 149 | return Ok(step); | |
| 150 | } | |
| 151 | ||
| 128 | 152 | fn add_iamb_commands(cmds: &mut ProgramCommands) { |
| 129 | 153 | cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); |
| 130 | 154 | cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); |
| 131 | 155 | cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); |
| 132 | 156 | cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); |
| 157 | cmds.add_command(ProgramCommand { names: vec!["set".into()], f: iamb_set }); | |
| 133 | 158 | cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); |
| 134 | 159 | cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); |
| 135 | 160 | cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome }); |
| @@ -214,4 +239,48 @@ mod tests { | ||
| 214 | 239 | let res = cmds.input_cmd("join foo bar", ctx.clone()); |
| 215 | 240 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 216 | 241 | } |
| 242 | ||
| 243 | #[test] | |
| 244 | fn test_cmd_set() { | |
| 245 | let mut cmds = setup_commands(); | |
| 246 | let ctx = ProgramContext::default(); | |
| 247 | ||
| 248 | let res = cmds | |
| 249 | .input_cmd("set room.topic \"Lots of fun discussion!\"", ctx.clone()) | |
| 250 | .unwrap(); | |
| 251 | let act = IambAction::Room(SetRoomField::Topic("Lots of fun discussion!".into()).into()); | |
| 252 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 253 | ||
| 254 | let res = cmds | |
| 255 | .input_cmd("set room.topic The\\ Discussion\\ Room", ctx.clone()) | |
| 256 | .unwrap(); | |
| 257 | let act = IambAction::Room(SetRoomField::Topic("The Discussion Room".into()).into()); | |
| 258 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 259 | ||
| 260 | let res = cmds.input_cmd("set room.topic Development", ctx.clone()).unwrap(); | |
| 261 | let act = IambAction::Room(SetRoomField::Topic("Development".into()).into()); | |
| 262 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 263 | ||
| 264 | let res = cmds.input_cmd("set room.name Development", ctx.clone()).unwrap(); | |
| 265 | let act = IambAction::Room(SetRoomField::Name("Development".into()).into()); | |
| 266 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 267 | ||
| 268 | let res = cmds | |
| 269 | .input_cmd("set room.name \"Application Development\"", ctx.clone()) | |
| 270 | .unwrap(); | |
| 271 | let act = IambAction::Room(SetRoomField::Name("Application Development".into()).into()); | |
| 272 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | |
| 273 | ||
| 274 | let res = cmds.input_cmd("set", ctx.clone()); | |
| 275 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 276 | ||
| 277 | let res = cmds.input_cmd("set room.name", ctx.clone()); | |
| 278 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 279 | ||
| 280 | let res = cmds.input_cmd("set room.topic", ctx.clone()); | |
| 281 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 282 | ||
| 283 | let res = cmds.input_cmd("set room.topic A B C", ctx.clone()); | |
| 284 | assert_eq!(res, Err(CommandError::InvalidArgument)); | |
| 285 | } | |
| 217 | 286 | } |
src/config.rs +26 −7
| @@ -100,25 +100,44 @@ impl Tunables { | ||
| 100 | 100 | #[derive(Clone)] |
| 101 | 101 | pub struct DirectoryValues { |
| 102 | 102 | pub cache: PathBuf, |
| 103 | pub logs: PathBuf, | |
| 104 | pub downloads: PathBuf, | |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | 107 | #[derive(Clone, Default, Deserialize)] |
| 106 | 108 | pub struct Directories { |
| 107 | 109 | pub cache: Option<PathBuf>, |
| 110 | pub logs: Option<PathBuf>, | |
| 111 | pub downloads: Option<PathBuf>, | |
| 108 | 112 | } |
| 109 | 113 | |
| 110 | 114 | impl Directories { |
| 111 | 115 | fn merge(self, other: Self) -> Self { |
| 112 | Directories { cache: self.cache.or(other.cache) } | |
| 116 | Directories { | |
| 117 | cache: self.cache.or(other.cache), | |
| 118 | logs: self.logs.or(other.logs), | |
| 119 | downloads: self.downloads.or(other.downloads), | |
| 120 | } | |
| 113 | 121 | } |
| 114 | 122 | |
| 115 | 123 | fn values(self) -> DirectoryValues { |
| 116 | DirectoryValues { | |
| 117 | cache: self | |
| 118 | .cache | |
| 119 | .or_else(dirs::cache_dir) | |
| 120 | .expect("no dirs.cache value configured!"), | |
| 121 | } | |
| 124 | let cache = self | |
| 125 | .cache | |
| 126 | .or_else(dirs::cache_dir) | |
| 127 | .expect("no dirs.cache value configured!"); | |
| 128 | ||
| 129 | let logs = self.logs.unwrap_or_else(|| { | |
| 130 | let mut dir = cache.clone(); | |
| 131 | dir.push("logs"); | |
| 132 | dir | |
| 133 | }); | |
| 134 | ||
| 135 | let downloads = self | |
| 136 | .downloads | |
| 137 | .or_else(dirs::download_dir) | |
| 138 | .expect("no dirs.download value configured!"); | |
| 139 | ||
| 140 | DirectoryValues { cache, logs, downloads } | |
| 122 | 141 | } |
| 123 | 142 | } |
| 124 | 143 | |
src/main.rs +3 −4
| @@ -162,7 +162,7 @@ impl Application { | ||
| 162 | 162 | term.draw(|f| { |
| 163 | 163 | let area = f.size(); |
| 164 | 164 | |
| 165 | let screen = Screen::new(store).showmode(modestr); | |
| 165 | let screen = Screen::new(store).showmode(modestr).borders(true); | |
| 166 | 166 | f.render_stateful_widget(screen, area, sstate); |
| 167 | 167 | |
| 168 | 168 | if let Some((cx, cy)) = sstate.get_term_cursor() { |
| @@ -457,11 +457,10 @@ async fn main() -> IambResult<()> { | ||
| 457 | 457 | |
| 458 | 458 | // Set up the tracing subscriber so we can log client messages. |
| 459 | 459 | let log_prefix = format!("iamb-log-{}", settings.profile_name); |
| 460 | let mut log_dir = settings.dirs.cache.clone(); | |
| 461 | log_dir.push("logs"); | |
| 460 | let log_dir = settings.dirs.logs.as_path(); | |
| 462 | 461 | |
| 463 | 462 | create_dir_all(settings.matrix_dir.as_path())?; |
| 464 | create_dir_all(log_dir.as_path())?; | |
| 463 | create_dir_all(log_dir)?; | |
| 465 | 464 | |
| 466 | 465 | let appender = tracing_appender::rolling::daily(log_dir, log_prefix); |
| 467 | 466 | let (appender, _) = tracing_appender::non_blocking(appender); |
src/tests.rs +9 −1
| @@ -110,6 +110,14 @@ pub fn mock_room() -> RoomInfo { | ||
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | pub fn mock_dirs() -> DirectoryValues { | |
| 114 | DirectoryValues { | |
| 115 | cache: PathBuf::new(), | |
| 116 | logs: PathBuf::new(), | |
| 117 | downloads: PathBuf::new(), | |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 113 | 121 | pub fn mock_settings() -> ApplicationSettings { |
| 114 | 122 | ApplicationSettings { |
| 115 | 123 | matrix_dir: PathBuf::new(), |
| @@ -122,7 +130,7 @@ pub fn mock_settings() -> ApplicationSettings { | ||
| 122 | 130 | dirs: None, |
| 123 | 131 | }, |
| 124 | 132 | tunables: TunableValues { typing_notice: true, typing_notice_display: true }, |
| 125 | dirs: DirectoryValues { cache: PathBuf::new() }, | |
| 133 | dirs: mock_dirs(), | |
| 126 | 134 | } |
| 127 | 135 | } |
| 128 | 136 | |
src/windows/mod.rs +66 −30
| @@ -13,7 +13,7 @@ use modalkit::tui::{ | ||
| 13 | 13 | layout::{Alignment, Rect}, |
| 14 | 14 | style::{Modifier as StyleModifier, Style}, |
| 15 | 15 | text::{Span, Spans, Text}, |
| 16 | widgets::{Block, Borders, StatefulWidget, Widget}, | |
| 16 | widgets::StatefulWidget, | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | use modalkit::{ |
| @@ -71,6 +71,21 @@ use self::{room::RoomState, welcome::WelcomeState}; | ||
| 71 | 71 | pub mod room; |
| 72 | 72 | pub mod welcome; |
| 73 | 73 | |
| 74 | #[inline] | |
| 75 | fn bold_style() -> Style { | |
| 76 | Style::default().add_modifier(StyleModifier::BOLD) | |
| 77 | } | |
| 78 | ||
| 79 | #[inline] | |
| 80 | fn bold_span(s: &str) -> Span { | |
| 81 | Span::styled(s, bold_style()) | |
| 82 | } | |
| 83 | ||
| 84 | #[inline] | |
| 85 | fn bold_spans(s: &str) -> Spans { | |
| 86 | bold_span(s).into() | |
| 87 | } | |
| 88 | ||
| 74 | 89 | #[inline] |
| 75 | 90 | fn selected_style(selected: bool) -> Style { |
| 76 | 91 | if selected { |
| @@ -168,22 +183,6 @@ impl IambWindow { | ||
| 168 | 183 | return Err(err); |
| 169 | 184 | } |
| 170 | 185 | } |
| 171 | ||
| 172 | pub fn get_title(&self, store: &mut ProgramStore) -> String { | |
| 173 | match self { | |
| 174 | IambWindow::DirectList(_) => "Direct Messages".to_string(), | |
| 175 | IambWindow::RoomList(_) => "Rooms".to_string(), | |
| 176 | IambWindow::SpaceList(_) => "Spaces".to_string(), | |
| 177 | IambWindow::VerifyList(_) => "Verifications".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 | }, | |
| 185 | } | |
| 186 | } | |
| 187 | 186 | } |
| 188 | 187 | |
| 189 | 188 | pub type DirectListState = ListState<DirectItem, IambInfo>; |
| @@ -281,13 +280,8 @@ impl TerminalCursor for IambWindow { | ||
| 281 | 280 | |
| 282 | 281 | impl WindowOps<IambInfo> for IambWindow { |
| 283 | 282 | fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { |
| 284 | let title = self.get_title(store); | |
| 285 | let block = Block::default().title(title.as_str()).borders(Borders::ALL); | |
| 286 | let inner = block.inner(area); | |
| 287 | block.render(area, buf); | |
| 288 | ||
| 289 | 283 | match self { |
| 290 | IambWindow::Room(state) => state.draw(inner, buf, focused, store), | |
| 284 | IambWindow::Room(state) => state.draw(area, buf, focused, store), | |
| 291 | 285 | IambWindow::DirectList(state) => { |
| 292 | 286 | let dms = store.application.worker.direct_messages(); |
| 293 | 287 | let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store)); |
| @@ -297,7 +291,7 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 297 | 291 | .empty_message("No direct messages yet!") |
| 298 | 292 | .empty_alignment(Alignment::Center) |
| 299 | 293 | .focus(focused) |
| 300 | .render(inner, buf, state); | |
| 294 | .render(area, buf, state); | |
| 301 | 295 | }, |
| 302 | 296 | IambWindow::MemberList(state, room_id) => { |
| 303 | 297 | if let Ok(mems) = store.application.worker.members(room_id.clone()) { |
| @@ -309,7 +303,7 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 309 | 303 | .empty_message("No users here yet!") |
| 310 | 304 | .empty_alignment(Alignment::Center) |
| 311 | 305 | .focus(focused) |
| 312 | .render(inner, buf, state); | |
| 306 | .render(area, buf, state); | |
| 313 | 307 | }, |
| 314 | 308 | IambWindow::RoomList(state) => { |
| 315 | 309 | let joined = store.application.worker.joined_rooms(); |
| @@ -320,20 +314,20 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 320 | 314 | .empty_message("You haven't joined any rooms yet") |
| 321 | 315 | .empty_alignment(Alignment::Center) |
| 322 | 316 | .focus(focused) |
| 323 | .render(inner, buf, state); | |
| 317 | .render(area, buf, state); | |
| 324 | 318 | }, |
| 325 | 319 | IambWindow::SpaceList(state) => { |
| 326 | 320 | let spaces = store.application.worker.spaces(); |
| 327 | 321 | let items = |
| 328 | 322 | spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store)); |
| 329 | 323 | state.set(items.collect()); |
| 330 | state.draw(inner, buf, focused, store); | |
| 324 | state.draw(area, buf, focused, store); | |
| 331 | 325 | |
| 332 | 326 | List::new(store) |
| 333 | 327 | .empty_message("You haven't joined any spaces yet") |
| 334 | 328 | .empty_alignment(Alignment::Center) |
| 335 | 329 | .focus(focused) |
| 336 | .render(inner, buf, state); | |
| 330 | .render(area, buf, state); | |
| 337 | 331 | }, |
| 338 | 332 | IambWindow::VerifyList(state) => { |
| 339 | 333 | let verifications = &store.application.verifications; |
| @@ -348,9 +342,9 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 348 | 342 | .empty_message("No in-progress verifications") |
| 349 | 343 | .empty_alignment(Alignment::Center) |
| 350 | 344 | .focus(focused) |
| 351 | .render(inner, buf, state); | |
| 345 | .render(area, buf, state); | |
| 352 | 346 | }, |
| 353 | IambWindow::Welcome(state) => state.draw(inner, buf, focused, store), | |
| 347 | IambWindow::Welcome(state) => state.draw(area, buf, focused, store), | |
| 354 | 348 | } |
| 355 | 349 | } |
| 356 | 350 | |
| @@ -394,6 +388,44 @@ impl Window<IambInfo> for IambWindow { | ||
| 394 | 388 | } |
| 395 | 389 | } |
| 396 | 390 | |
| 391 | fn get_tab_title(&self, store: &mut ProgramStore) -> Spans { | |
| 392 | match self { | |
| 393 | IambWindow::DirectList(_) => bold_spans("Direct Messages"), | |
| 394 | IambWindow::RoomList(_) => bold_spans("Rooms"), | |
| 395 | IambWindow::SpaceList(_) => bold_spans("Spaces"), | |
| 396 | IambWindow::VerifyList(_) => bold_spans("Verifications"), | |
| 397 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), | |
| 398 | ||
| 399 | IambWindow::Room(w) => { | |
| 400 | let title = store.application.get_room_title(w.id()); | |
| 401 | ||
| 402 | Spans::from(title) | |
| 403 | }, | |
| 404 | IambWindow::MemberList(_, room_id) => { | |
| 405 | let title = store.application.get_room_title(room_id.as_ref()); | |
| 406 | ||
| 407 | Spans(vec![bold_span("Room Members: "), title.into()]) | |
| 408 | }, | |
| 409 | } | |
| 410 | } | |
| 411 | ||
| 412 | fn get_win_title(&self, store: &mut ProgramStore) -> Spans { | |
| 413 | match self { | |
| 414 | IambWindow::DirectList(_) => bold_spans("Direct Messages"), | |
| 415 | IambWindow::RoomList(_) => bold_spans("Rooms"), | |
| 416 | IambWindow::SpaceList(_) => bold_spans("Spaces"), | |
| 417 | IambWindow::VerifyList(_) => bold_spans("Verifications"), | |
| 418 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), | |
| 419 | ||
| 420 | IambWindow::Room(w) => w.get_title(store), | |
| 421 | IambWindow::MemberList(_, room_id) => { | |
| 422 | let title = store.application.get_room_title(room_id.as_ref()); | |
| 423 | ||
| 424 | Spans(vec![bold_span("Room Members: "), title.into()]) | |
| 425 | }, | |
| 426 | } | |
| 427 | } | |
| 428 | ||
| 397 | 429 | fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> { |
| 398 | 430 | match id { |
| 399 | 431 | IambId::Room(room_id) => { |
| @@ -464,6 +496,10 @@ impl Window<IambInfo> for IambWindow { | ||
| 464 | 496 | |
| 465 | 497 | Err(err) |
| 466 | 498 | } |
| 499 | ||
| 500 | fn unnamed(store: &mut ProgramStore) -> IambResult<Self> { | |
| 501 | Self::open(IambId::RoomList, store) | |
| 502 | } | |
| 467 | 503 | } |
| 468 | 504 | |
| 469 | 505 | #[derive(Clone)] |
src/windows/room/chat.rs +7
| @@ -44,6 +44,7 @@ use super::scrollback::{Scrollback, ScrollbackState}; | ||
| 44 | 44 | |
| 45 | 45 | pub struct ChatState { |
| 46 | 46 | room_id: OwnedRoomId, |
| 47 | room: MatrixRoom, | |
| 47 | 48 | |
| 48 | 49 | tbox: TextBoxState<IambInfo>, |
| 49 | 50 | sent: HistoryList<EditRope>, |
| @@ -63,6 +64,7 @@ impl ChatState { | ||
| 63 | 64 | |
| 64 | 65 | ChatState { |
| 65 | 66 | room_id, |
| 67 | room, | |
| 66 | 68 | |
| 67 | 69 | tbox, |
| 68 | 70 | sent: HistoryList::new(EditRope::from(""), 100), |
| @@ -80,6 +82,10 @@ impl ChatState { | ||
| 80 | 82 | }; |
| 81 | 83 | } |
| 82 | 84 | |
| 85 | pub fn room(&self) -> &MatrixRoom { | |
| 86 | &self.room | |
| 87 | } | |
| 88 | ||
| 83 | 89 | pub fn id(&self) -> &RoomId { |
| 84 | 90 | &self.room_id |
| 85 | 91 | } |
| @@ -133,6 +139,7 @@ impl WindowOps<IambInfo> for ChatState { | ||
| 133 | 139 | |
| 134 | 140 | ChatState { |
| 135 | 141 | room_id: self.room_id.clone(), |
| 142 | room: self.room.clone(), | |
| 136 | 143 | |
| 137 | 144 | tbox, |
| 138 | 145 | sent: self.sent.clone(), |
src/windows/room/mod.rs +35 −4
| @@ -2,7 +2,13 @@ use matrix_sdk::room::Room as MatrixRoom; | ||
| 2 | 2 | use matrix_sdk::ruma::RoomId; |
| 3 | 3 | use matrix_sdk::DisplayName; |
| 4 | 4 | |
| 5 | use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; | |
| 5 | use modalkit::tui::{ | |
| 6 | buffer::Buffer, | |
| 7 | layout::Rect, | |
| 8 | style::{Modifier as StyleModifier, Style}, | |
| 9 | text::{Span, Spans}, | |
| 10 | widgets::StatefulWidget, | |
| 11 | }; | |
| 6 | 12 | |
| 7 | 13 | use modalkit::{ |
| 8 | 14 | editing::action::{ |
| @@ -90,7 +96,7 @@ impl RoomState { | ||
| 90 | 96 | &mut self, |
| 91 | 97 | act: RoomAction, |
| 92 | 98 | _: ProgramContext, |
| 93 | _: &mut ProgramStore, | |
| 99 | store: &mut ProgramStore, | |
| 94 | 100 | ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { |
| 95 | 101 | match act { |
| 96 | 102 | RoomAction::Members(mut cmd) => { |
| @@ -103,11 +109,29 @@ impl RoomState { | ||
| 103 | 109 | |
| 104 | 110 | Ok(vec![(act, cmd.context.take())]) |
| 105 | 111 | }, |
| 112 | RoomAction::Set(field) => { | |
| 113 | store.application.worker.set_room(self.id().to_owned(), field)?; | |
| 114 | ||
| 115 | Ok(vec![]) | |
| 116 | }, | |
| 106 | 117 | } |
| 107 | 118 | } |
| 108 | 119 | |
| 109 | pub fn get_title(&self, store: &mut ProgramStore) -> String { | |
| 110 | store.application.get_room_title(self.id()) | |
| 120 | pub fn get_title(&self, store: &mut ProgramStore) -> Spans { | |
| 121 | let title = store.application.get_room_title(self.id()); | |
| 122 | let style = Style::default().add_modifier(StyleModifier::BOLD); | |
| 123 | let mut spans = vec![Span::styled(title, style)]; | |
| 124 | ||
| 125 | match self.room().topic() { | |
| 126 | Some(desc) if !desc.is_empty() => { | |
| 127 | spans.push(" (".into()); | |
| 128 | spans.push(desc.into()); | |
| 129 | spans.push(")".into()); | |
| 130 | }, | |
| 131 | _ => {}, | |
| 132 | } | |
| 133 | ||
| 134 | Spans(spans) | |
| 111 | 135 | } |
| 112 | 136 | |
| 113 | 137 | pub fn focus_toggle(&mut self) { |
| @@ -117,6 +141,13 @@ impl RoomState { | ||
| 117 | 141 | } |
| 118 | 142 | } |
| 119 | 143 | |
| 144 | pub fn room(&self) -> &MatrixRoom { | |
| 145 | match self { | |
| 146 | RoomState::Chat(chat) => chat.room(), | |
| 147 | RoomState::Space(space) => space.room(), | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 120 | 151 | pub fn id(&self) -> &RoomId { |
| 121 | 152 | match self { |
| 122 | 153 | RoomState::Chat(chat) => chat.id(), |
src/windows/room/space.rs +7 −1
| @@ -18,6 +18,7 @@ use crate::windows::RoomItem; | ||
| 18 | 18 | |
| 19 | 19 | pub struct SpaceState { |
| 20 | 20 | room_id: OwnedRoomId, |
| 21 | room: MatrixRoom, | |
| 21 | 22 | list: ListState<RoomItem, IambInfo>, |
| 22 | 23 | } |
| 23 | 24 | |
| @@ -27,7 +28,11 @@ impl SpaceState { | ||
| 27 | 28 | let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback); |
| 28 | 29 | let list = ListState::new(content, vec![]); |
| 29 | 30 | |
| 30 | SpaceState { room_id, list } | |
| 31 | SpaceState { room_id, room, list } | |
| 32 | } | |
| 33 | ||
| 34 | pub fn room(&self) -> &MatrixRoom { | |
| 35 | &self.room | |
| 31 | 36 | } |
| 32 | 37 | |
| 33 | 38 | pub fn id(&self) -> &RoomId { |
| @@ -37,6 +42,7 @@ impl SpaceState { | ||
| 37 | 42 | pub fn dup(&self, store: &mut ProgramStore) -> Self { |
| 38 | 43 | SpaceState { |
| 39 | 44 | room_id: self.room_id.clone(), |
| 45 | room: self.room.clone(), | |
| 40 | 46 | list: self.list.dup(store), |
| 41 | 47 | } |
| 42 | 48 | } |
src/worker.rs +40 −3
| @@ -30,8 +30,11 @@ use matrix_sdk::{ | ||
| 30 | 30 | start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, |
| 31 | 31 | VerificationMethod, |
| 32 | 32 | }, |
| 33 | room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, | |
| 34 | room::name::RoomNameEventContent, | |
| 33 | room::{ | |
| 34 | message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, | |
| 35 | name::RoomNameEventContent, | |
| 36 | topic::RoomTopicEventContent, | |
| 37 | }, | |
| 35 | 38 | typing::SyncTypingEvent, |
| 36 | 39 | AnyMessageLikeEvent, |
| 37 | 40 | AnyTimelineEvent, |
| @@ -51,7 +54,7 @@ use matrix_sdk::{ | ||
| 51 | 54 | use modalkit::editing::action::{EditInfo, InfoMessage, UIError}; |
| 52 | 55 | |
| 53 | 56 | use crate::{ |
| 54 | base::{AsyncProgramStore, IambError, IambResult, VerifyAction}, | |
| 57 | base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction}, | |
| 55 | 58 | message::{Message, MessageFetchResult, MessageTimeStamp}, |
| 56 | 59 | ApplicationSettings, |
| 57 | 60 | }; |
| @@ -106,6 +109,7 @@ pub enum WorkerTask { | ||
| 106 | 109 | SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), |
| 107 | 110 | Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), |
| 108 | 111 | SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>), |
| 112 | SetRoom(OwnedRoomId, SetRoomField, ClientReply<IambResult<()>>), | |
| 109 | 113 | TypingNotice(OwnedRoomId), |
| 110 | 114 | Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>), |
| 111 | 115 | VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>), |
| @@ -204,6 +208,14 @@ impl Requester { | ||
| 204 | 208 | return response.recv(); |
| 205 | 209 | } |
| 206 | 210 | |
| 211 | pub fn set_room(&self, room_id: OwnedRoomId, ev: SetRoomField) -> IambResult<()> { | |
| 212 | let (reply, response) = oneshot(); | |
| 213 | ||
| 214 | self.tx.send(WorkerTask::SetRoom(room_id, ev, reply)).unwrap(); | |
| 215 | ||
| 216 | return response.recv(); | |
| 217 | } | |
| 218 | ||
| 207 | 219 | pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> { |
| 208 | 220 | let (reply, response) = oneshot(); |
| 209 | 221 | |
| @@ -340,6 +352,10 @@ impl ClientWorker { | ||
| 340 | 352 | assert!(self.initialized); |
| 341 | 353 | reply.send(self.members(room_id).await); |
| 342 | 354 | }, |
| 355 | WorkerTask::SetRoom(room_id, field, reply) => { | |
| 356 | assert!(self.initialized); | |
| 357 | reply.send(self.set_room(room_id, field).await); | |
| 358 | }, | |
| 343 | 359 | WorkerTask::SpaceMembers(space, reply) => { |
| 344 | 360 | assert!(self.initialized); |
| 345 | 361 | reply.send(self.space_members(space).await); |
| @@ -765,6 +781,27 @@ impl ClientWorker { | ||
| 765 | 781 | } |
| 766 | 782 | } |
| 767 | 783 | |
| 784 | async fn set_room(&mut self, room_id: OwnedRoomId, field: SetRoomField) -> IambResult<()> { | |
| 785 | let room = if let Some(r) = self.client.get_joined_room(&room_id) { | |
| 786 | r | |
| 787 | } else { | |
| 788 | return Err(IambError::UnknownRoom(room_id).into()); | |
| 789 | }; | |
| 790 | ||
| 791 | match field { | |
| 792 | SetRoomField::Name(name) => { | |
| 793 | let ev = RoomNameEventContent::new(name.into()); | |
| 794 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 795 | }, | |
| 796 | SetRoomField::Topic(topic) => { | |
| 797 | let ev = RoomTopicEventContent::new(topic); | |
| 798 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; | |
| 799 | }, | |
| 800 | } | |
| 801 | ||
| 802 | Ok(()) | |
| 803 | } | |
| 804 | ||
| 768 | 805 | async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { |
| 769 | 806 | let mut req = SpaceHierarchyRequest::new(&space); |
| 770 | 807 | req.limit = Some(1000u32.into()); |