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 = [
16001600
16011601[[package]]
16021602name = "modalkit"
1603version = "0.0.8"
1603version = "0.0.9"
16041604source = "registry+https://github.com/rust-lang/crates.io-index"
1605checksum = "7f4e400066e546471efee517b7e5e3ca5af2c04014e76289aecc7af621011bba"
1605checksum = "28a676fc7ab6a9fd329ff82d9d291370aafcf904ac3ff9f72397f64529cb1b2d"
16061606dependencies = [
16071607 "anymap2",
16081608 "bitflags",
Cargo.toml +1 −1
@@ -19,7 +19,7 @@ dirs = "4.0.0"
1919futures = "0.3.21"
2020gethostname = "0.4.1"
2121matrix-sdk = {version = "0.6", default-features = false, features = ["e2e-encryption", "sled", "rustls-tls"]}
22modalkit = "0.0.8"
22modalkit = "0.0.9"
2323regex = "^1.5"
2424rpassword = "^7.2"
2525serde = "^1.0"
README.md +2 −2
@@ -43,8 +43,8 @@ two other TUI clients and Element Web:
4343| Room tag editing | :x: ([#15]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
4444| Search joined rooms | :x: ([#16]) | :heavy_check_mark: | :x: | :heavy_check_mark: |
4545| 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: |
4848| Highlights | :x: ([#8]) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
4949| Pushrules | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
5050| 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 {
5959 Mismatch,
6060}
6161
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum SetRoomField {
64 Name(String),
65 Topic(String),
66}
67
6268#[derive(Clone, Debug, Eq, PartialEq)]
6369pub enum RoomAction {
6470 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 }
6578}
6679
6780#[derive(Clone, Debug, Eq, PartialEq)]
@@ -73,6 +86,12 @@ pub enum IambAction {
7386 ToggleScrollbackFocus,
7487}
7588
89impl From<RoomAction> for IambAction {
90 fn from(act: RoomAction) -> Self {
91 IambAction::Room(act)
92 }
93}
94
7695impl ApplicationAction for IambAction {
7796 fn is_edit_sequence<C: EditContext>(&self, _: &C) -> SequenceStatus {
7897 match self {
src/commands.rs +69
@@ -12,6 +12,7 @@ use crate::base::{
1212 ProgramCommands,
1313 ProgramContext,
1414 RoomAction,
15 SetRoomField,
1516 VerifyAction,
1617};
1718
@@ -125,11 +126,35 @@ fn iamb_join(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
125126 return Ok(step);
126127}
127128
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
128152fn add_iamb_commands(cmds: &mut ProgramCommands) {
129153 cmds.add_command(ProgramCommand { names: vec!["dms".into()], f: iamb_dms });
130154 cmds.add_command(ProgramCommand { names: vec!["join".into()], f: iamb_join });
131155 cmds.add_command(ProgramCommand { names: vec!["members".into()], f: iamb_members });
132156 cmds.add_command(ProgramCommand { names: vec!["rooms".into()], f: iamb_rooms });
157 cmds.add_command(ProgramCommand { names: vec!["set".into()], f: iamb_set });
133158 cmds.add_command(ProgramCommand { names: vec!["spaces".into()], f: iamb_spaces });
134159 cmds.add_command(ProgramCommand { names: vec!["verify".into()], f: iamb_verify });
135160 cmds.add_command(ProgramCommand { names: vec!["welcome".into()], f: iamb_welcome });
@@ -214,4 +239,48 @@ mod tests {
214239 let res = cmds.input_cmd("join foo bar", ctx.clone());
215240 assert_eq!(res, Err(CommandError::InvalidArgument));
216241 }
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 }
217286}
src/config.rs +26 −7
@@ -100,25 +100,44 @@ impl Tunables {
100100#[derive(Clone)]
101101pub struct DirectoryValues {
102102 pub cache: PathBuf,
103 pub logs: PathBuf,
104 pub downloads: PathBuf,
103105}
104106
105107#[derive(Clone, Default, Deserialize)]
106108pub struct Directories {
107109 pub cache: Option<PathBuf>,
110 pub logs: Option<PathBuf>,
111 pub downloads: Option<PathBuf>,
108112}
109113
110114impl Directories {
111115 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 }
113121 }
114122
115123 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 }
122141 }
123142}
124143
src/main.rs +3 −4
@@ -162,7 +162,7 @@ impl Application {
162162 term.draw(|f| {
163163 let area = f.size();
164164
165 let screen = Screen::new(store).showmode(modestr);
165 let screen = Screen::new(store).showmode(modestr).borders(true);
166166 f.render_stateful_widget(screen, area, sstate);
167167
168168 if let Some((cx, cy)) = sstate.get_term_cursor() {
@@ -457,11 +457,10 @@ async fn main() -> IambResult<()> {
457457
458458 // Set up the tracing subscriber so we can log client messages.
459459 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();
462461
463462 create_dir_all(settings.matrix_dir.as_path())?;
464 create_dir_all(log_dir.as_path())?;
463 create_dir_all(log_dir)?;
465464
466465 let appender = tracing_appender::rolling::daily(log_dir, log_prefix);
467466 let (appender, _) = tracing_appender::non_blocking(appender);
src/tests.rs +9 −1
@@ -110,6 +110,14 @@ pub fn mock_room() -> RoomInfo {
110110 }
111111}
112112
113pub fn mock_dirs() -> DirectoryValues {
114 DirectoryValues {
115 cache: PathBuf::new(),
116 logs: PathBuf::new(),
117 downloads: PathBuf::new(),
118 }
119}
120
113121pub fn mock_settings() -> ApplicationSettings {
114122 ApplicationSettings {
115123 matrix_dir: PathBuf::new(),
@@ -122,7 +130,7 @@ pub fn mock_settings() -> ApplicationSettings {
122130 dirs: None,
123131 },
124132 tunables: TunableValues { typing_notice: true, typing_notice_display: true },
125 dirs: DirectoryValues { cache: PathBuf::new() },
133 dirs: mock_dirs(),
126134 }
127135}
128136
src/windows/mod.rs +66 −30
@@ -13,7 +13,7 @@ use modalkit::tui::{
1313 layout::{Alignment, Rect},
1414 style::{Modifier as StyleModifier, Style},
1515 text::{Span, Spans, Text},
16 widgets::{Block, Borders, StatefulWidget, Widget},
16 widgets::StatefulWidget,
1717};
1818
1919use modalkit::{
@@ -71,6 +71,21 @@ use self::{room::RoomState, welcome::WelcomeState};
7171pub mod room;
7272pub mod welcome;
7373
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
7489#[inline]
7590fn selected_style(selected: bool) -> Style {
7691 if selected {
@@ -168,22 +183,6 @@ impl IambWindow {
168183 return Err(err);
169184 }
170185 }
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 }
187186}
188187
189188pub type DirectListState = ListState<DirectItem, IambInfo>;
@@ -281,13 +280,8 @@ impl TerminalCursor for IambWindow {
281280
282281impl WindowOps<IambInfo> for IambWindow {
283282 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
289283 match self {
290 IambWindow::Room(state) => state.draw(inner, buf, focused, store),
284 IambWindow::Room(state) => state.draw(area, buf, focused, store),
291285 IambWindow::DirectList(state) => {
292286 let dms = store.application.worker.direct_messages();
293287 let items = dms.into_iter().map(|(id, name)| DirectItem::new(id, name, store));
@@ -297,7 +291,7 @@ impl WindowOps<IambInfo> for IambWindow {
297291 .empty_message("No direct messages yet!")
298292 .empty_alignment(Alignment::Center)
299293 .focus(focused)
300 .render(inner, buf, state);
294 .render(area, buf, state);
301295 },
302296 IambWindow::MemberList(state, room_id) => {
303297 if let Ok(mems) = store.application.worker.members(room_id.clone()) {
@@ -309,7 +303,7 @@ impl WindowOps<IambInfo> for IambWindow {
309303 .empty_message("No users here yet!")
310304 .empty_alignment(Alignment::Center)
311305 .focus(focused)
312 .render(inner, buf, state);
306 .render(area, buf, state);
313307 },
314308 IambWindow::RoomList(state) => {
315309 let joined = store.application.worker.joined_rooms();
@@ -320,20 +314,20 @@ impl WindowOps<IambInfo> for IambWindow {
320314 .empty_message("You haven't joined any rooms yet")
321315 .empty_alignment(Alignment::Center)
322316 .focus(focused)
323 .render(inner, buf, state);
317 .render(area, buf, state);
324318 },
325319 IambWindow::SpaceList(state) => {
326320 let spaces = store.application.worker.spaces();
327321 let items =
328322 spaces.into_iter().map(|(room, name)| SpaceItem::new(room, name, store));
329323 state.set(items.collect());
330 state.draw(inner, buf, focused, store);
324 state.draw(area, buf, focused, store);
331325
332326 List::new(store)
333327 .empty_message("You haven't joined any spaces yet")
334328 .empty_alignment(Alignment::Center)
335329 .focus(focused)
336 .render(inner, buf, state);
330 .render(area, buf, state);
337331 },
338332 IambWindow::VerifyList(state) => {
339333 let verifications = &store.application.verifications;
@@ -348,9 +342,9 @@ impl WindowOps<IambInfo> for IambWindow {
348342 .empty_message("No in-progress verifications")
349343 .empty_alignment(Alignment::Center)
350344 .focus(focused)
351 .render(inner, buf, state);
345 .render(area, buf, state);
352346 },
353 IambWindow::Welcome(state) => state.draw(inner, buf, focused, store),
347 IambWindow::Welcome(state) => state.draw(area, buf, focused, store),
354348 }
355349 }
356350
@@ -394,6 +388,44 @@ impl Window<IambInfo> for IambWindow {
394388 }
395389 }
396390
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
397429 fn open(id: IambId, store: &mut ProgramStore) -> IambResult<Self> {
398430 match id {
399431 IambId::Room(room_id) => {
@@ -464,6 +496,10 @@ impl Window<IambInfo> for IambWindow {
464496
465497 Err(err)
466498 }
499
500 fn unnamed(store: &mut ProgramStore) -> IambResult<Self> {
501 Self::open(IambId::RoomList, store)
502 }
467503}
468504
469505#[derive(Clone)]
src/windows/room/chat.rs +7
@@ -44,6 +44,7 @@ use super::scrollback::{Scrollback, ScrollbackState};
4444
4545pub struct ChatState {
4646 room_id: OwnedRoomId,
47 room: MatrixRoom,
4748
4849 tbox: TextBoxState<IambInfo>,
4950 sent: HistoryList<EditRope>,
@@ -63,6 +64,7 @@ impl ChatState {
6364
6465 ChatState {
6566 room_id,
67 room,
6668
6769 tbox,
6870 sent: HistoryList::new(EditRope::from(""), 100),
@@ -80,6 +82,10 @@ impl ChatState {
8082 };
8183 }
8284
85 pub fn room(&self) -> &MatrixRoom {
86 &self.room
87 }
88
8389 pub fn id(&self) -> &RoomId {
8490 &self.room_id
8591 }
@@ -133,6 +139,7 @@ impl WindowOps<IambInfo> for ChatState {
133139
134140 ChatState {
135141 room_id: self.room_id.clone(),
142 room: self.room.clone(),
136143
137144 tbox,
138145 sent: self.sent.clone(),
src/windows/room/mod.rs +35 −4
@@ -2,7 +2,13 @@ use matrix_sdk::room::Room as MatrixRoom;
22use matrix_sdk::ruma::RoomId;
33use matrix_sdk::DisplayName;
44
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};
612
713use modalkit::{
814 editing::action::{
@@ -90,7 +96,7 @@ impl RoomState {
9096 &mut self,
9197 act: RoomAction,
9298 _: ProgramContext,
93 _: &mut ProgramStore,
99 store: &mut ProgramStore,
94100 ) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
95101 match act {
96102 RoomAction::Members(mut cmd) => {
@@ -103,11 +109,29 @@ impl RoomState {
103109
104110 Ok(vec![(act, cmd.context.take())])
105111 },
112 RoomAction::Set(field) => {
113 store.application.worker.set_room(self.id().to_owned(), field)?;
114
115 Ok(vec![])
116 },
106117 }
107118 }
108119
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)
111135 }
112136
113137 pub fn focus_toggle(&mut self) {
@@ -117,6 +141,13 @@ impl RoomState {
117141 }
118142 }
119143
144 pub fn room(&self) -> &MatrixRoom {
145 match self {
146 RoomState::Chat(chat) => chat.room(),
147 RoomState::Space(space) => space.room(),
148 }
149 }
150
120151 pub fn id(&self) -> &RoomId {
121152 match self {
122153 RoomState::Chat(chat) => chat.id(),
src/windows/room/space.rs +7 −1
@@ -18,6 +18,7 @@ use crate::windows::RoomItem;
1818
1919pub struct SpaceState {
2020 room_id: OwnedRoomId,
21 room: MatrixRoom,
2122 list: ListState<RoomItem, IambInfo>,
2223}
2324
@@ -27,7 +28,11 @@ impl SpaceState {
2728 let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback);
2829 let list = ListState::new(content, vec![]);
2930
30 SpaceState { room_id, list }
31 SpaceState { room_id, room, list }
32 }
33
34 pub fn room(&self) -> &MatrixRoom {
35 &self.room
3136 }
3237
3338 pub fn id(&self) -> &RoomId {
@@ -37,6 +42,7 @@ impl SpaceState {
3742 pub fn dup(&self, store: &mut ProgramStore) -> Self {
3843 SpaceState {
3944 room_id: self.room_id.clone(),
45 room: self.room.clone(),
4046 list: self.list.dup(store),
4147 }
4248 }
src/worker.rs +40 −3
@@ -30,8 +30,11 @@ use matrix_sdk::{
3030 start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent},
3131 VerificationMethod,
3232 },
33 room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
34 room::name::RoomNameEventContent,
33 room::{
34 message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
35 name::RoomNameEventContent,
36 topic::RoomTopicEventContent,
37 },
3538 typing::SyncTypingEvent,
3639 AnyMessageLikeEvent,
3740 AnyTimelineEvent,
@@ -51,7 +54,7 @@ use matrix_sdk::{
5154use modalkit::editing::action::{EditInfo, InfoMessage, UIError};
5255
5356use crate::{
54 base::{AsyncProgramStore, IambError, IambResult, VerifyAction},
57 base::{AsyncProgramStore, IambError, IambResult, SetRoomField, VerifyAction},
5558 message::{Message, MessageFetchResult, MessageTimeStamp},
5659 ApplicationSettings,
5760};
@@ -106,6 +109,7 @@ pub enum WorkerTask {
106109 SpaceMembers(OwnedRoomId, ClientReply<IambResult<Vec<OwnedRoomId>>>),
107110 Spaces(ClientReply<Vec<(MatrixRoom, DisplayName)>>),
108111 SendMessage(OwnedRoomId, String, ClientReply<IambResult<EchoPair>>),
112 SetRoom(OwnedRoomId, SetRoomField, ClientReply<IambResult<()>>),
109113 TypingNotice(OwnedRoomId),
110114 Verify(VerifyAction, SasVerification, ClientReply<IambResult<EditInfo>>),
111115 VerifyRequest(OwnedUserId, ClientReply<IambResult<EditInfo>>),
@@ -204,6 +208,14 @@ impl Requester {
204208 return response.recv();
205209 }
206210
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
207219 pub fn spaces(&self) -> Vec<(MatrixRoom, DisplayName)> {
208220 let (reply, response) = oneshot();
209221
@@ -340,6 +352,10 @@ impl ClientWorker {
340352 assert!(self.initialized);
341353 reply.send(self.members(room_id).await);
342354 },
355 WorkerTask::SetRoom(room_id, field, reply) => {
356 assert!(self.initialized);
357 reply.send(self.set_room(room_id, field).await);
358 },
343359 WorkerTask::SpaceMembers(space, reply) => {
344360 assert!(self.initialized);
345361 reply.send(self.space_members(space).await);
@@ -765,6 +781,27 @@ impl ClientWorker {
765781 }
766782 }
767783
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
768805 async fn space_members(&mut self, space: OwnedRoomId) -> IambResult<Vec<OwnedRoomId>> {
769806 let mut req = SpaceHierarchyRequest::new(&space);
770807 req.limit = Some(1000u32.into());