Skip to content

Commit c183fdb

Browse files
committed
refactor(ffi): Handle all unknown join rules with JoinRule::Custom
Signed-off-by: Kévin Commaille <[email protected]>
1 parent 07d428a commit c183fdb

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ All notable changes to this project will be documented in this file.
1515

1616
### Breaking changes:
1717

18+
- `RoomPreview::info()` doesn't return a result anymore. All unknown join rules are handled in the
19+
`JoinRule::Custom` variant.
1820
- The `reason` argument of `Room::report_room` is now required, do to a clarification in the spec.
1921
([#5337](https://github.com/matrix-org/matrix-rust-sdk/pull/5337))
2022
- `PublicRoomJoinRule` has more variants, supporting all the known values from the spec.

bindings/matrix-sdk-ffi/src/room_preview.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::Context as _;
22
use matrix_sdk::{room_preview::RoomPreview as SdkRoomPreview, Client};
33
use ruma::room::{JoinRuleSummary, RoomType as RumaRoomType};
4-
use tracing::warn;
54

65
use crate::{
76
client::{AllowRule, JoinRule},
@@ -22,9 +21,9 @@ pub struct RoomPreview {
2221
#[matrix_sdk_ffi_macros::export]
2322
impl RoomPreview {
2423
/// Returns the room info the preview contains.
25-
pub fn info(&self) -> Result<RoomPreviewInfo, ClientError> {
24+
pub fn info(&self) -> RoomPreviewInfo {
2625
let info = &self.inner;
27-
Ok(RoomPreviewInfo {
26+
RoomPreviewInfo {
2827
room_id: info.room_id.to_string(),
2928
canonical_alias: info.canonical_alias.as_ref().map(|alias| alias.to_string()),
3029
name: info.name.clone(),
@@ -35,18 +34,13 @@ impl RoomPreview {
3534
room_type: info.room_type.as_ref().into(),
3635
is_history_world_readable: info.is_world_readable,
3736
membership: info.state.map(|state| state.into()),
38-
join_rule: info
39-
.join_rule
40-
.as_ref()
41-
.map(TryInto::try_into)
42-
.transpose()
43-
.map_err(|_| anyhow::anyhow!("unhandled JoinRuleSummary kind"))?,
37+
join_rule: info.join_rule.as_ref().map(Into::into),
4438
is_direct: info.is_direct,
4539
heroes: info
4640
.heroes
4741
.as_ref()
4842
.map(|heroes| heroes.iter().map(|h| h.to_owned().into()).collect()),
49-
})
43+
}
5044
}
5145

5246
/// Leave the room if the room preview state is either joined, invited or
@@ -122,11 +116,9 @@ pub struct RoomPreviewInfo {
122116
pub heroes: Option<Vec<RoomHero>>,
123117
}
124118

125-
impl TryFrom<&JoinRuleSummary> for JoinRule {
126-
type Error = ();
127-
128-
fn try_from(join_rule: &JoinRuleSummary) -> Result<Self, ()> {
129-
Ok(match join_rule {
119+
impl From<&JoinRuleSummary> for JoinRule {
120+
fn from(join_rule: &JoinRuleSummary) -> Self {
121+
match join_rule {
130122
JoinRuleSummary::Invite => JoinRule::Invite,
131123
JoinRuleSummary::Knock => JoinRule::Knock,
132124
JoinRuleSummary::Private => JoinRule::Private,
@@ -145,12 +137,8 @@ impl TryFrom<&JoinRuleSummary> for JoinRule {
145137
.collect(),
146138
},
147139
JoinRuleSummary::Public => JoinRule::Public,
148-
JoinRuleSummary::_Custom(_) => JoinRule::Custom { repr: join_rule.as_str().to_owned() },
149-
_ => {
150-
warn!("unhandled JoinRuleSummary: {}", join_rule.as_str());
151-
return Err(());
152-
}
153-
})
140+
_ => JoinRule::Custom { repr: join_rule.as_str().to_owned() },
141+
}
154142
}
155143
}
156144

0 commit comments

Comments
 (0)