Skip to content

Commit

Permalink
ffi: add previous power levels to OtherState::RoomPowerLevels
Browse files Browse the repository at this point in the history
This is needed to be able to diff between increases and decreases of power levels.
  • Loading branch information
jmartinesp committed Mar 8, 2024
1 parent b7d6fd0 commit ead2e14
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 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,32 @@ 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 = if let Some(prev_content) = prev_content {
Some(
prev_content
.users
.iter()
.map(|(k, &v)| (k.to_string(), v.into()))
.collect(),
)
} else {
None
};
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

0 comments on commit ead2e14

Please sign in to comment.