Skip to content

Commit

Permalink
Return unfollowed threads in updates loop (#4445)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Sep 26, 2023
1 parent 43d7195 commit 2ce7bec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl Channel {
m.user_id,
now,
),
unfollowed_threads: self.chat.events.unfollowed_threads(m.threads.iter(), since, m.user_id),
rules_accepted: m
.rules_accepted
.as_ref()
Expand Down
3 changes: 3 additions & 0 deletions backend/canisters/group/impl/src/queries/summary_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ fn summary_updates_impl(args: Args, state: &RuntimeState) -> Response {
member.user_id,
now,
),
unfollowed_threads: chat
.events
.unfollowed_threads(member.threads.iter(), args.updates_since, member.user_id),
notifications_muted: member.notifications_muted.if_set_after(args.updates_since).cloned(),
frozen: state
.data
Expand Down
26 changes: 26 additions & 0 deletions backend/libraries/chat_events/src/chat_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,32 @@ impl ChatEvents {
.collect()
}

pub fn unfollowed_threads<'a>(
&self,
root_message_indexes: impl Iterator<Item = &'a MessageIndex>,
updated_since: TimestampMillis,
my_user_id: UserId,
) -> Vec<MessageIndex> {
root_message_indexes
.filter_map(|root_message_index| {
let follower = self
.main
.get((*root_message_index).into(), EventIndex::default(), 0)?
.event
.as_message()?
.thread_summary
.as_ref()?
.get_follower(my_user_id)?;

if !follower.value && follower.timestamp > updated_since {
Some(*root_message_index)
} else {
None
}
})
.collect()
}

pub fn freeze(&mut self, user_id: UserId, reason: Option<String>, now: TimestampMillis) -> PushEventResult {
let push_event_result = self.push_event(
None,
Expand Down
2 changes: 2 additions & 0 deletions backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ type GroupCanisterGroupChatSummaryUpdates = record {
my_metrics : opt ChatMetrics;
is_public : opt bool;
latest_threads : vec GroupCanisterThreadDetails;
unfollowed_threads : vec MessageIndex;
notifications_muted : opt bool;
frozen : FrozenGroupUpdate;
wasm_version : opt BuildVersion;
Expand Down Expand Up @@ -465,6 +466,7 @@ type ChannelMembershipUpdates = record {
notifications_muted : opt bool;
my_metrics : opt ChatMetrics;
latest_threads : vec GroupCanisterThreadDetails;
unfollowed_threads : vec MessageIndex;
rules_accepted : opt bool;
};

Expand Down
2 changes: 2 additions & 0 deletions backend/libraries/types/src/channel_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct ChannelMembershipUpdates {
pub notifications_muted: Option<bool>,
pub my_metrics: Option<ChatMetrics>,
pub latest_threads: Vec<GroupCanisterThreadDetails>,
#[serde(default)]
pub unfollowed_threads: Vec<MessageIndex>,
pub rules_accepted: Option<bool>,
}

Expand Down
2 changes: 2 additions & 0 deletions backend/libraries/types/src/chat_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ pub struct GroupCanisterGroupChatSummaryUpdates {
pub my_metrics: Option<ChatMetrics>,
pub is_public: Option<bool>,
pub latest_threads: Vec<GroupCanisterThreadDetails>,
#[serde(default)]
pub unfollowed_threads: Vec<MessageIndex>,
pub notifications_muted: Option<bool>,
pub frozen: OptionUpdate<FrozenGroupInfo>,
pub date_last_pinned: Option<TimestampMillis>,
Expand Down

0 comments on commit 2ce7bec

Please sign in to comment.