From 808340236dbc8073dedb1954932cb81fa34425ec 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 | 27 +++++++++++++++---- 1 file changed, 22 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..4fa080424bc 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/content.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/content.rs @@ -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; @@ -310,7 +311,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 +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>; + 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 = Default::default(); + users = Default::default(); + } }; - Self::RoomPowerLevels { users: changes } + Self::RoomPowerLevels { users, previous } } Content::RoomServerAcl(_) => Self::RoomServerAcl, Content::RoomThirdPartyInvite(c) => {