Commit 38f4795886

38f479588668ca364473ddfb3aa252f77eca50a3

parent: 8ed037afca

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-01-06 02:12 UTC

Support displaying and editing room descriptions (#12)

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.8" 1603version = "0.0.9"
1604source = "registry+https://github.com/rust-lang/crates.io-index" 1604source = "registry+https://github.com/rust-lang/crates.io-index"
1605checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba" 1605checksum = "28a676fc7ab6a9fd329ff82d9d291370aafcf904ac3ff9f72397f64529cb1b2d"
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.8" 22modalkit = "0.0.9"
23regex = "^1.5" 23regex = "^1.5"
24rpassword = "^7.2" 24rpassword = "^7.2"
25serde = "^1.0" 25serde = "^1.0"
README.md +2 −2
@@ -43,8 +43,8 @@ two other TUI clients and Element Web:
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 | :heavy_check_mark: | :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 | :heavy_check_mark: | :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 | :heavy_check_mark: | :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: |
49| Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | 49| Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
50| Send read markers | :x: ([#11]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 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 Mismatch, 59 Mismatch,
60} 60}
61 61
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum SetRoomField {
64 Name(String),
65 Topic(String),
66}
67
62#[derive(Clone, Debug, Eq, PartialEq)] 68#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum RoomAction { 69pub enum RoomAction {
64 Members(Box<CommandContext<ProgramContext>>), 70 Members(Box<CommandContext<ProgramContext>>),
71 Set(SetRoomField),
72}
73
74impl From<SetRoomField> for RoomAction {
75 fn from(act: SetRoomField) -> Self {
76 RoomAction::Set(act)
77 }
65} 78}
66 79
67#[derive(Clone, Debug, Eq, PartialEq)] 80#[derive(Clone, Debug, Eq, PartialEq)]
@@ -73,6 +86,12 @@ pub enum IambAction {
73 ToggleScrollbackFocus, 86 ToggleScrollbackFocus,
74} 87}
75 88
89impl From<RoomAction> for IambAction {
90 fn from(act: RoomAction) -> Self {
91 IambAction::Room(act)
92 }
93}
94
76impl ApplicationAction for IambAction { 95impl ApplicationAction for IambAction {
77 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus { 96 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus {
78 match self { 97 match self {
src/commands.rs +69
@@ -12,6 +12,7 @@ use crate::base::{
12 ProgramCommands, 12 ProgramCommands,
13 ProgramContext, 13 ProgramContext,
14 RoomAction, 14 RoomAction,
15 SetRoomField,
15 VerifyAction, 16 VerifyAction,
16}; 17};
17 18
@@ -125,11 +126,35 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
125 return Ok(step); 126 return Ok(step);
126} 127}
127 128
129fn 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
128fn add_iamb_commands(cmds: &mut ProgramCommands) { 152fn add_iamb_commands(cmds: &mut ProgramCommands) {
129 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms }); 153 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
130 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join }); 154 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
131 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members }); 155 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
132 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms }); 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 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces }); 158 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
134 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify }); 159 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
135 cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome }); 160 cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome });
@@ -214,4 +239,48 @@ mod tests {
214 let res = cmds.input_cmd("join foo bar", ctx.clone()); 239 let res = cmds.input_cmd("join foo bar", ctx.clone());
215 assert_eq!(res, Err(CommandError::InvalidArgument)); 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#[derive(Clone)] 100#[derive(Clone)]
101pub struct DirectoryValues { 101pub struct DirectoryValues {
102 pub cache: PathBuf, 102 pub cache: PathBuf,
103 pub logs: PathBuf,
104 pub downloads: PathBuf,
103} 105}
104 106
105#[derive(Clone, Default, Deserialize)] 107#[derive(Clone, Default, Deserialize)]
106pub struct Directories { 108pub struct Directories {
107 pub cache: Option<PathBuf>, 109 pub cache: Option<PathBuf>,
110 pub logs: Option<PathBuf>,
111 pub downloads: Option<PathBuf>,
108} 112}
109 113
110impl Directories { 114impl Directories {
111 fn merge(self, other: Self) -> Self { 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 fn values(self) -> DirectoryValues { 123 fn values(self) -> DirectoryValues {
116 DirectoryValues { 124 let cache = self
117 cache: self 125 .cache
118 .cache 126 .or_else(dirs::cache_dir)
119 .or_else(dirs::cache_dir) 127 .expect("no dirs.cache value configured!");
120 .expect("no dirs.cache value configured!"), 128
121 } 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 term.draw(|f| { 162 term.draw(|f| {
163 let area = f.size(); 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 f.render_stateful_widget(screen, area, sstate); 166 f.render_stateful_widget(screen, area, sstate);
167 167
168 if let Some((cx, cy)) = sstate.get_term_cursor() { 168 if let Some((cx, cy)) = sstate.get_term_cursor() {
@@ -457,11 +457,10 @@ async fn main() -> IambResult<()> {
457 457
458 // Set up the tracing subscriber so we can log client messages. 458 // Set up the tracing subscriber so we can log client messages.
459 let log_prefix = format!("iamb-log-{}", settings.profile_name); 459 let log_prefix = format!("iamb-log-{}", settings.profile_name);
460 let mut log_dir = settings.dirs.cache.clone(); 460 let log_dir = settings.dirs.logs.as_path();
461 log_dir.push("logs");
462 461
463 create_dir_all(settings.matrix_dir.as_path())?; 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 let appender = tracing_appender::rolling::daily(log_dir, log_prefix); 465 let appender = tracing_appender::rolling::daily(log_dir, log_prefix);
467 let (appender, _) = tracing_appender::non_blocking(appender); 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
113pub fn mock_dirs() -> DirectoryValues {
114 DirectoryValues {
115 cache: PathBuf::new(),
116 logs: PathBuf::new(),
117 downloads: PathBuf::new(),
118 }
119}
120
113pub fn mock_settings() -> ApplicationSettings { 121pub fn mock_settings() -> ApplicationSettings {
114 ApplicationSettings { 122 ApplicationSettings {
115 matrix_dir: PathBuf::new(), 123 matrix_dir: PathBuf::new(),
@@ -122,7 +130,7 @@ pub fn mock_settings() -> ApplicationSettings {
122 dirs: None, 130 dirs: None,
123 }, 131 },
124 tunables: TunableValues { typing_notice: true, typing_notice_display: true }, 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 layout::{Alignment, 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, StatefulWidget, Widget}, 16 widgets::StatefulWidget,
17}; 17};
18 18
19use modalkit::{ 19use modalkit::{
@@ -71,6 +71,21 @@ use self::{room::RoomState, welcome::WelcomeState};
71pub mod room; 71pub mod room;
72pub mod welcome; 72pub mod welcome;
73 73
74#[inline]
75fn bold_style() -> Style {
76 Style::default().add_modifier(StyleModifier::BOLD)
77}
78
79#[inline]
80fn bold_span(s: &str) -> Span {
81 Span::styled(s, bold_style())
82}
83
84#[inline]
85fn bold_spans(s: &str) -> Spans {
86 bold_span(s).into()
87}
88
74#[inline] 89#[inline]
75fn selected_style(selected: bool) -> Style { 90fn selected_style(selected: bool) -> Style {
76 if selected { 91 if selected {
@@ -168,22 +183,6 @@ impl IambWindow {
168 return Err(err); 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
189pub type DirectListState = ListState<DirectItem, IambInfo>; 188pub type DirectListState = ListState<DirectItem, IambInfo>;
@@ -281,13 +280,8 @@ impl TerminalCursor for IambWindow {
281 280
282impl WindowOps<IambInfo> for IambWindow { 281impl WindowOps<IambInfo> for IambWindow {
283 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { 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 match self { 283 match self {
290 IambWindow::Room(state) => state.draw(inner, buf, focused, store), 284 IambWindow::Room(state) => state.draw(area, buf, focused, store),
291 IambWindow::DirectList(state) => { 285 IambWindow::DirectList(state) => {
292 let dms = store.application.worker.direct_messages(); 286 let dms = store.application.worker.direct_messages();
293 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store)); 287 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store));
@@ -297,7 +291,7 @@ impl WindowOps<IambInfo> for IambWindow {
297 .empty_message("No direct messages yet!") 291 .empty_message("No direct messages yet!")
298 .empty_alignment(Alignment::Center) 292 .empty_alignment(Alignment::Center)
299 .focus(focused) 293 .focus(focused)
300 .render(inner, buf, state); 294 .render(area, buf, state);
301 }, 295 },
302 IambWindow::MemberList(state, room_id) => { 296 IambWindow::MemberList(state, room_id) => {
303 if let Ok(mems) = store.application.worker.members(room_id.clone()) { 297 if let Ok(mems) = store.application.worker.members(room_id.clone()) {
@@ -309,7 +303,7 @@ impl WindowOps<IambInfo> for IambWindow {
309 .empty_message("No users here yet!") 303 .empty_message("No users here yet!")
310 .empty_alignment(Alignment::Center) 304 .empty_alignment(Alignment::Center)
311 .focus(focused) 305 .focus(focused)
312 .render(inner, buf, state); 306 .render(area, buf, state);
313 }, 307 },
314 IambWindow::RoomList(state) => { 308 IambWindow::RoomList(state) => {
315 let joined = store.application.worker.joined_rooms(); 309 let joined = store.application.worker.joined_rooms();
@@ -320,20 +314,20 @@ impl WindowOps<IambInfo> for IambWindow {
320 .empty_message("You haven't joined any rooms yet") 314 .empty_message("You haven't joined any rooms yet")
321 .empty_alignment(Alignment::Center) 315 .empty_alignment(Alignment::Center)
322 .focus(focused) 316 .focus(focused)
323 .render(inner, buf, state); 317 .render(area, buf, state);
324 }, 318 },
325 IambWindow::SpaceList(state) => { 319 IambWindow::SpaceList(state) => {
326 let spaces = store.application.worker.spaces(); 320 let spaces = store.application.worker.spaces();
327 let items = 321 let items =
328 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store)); 322 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store));
329 state.set(items.collect()); 323 state.set(items.collect());
330 state.draw(inner, buf, focused, store); 324 state.draw(area, buf, focused, store);
331 325
332 List::new(store) 326 List::new(store)
333 .empty_message("You haven't joined any spaces yet") 327 .empty_message("You haven't joined any spaces yet")
334 .empty_alignment(Alignment::Center) 328 .empty_alignment(Alignment::Center)
335 .focus(focused) 329 .focus(focused)
336 .render(inner, buf, state); 330 .render(area, buf, state);
337 }, 331 },
338 IambWindow::VerifyList(state) => { 332 IambWindow::VerifyList(state) => {
339 let verifications = &store.application.verifications; 333 let verifications = &store.application.verifications;
@@ -348,9 +342,9 @@ impl WindowOps<IambInfo> for IambWindow {
348 .empty_message("No in-progress verifications") 342 .empty_message("No in-progress verifications")
349 .empty_alignment(Alignment::Center) 343 .empty_alignment(Alignment::Center)
350 .focus(focused) 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 fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> { 429 fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> {
398 match id { 430 match id {
399 IambId::Room(room_id) => { 431 IambId::Room(room_id) => {
@@ -464,6 +496,10 @@ impl Window<IambInfo> for IambWindow {
464 496
465 Err(err) 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#[derive(Clone)] 505#[derive(Clone)]
src/windows/room/chat.rs +7
@@ -44,6 +44,7 @@ use super::scrollback::{Scrollback, ScrollbackState};
44 44
45pub struct ChatState { 45pub struct ChatState {
46 room_id: OwnedRoomId, 46 room_id: OwnedRoomId,
47 room: MatrixRoom,
47 48
48 tbox: TextBoxState<IambInfo>, 49 tbox: TextBoxState<IambInfo>,
49 sent: HistoryList<EditRope>, 50 sent: HistoryList<EditRope>,
@@ -63,6 +64,7 @@ impl ChatState {
63 64
64 ChatState { 65 ChatState {
65 room_id, 66 room_id,
67 room,
66 68
67 tbox, 69 tbox,
68 sent: HistoryList::new(EditRope::from(""), 100), 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 pub fn id(&self) -> &RoomId { 89 pub fn id(&self) -> &RoomId {
84 &self.room_id 90 &self.room_id
85 } 91 }
@@ -133,6 +139,7 @@ impl WindowOps<IambInfo> for ChatState {
133 139
134 ChatState { 140 ChatState {
135 room_id: self.room_id.clone(), 141 room_id: self.room_id.clone(),
142 room: self.room.clone(),
136 143
137 tbox, 144 tbox,
138 sent: self.sent.clone(), 145 sent: self.sent.clone(),
src/windows/room/mod.rs +35 −4
@@ -2,7 +2,13 @@ use matrix_sdk::room::Room as MatrixRoom;
2use matrix_sdk::ruma::RoomId; 2use matrix_sdk::ruma::RoomId;
3use matrix_sdk::DisplayName; 3use matrix_sdk::DisplayName;
4 4
5use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget}; 5use modalkit::tui::{
6 buffer::Buffer,
7 layout::Rect,
8 style::{Modifier as StyleModifier, Style},
9 text::{Span, Spans},
10 widgets::StatefulWidget,
11};
6 12
7use modalkit::{ 13use modalkit::{
8 editing::action::{ 14 editing::action::{
@@ -90,7 +96,7 @@ impl RoomState {
90 &mut self, 96 &mut self,
91 act: RoomAction, 97 act: RoomAction,
92 _: ProgramContext, 98 _: ProgramContext,
93 _: &mut ProgramStore, 99 store: &mut ProgramStore,
94 ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> { 100 ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
95 match act { 101 match act {
96 RoomAction::Members(mut cmd) => { 102 RoomAction::Members(mut cmd) => {
@@ -103,11 +109,29 @@ impl RoomState {
103 109
104 Ok(vec![(act, cmd.context.take())]) 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 { 120 pub fn get_title(&self, store: &mut ProgramStore) -> Spans {
110 store.application.get_room_title(self.id()) 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 pub fn focus_toggle(&mut self) { 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 pub fn id(&self) -> &RoomId { 151 pub fn id(&self) -> &RoomId {
121 match self { 152 match self {
122 RoomState::Chat(chat) => chat.id(), 153 RoomState::Chat(chat) => chat.id(),
src/windows/room/space.rs +7 −1
@@ -18,6 +18,7 @@ use crate::windows::RoomItem;
18 18
19pub struct SpaceState { 19pub struct SpaceState {
20 room_id: OwnedRoomId, 20 room_id: OwnedRoomId,
21 room: MatrixRoom,
21 list: ListState<RoomItem, IambInfo>, 22 list: ListState<RoomItem, IambInfo>,
22} 23}
23 24
@@ -27,7 +28,11 @@ impl SpaceState {
27 let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback); 28 let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback);
28 let list = ListState::new(content, vec![]); 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 pub fn id(&self) -> &RoomId { 38 pub fn id(&self) -> &RoomId {
@@ -37,6 +42,7 @@ impl SpaceState {
37 pub fn dup(&self, store: &mut ProgramStore) -> Self { 42 pub fn dup(&self, store: &mut ProgramStore) -> Self {
38 SpaceState { 43 SpaceState {
39 room_id: self.room_id.clone(), 44 room_id: self.room_id.clone(),
45 room: self.room.clone(),
40 list: self.list.dup(store), 46 list: self.list.dup(store),
41 } 47 }
42 } 48 }
src/worker.rs +40 −3
@@ -30,8 +30,11 @@ use matrix_sdk::{
30 start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, 30 start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
31 VerificationMethod, 31 VerificationMethod,
32 }, 32 },
33 room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, 33 room::{
34 room::name::RoomNameEventContent, 34 message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
35 name::RoomNameEventContent,
36 topic::RoomTopicEventContent,
37 },
35 typing::SyncTypingEvent, 38 typing::SyncTypingEvent,
36 AnyMessageLikeEvent, 39 AnyMessageLikeEvent,
37 AnyTimelineEvent, 40 AnyTimelineEvent,
@@ -51,7 +54,7 @@ use matrix_sdk::{
51use modalkit::editing::action::{EditInfo, InfoMessage, UIError}; 54use modalkit::editing::action::{EditInfo, InfoMessage, UIError};
52 55
53use crate::{ 56use crate::{
54 base::{AsyncProgramStore, IambError, IambResult, VerifyAction}, 57 base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction},
55 message::{Message, MessageFetchResult, MessageTimeStamp}, 58 message::{Message, MessageFetchResult, MessageTimeStamp},
56 ApplicationSettings, 59 ApplicationSettings,
57}; 60};
@@ -106,6 +109,7 @@ pub enum WorkerTask {
106 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>), 109 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>),
107 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>), 110 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
108 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>), 111 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>),
112 SetRoom(OwnedRoomId, SetRoomField, ClientReply<IambResult<()>>),
109 TypingNotice(OwnedRoomId), 113 TypingNotice(OwnedRoomId),
110 Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>), 114 Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>),
111 VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>), 115 VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>),
@@ -204,6 +208,14 @@ impl Requester {
204 return response.recv(); 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 pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> { 219 pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> {
208 let (reply, response) = oneshot(); 220 let (reply, response) = oneshot();
209 221
@@ -340,6 +352,10 @@ impl ClientWorker {
340 assert!(self.initialized); 352 assert!(self.initialized);
341 reply.send(self.members(room_id).await); 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 WorkerTask::SpaceMembers(space, reply) => { 359 WorkerTask::SpaceMembers(space, reply) => {
344 assert!(self.initialized); 360 assert!(self.initialized);
345 reply.send(self.space_members(space).await); 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 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> { 805 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
769 let mut req = SpaceHierarchyRequest::new(&space); 806 let mut req = SpaceHierarchyRequest::new(&space);
770 req.limit = Some(1000u32.into()); 807 req.limit = Some(1000u32.into());