Skip to content

Commit

Permalink
Store timestamp in the member_channel_links_removed map (#6918)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 28, 2024
1 parent 9ae8d11 commit e871f8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 6 additions & 6 deletions backend/canisters/community/impl/src/model/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct CommunityMembers {
#[serde(default)]
member_channel_links: BTreeSet<(UserId, ChannelId)>,
#[serde(default)]
member_channel_links_removed: BTreeSet<(UserId, ChannelId)>,
member_channel_links_removed: BTreeMap<(UserId, ChannelId), TimestampMillis>,
user_groups: UserGroups,
// This includes the userIds of community members and also users invited to the community
principal_to_user_id_map: BTreeMap<Principal, UserId>,
Expand Down Expand Up @@ -64,7 +64,7 @@ impl CommunityMembers {
}
for channel_removed in member.channels_removed.iter() {
self.member_channel_links_removed
.insert((member.user_id, channel_removed.value));
.insert((member.user_id, channel_removed.value), channel_removed.timestamp);
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl CommunityMembers {
CommunityMembers {
members: vec![(creator_user_id, member)].into_iter().collect(),
member_channel_links: public_channels.into_iter().map(|c| (creator_user_id, c)).collect(),
member_channel_links_removed: BTreeSet::new(),
member_channel_links_removed: BTreeMap::new(),
user_groups: UserGroups::default(),
principal_to_user_id_map: vec![(creator_principal, creator_user_id)].into_iter().collect(),
member_ids: [creator_user_id].into_iter().collect(),
Expand Down Expand Up @@ -366,7 +366,7 @@ impl CommunityMembers {
if let Some(member) = self.members.get_mut(&user_id) {
if member.leave(channel_id, now) {
self.member_channel_links.remove(&(user_id, channel_id));
self.member_channel_links_removed.insert((user_id, channel_id));
self.member_channel_links_removed.insert((user_id, channel_id), now);
}
}
}
Expand Down Expand Up @@ -455,8 +455,8 @@ impl CommunityMembers {
.map(|(_, c)| *c)
}

pub fn member_channel_links_removed(&self) -> &BTreeSet<(UserId, ChannelId)> {
&self.member_channel_links_removed
pub fn member_channel_links_removed_contains(&self, user_id: UserId, channel_id: ChannelId) -> bool {
self.member_channel_links_removed.contains_key(&(user_id, channel_id))
}

pub fn owners(&self) -> &BTreeSet<UserId> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ fn update_channel_impl(mut args: Args, state: &mut RuntimeState) -> Response {
let channel_id = channel.id;
let mut user_ids = Vec::with_capacity(state.data.members.member_ids().len());
user_ids.extend(state.data.members.member_ids().iter().filter(|&user_id| {
!state
.data
.members
.member_channel_links_removed()
.contains(&(*user_id, channel_id))
!state.data.members.member_channel_links_removed_contains(*user_id, channel_id)
}));

add_members_to_public_channel_unchecked(
Expand Down

0 comments on commit e871f8d

Please sign in to comment.