| @@ -15,6 +15,7 @@ use matrix_sdk::{ |
| 15 | events::{ |
15 | events::{ |
| 16 | room::{ |
16 | room::{ |
| 17 | canonical_alias::RoomCanonicalAliasEventContent, |
17 | canonical_alias::RoomCanonicalAliasEventContent, |
| |
18 | history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, |
| 18 | name::RoomNameEventContent, |
19 | name::RoomNameEventContent, |
| 19 | topic::RoomTopicEventContent, |
20 | topic::RoomTopicEventContent, |
| 20 | }, |
21 | }, |
| @@ -98,6 +99,20 @@ fn notification_mode(name: impl Into<String>) -> IambResult<RoomNotificationMode |
| 98 | Ok(mode) |
99 | Ok(mode) |
| 99 | } |
100 | } |
| 100 | |
101 | |
| |
102 | fn hist_visibility_mode(name: impl Into<String>) -> IambResult<HistoryVisibility> { |
| |
103 | let name = name.into(); |
| |
104 | |
| |
105 | let mode = match name.to_lowercase().as_str() { |
| |
106 | "invited" => HistoryVisibility::Invited, |
| |
107 | "joined" => HistoryVisibility::Joined, |
| |
108 | "shared" => HistoryVisibility::Shared, |
| |
109 | "world" | "world_readable" => HistoryVisibility::WorldReadable, |
| |
110 | _ => return Err(IambError::InvalidHistoryVisibility(name).into()), |
| |
111 | }; |
| |
112 | |
| |
113 | Ok(mode) |
| |
114 | } |
| |
115 | |
| 101 | /// State for a Matrix room or space. |
116 | /// State for a Matrix room or space. |
| 102 | /// |
117 | /// |
| 103 | /// Since spaces function as special rooms within Matrix, we wrap their window state together, so |
118 | /// Since spaces function as special rooms within Matrix, we wrap their window state together, so |
| @@ -339,6 +354,11 @@ impl RoomState { |
| 339 | .ok_or(UIError::Application(IambError::NotJoined))?; |
354 | .ok_or(UIError::Application(IambError::NotJoined))?; |
| 340 | |
355 | |
| 341 | match field { |
356 | match field { |
| |
357 | RoomField::History => { |
| |
358 | let visibility = hist_visibility_mode(value)?; |
| |
359 | let ev = RoomHistoryVisibilityEventContent::new(visibility); |
| |
360 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
| |
361 | }, |
| 342 | RoomField::Name => { |
362 | RoomField::Name => { |
| 343 | let ev = RoomNameEventContent::new(value); |
363 | let ev = RoomNameEventContent::new(value); |
| 344 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
364 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
| @@ -455,6 +475,11 @@ impl RoomState { |
| 455 | .ok_or(UIError::Application(IambError::NotJoined))?; |
475 | .ok_or(UIError::Application(IambError::NotJoined))?; |
| 456 | |
476 | |
| 457 | match field { |
477 | match field { |
| |
478 | RoomField::History => { |
| |
479 | let visibility = HistoryVisibility::Joined; |
| |
480 | let ev = RoomHistoryVisibilityEventContent::new(visibility); |
| |
481 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
| |
482 | }, |
| 458 | RoomField::Name => { |
483 | RoomField::Name => { |
| 459 | let ev = RoomNameEventContent::new("".into()); |
484 | let ev = RoomNameEventContent::new("".into()); |
| 460 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
485 | let _ = room.send_state_event(ev).await.map_err(IambError::from)?; |
| @@ -545,6 +570,10 @@ impl RoomState { |
| 545 | .ok_or(UIError::Application(IambError::NotJoined))?; |
570 | .ok_or(UIError::Application(IambError::NotJoined))?; |
| 546 | |
571 | |
| 547 | let msg = match field { |
572 | let msg = match field { |
| |
573 | RoomField::History => { |
| |
574 | let visibility = room.history_visibility(); |
| |
575 | format!("Room history visibility: {visibility}") |
| |
576 | }, |
| 548 | RoomField::Name => { |
577 | RoomField::Name => { |
| 549 | match room.name() { |
578 | match room.name() { |
| 550 | None => "Room has no name".into(), |
579 | None => "Room has no name".into(), |