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 8083402
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions bindings/matrix-sdk-ffi/src/timeline/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{collections::HashMap, sync::Arc};

use matrix_sdk::room::power_levels::power_level_user_changes;
use matrix_sdk_ui::timeline::{PollResult, TimelineDetails};
use ruma::{directory::RoomTypeFilter::Default, OwnedUserId};
use tracing::warn;

use super::ProfileDetails;
Expand Down Expand Up @@ -310,7 +311,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 +355,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 = Default::default();
users = Default::default();
}
};
Self::RoomPowerLevels { users: changes }
Self::RoomPowerLevels { users, previous }
}
Content::RoomServerAcl(_) => Self::RoomServerAcl,
Content::RoomThirdPartyInvite(c) => {
Expand Down

0 comments on commit 8083402

Please sign in to comment.