Skip to content

Commit

Permalink
MatrixRTC: Fix different devices from the same user overwriting the r…
Browse files Browse the repository at this point in the history
…oom info state event.
  • Loading branch information
toger5 authored and Hywan committed Sep 17, 2024
1 parent decdd6f commit 8119697
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 66 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ once_cell = "1.16.0"
pin-project-lite = "0.2.9"
rand = "0.8.5"
reqwest = { version = "0.12.4", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "92a35381b56ffa3c2a611287bb5011f574271478", features = [
ruma = { git = "https://github.com/ruma/ruma", rev = "1ae98db9c44f46a590f4c76baf5cef70ebb6970d", features = [
"client-api-c",
"compat-upload-signatures",
"compat-user-id",
Expand All @@ -61,7 +61,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "92a35381b56ffa3c2a611287bb
"unstable-msc4075",
"unstable-msc4140",
] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "92a35381b56ffa3c2a611287bb5011f574271478" }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "1ae98db9c44f46a590f4c76baf5cef70ebb6970d" }
serde = "1.0.151"
serde_html_form = "0.2.0"
serde_json = "1.0.91"
Expand Down
20 changes: 10 additions & 10 deletions crates/matrix-sdk-base/src/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ruma::{
assign,
events::{
beacon_info::BeaconInfoEventContent,
call::member::CallMemberEventContent,
call::member::{CallMemberEventContent, CallMemberStateKey},
macros::EventContent,
room::{
avatar::RoomAvatarEventContent,
Expand Down Expand Up @@ -112,7 +112,8 @@ pub struct BaseRoomInfo {
/// All minimal state events that containing one or more running matrixRTC
/// memberships.
#[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
pub(crate) rtc_member: BTreeMap<OwnedUserId, MinimalStateEvent<CallMemberEventContent>>,
pub(crate) rtc_member_events:
BTreeMap<CallMemberStateKey, MinimalStateEvent<CallMemberEventContent>>,
/// Whether this room has been manually marked as unread.
#[serde(default)]
pub(crate) is_marked_unread: bool,
Expand Down Expand Up @@ -195,14 +196,12 @@ impl BaseRoomInfo {
let mut o_ev = o_ev.clone();
o_ev.content.set_created_ts_if_none(o_ev.origin_server_ts);

// add the new event.
self.rtc_member.insert(
m.state_key().user_id().to_owned(),
SyncStateEvent::Original(o_ev).into(),
);
// Add the new event.
self.rtc_member_events
.insert(m.state_key().clone(), SyncStateEvent::Original(o_ev).into());

// Remove all events that don't contain any memberships anymore.
self.rtc_member.retain(|_, ev| {
self.rtc_member_events.retain(|_, ev| {
ev.as_original().is_some_and(|o| !o.content.active_memberships(None).is_empty())
});
}
Expand Down Expand Up @@ -302,7 +301,8 @@ impl BaseRoomInfo {
} else if self.topic.has_event_id(redacts) {
self.topic.as_mut().unwrap().redact(&room_version);
} else {
self.rtc_member.retain(|_, member_event| member_event.event_id() != Some(redacts));
self.rtc_member_events
.retain(|_, member_event| member_event.event_id() != Some(redacts));
}
}

Expand Down Expand Up @@ -367,7 +367,7 @@ impl Default for BaseRoomInfo {
name: None,
tombstone: None,
topic: None,
rtc_member: BTreeMap::new(),
rtc_member_events: BTreeMap::new(),
is_marked_unread: false,
notable_tags: RoomNotableTags::empty(),
pinned_events: None,
Expand Down
Loading

0 comments on commit 8119697

Please sign in to comment.