Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: add previous power levels to OtherState::RoomPowerLevels #3199

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions bindings/matrix-sdk-ffi/src/timeline/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub enum OtherState {
RoomJoinRules,
RoomName { name: Option<String> },
RoomPinnedEvents,
RoomPowerLevels { users: HashMap<String, i64> },
RoomPowerLevels { users: HashMap<String, i64>, previous: Option<HashMap<String, i64>> },
RoomServerAcl,
RoomThirdPartyInvite { display_name: Option<String> },
RoomTombstone,
Expand Down Expand Up @@ -354,16 +354,28 @@ impl From<&matrix_sdk_ui::timeline::AnyOtherFullStateEventContent> for OtherStat
}
Content::RoomPinnedEvents(_) => Self::RoomPinnedEvents,
Content::RoomPowerLevels(c) => {
let changes = match c {
let previous: Option<HashMap<String, i64>>;
let users: HashMap<String, i64>;
match c {
FullContent::Original { content, prev_content } => {
power_level_user_changes(content, prev_content)
previous = prev_content.as_ref().map(|prev_content| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: can you have each branch return a Self::RoomPowerLevels immediately, instead of having two temporary variables? it would read slightly more straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I just did it this way to not repeat too much code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ff911e4

prev_content
.users
.iter()
.map(|(k, &v)| (k.to_string(), v.into()))
.collect()
});
users = power_level_user_changes(content, prev_content)
.iter()
.map(|(k, v)| (k.to_string(), *v))
.collect()
}
FullContent::Redacted(_) => Default::default(),
FullContent::Redacted(_) => {
previous = None;
users = Default::default();
}
};
Self::RoomPowerLevels { users: changes }
Self::RoomPowerLevels { users, previous }
}
Content::RoomServerAcl(_) => Self::RoomServerAcl,
Content::RoomThirdPartyInvite(c) => {
Expand Down
Loading