From ead2e140261d264b6a700778a8474dc7980fdd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 8 Mar 2024 11:51:21 +0100 Subject: [PATCH] ffi: add `previous` power levels to `OtherState::RoomPowerLevels` This is needed to be able to diff between increases and decreases of power levels. --- .../matrix-sdk-ffi/src/timeline/content.rs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/timeline/content.rs b/bindings/matrix-sdk-ffi/src/timeline/content.rs index 51e71e6b9e0..21aee269ec3 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/content.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/content.rs @@ -310,7 +310,7 @@ pub enum OtherState { RoomJoinRules, RoomName { name: Option }, RoomPinnedEvents, - RoomPowerLevels { users: HashMap }, + RoomPowerLevels { users: HashMap, previous: Option> }, RoomServerAcl, RoomThirdPartyInvite { display_name: Option }, RoomTombstone, @@ -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>; + let users: HashMap; + 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) => {