Skip to content

Commit

Permalink
Add events_ttl_last_updated to chat summaries (#4711)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Nov 7, 2023
1 parent b081f8a commit 9500891
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 114 deletions.
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Refund remaining prizes early if message gets deleted ([#4708](https://github.com/open-chat-labs/open-chat/pull/4708))
- Add `events_ttl_last_updated` to chat summaries ([#4711](https://github.com/open-chat-labs/open-chat/pull/4711))

## [[2.0.921](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.921-community)] - 2023-11-02

Expand Down
5 changes: 4 additions & 1 deletion backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl Channel {

let main_events_reader = chat.events.visible_main_events_reader(min_visible_event_index);
let latest_message = if can_view_latest_message { main_events_reader.latest_message_event(user_id) } else { None };
let events_ttl = chat.events.get_events_time_to_live();

let latest_message_sender_display_name = latest_message
.as_ref()
Expand Down Expand Up @@ -257,7 +258,8 @@ impl Channel {
permissions_v2: chat.permissions.value.clone(),
metrics: chat.events.metrics().hydrate(),
date_last_pinned: chat.date_last_pinned,
events_ttl: chat.events.get_events_time_to_live().value,
events_ttl: events_ttl.value,
events_ttl_last_updated: events_ttl.timestamp,
gate: chat.gate.value.clone(),
membership,
})
Expand Down Expand Up @@ -339,6 +341,7 @@ impl Channel {
metrics: Some(self.chat.events.metrics().hydrate()),
date_last_pinned: updates.date_last_pinned,
events_ttl: updates.events_ttl,
events_ttl_last_updated: updates.events_ttl_last_updated,
gate: updates.gate,
membership,
})
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Refund remaining prizes early if message gets deleted ([#4708](https://github.com/open-chat-labs/open-chat/pull/4708))
- Add `events_ttl_last_updated` to chat summaries ([#4711](https://github.com/open-chat-labs/open-chat/pull/4711))

## [[2.0.922](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.922-group)] - 2023-11-02

Expand Down
4 changes: 3 additions & 1 deletion backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl RuntimeState {
let min_visible_event_index = member.min_visible_event_index();
let min_visible_message_index = member.min_visible_message_index();
let main_events_reader = chat.events.visible_main_events_reader(min_visible_event_index);
let events_ttl = chat.events.get_events_time_to_live();

GroupCanisterGroupChatSummary {
chat_id: self.env.canister_id().into(),
Expand Down Expand Up @@ -142,7 +143,8 @@ impl RuntimeState {
frozen: self.data.frozen.value.clone(),
wasm_version: BuildVersion::default(),
date_last_pinned: chat.date_last_pinned,
events_ttl: chat.events.get_events_time_to_live().value,
events_ttl: events_ttl.value,
events_ttl_last_updated: events_ttl.timestamp,
gate: chat.gate.value.clone(),
rules_accepted: member
.rules_accepted
Expand Down
4 changes: 3 additions & 1 deletion backend/canisters/group/impl/src/queries/public_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn public_summary_impl(args: Args, state: &RuntimeState) -> Response {
let is_public = state.data.chat.is_public.value;
let data = &state.data;
let events_reader = data.chat.events.main_events_reader();
let events_ttl = data.chat.events.get_events_time_to_live();

// You can't see private group messages unless you are a member of the group
let latest_message = if is_public || state.data.get_member(caller).is_some() {
Expand All @@ -42,7 +43,8 @@ fn public_summary_impl(args: Args, state: &RuntimeState) -> Response {
participant_count: data.chat.members.len(),
is_public,
frozen: data.frozen.value.clone(),
events_ttl: data.chat.events.get_events_time_to_live().value,
events_ttl: events_ttl.value,
events_ttl_last_updated: events_ttl.timestamp,
gate: data.chat.gate.value.clone(),
wasm_version: BuildVersion::default(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ fn summary_updates_impl(args: Args, state: &RuntimeState) -> Response {
wasm_version: None,
date_last_pinned: updates.date_last_pinned,
events_ttl: updates.events_ttl,
events_ttl_last_updated: updates.events_ttl_last_updated,
gate: updates.gate,
rules_accepted: member
.rules_accepted
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `events_ttl_last_updated` to chat summaries ([#4711](https://github.com/open-chat-labs/open-chat/pull/4711))

## [[2.0.926](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.926-group_index)] - 2023-11-03

### Changed
Expand Down
34 changes: 2 additions & 32 deletions backend/canisters/group_index/impl/src/model/cached_hot_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl CachedHotGroups {
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(from = "CachedPublicGroupSummaryCombined")]
pub struct CachedPublicGroupSummary {
pub chat_id: ChatId,
pub last_updated: TimestampMillis,
Expand All @@ -45,41 +44,11 @@ pub struct CachedPublicGroupSummary {
pub latest_message_index: Option<MessageIndex>,
pub participant_count: u32,
pub events_ttl: Option<Milliseconds>,
pub gate: Option<AccessGate>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CachedPublicGroupSummaryCombined {
pub chat_id: ChatId,
pub last_updated: TimestampMillis,
pub latest_message: Option<EventWrapper<Message>>,
pub latest_event_index: EventIndex,
#[serde(default)]
pub latest_message_index: Option<MessageIndex>,
pub participant_count: u32,
pub events_ttl: Option<Milliseconds>,
pub events_ttl_last_updated: TimestampMillis,
pub gate: Option<AccessGate>,
}

impl From<CachedPublicGroupSummaryCombined> for CachedPublicGroupSummary {
fn from(value: CachedPublicGroupSummaryCombined) -> Self {
let latest_message_index = value
.latest_message_index
.or_else(|| value.latest_message.as_ref().map(|m| m.event.message_index));

CachedPublicGroupSummary {
chat_id: value.chat_id,
last_updated: value.last_updated,
latest_message: value.latest_message,
latest_event_index: value.latest_event_index,
latest_message_index,
participant_count: value.participant_count,
events_ttl: value.events_ttl,
gate: value.gate,
}
}
}

impl From<PublicGroupSummary> for CachedPublicGroupSummary {
fn from(summary: PublicGroupSummary) -> Self {
CachedPublicGroupSummary {
Expand All @@ -90,6 +59,7 @@ impl From<PublicGroupSummary> for CachedPublicGroupSummary {
latest_message_index: summary.latest_message_index,
participant_count: summary.participant_count,
events_ttl: summary.events_ttl,
events_ttl_last_updated: summary.events_ttl_last_updated,
gate: summary.gate,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl PublicGroups {
is_public: true,
frozen: None,
events_ttl: summary.events_ttl,
events_ttl_last_updated: summary.events_ttl_last_updated,
gate: summary.gate,
wasm_version: BuildVersion::default(),
})
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/user/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `events_ttl_last_updated` to chat summaries ([#4711](https://github.com/open-chat-labs/open-chat/pull/4711))

## [[2.0.923](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.923-user)] - 2023-11-03

### Added
Expand Down
10 changes: 6 additions & 4 deletions backend/canisters/user/impl/src/model/direct_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl DirectChat {

pub fn to_summary(&self, my_user_id: UserId) -> DirectChatSummary {
let events_reader = self.events.main_events_reader();
let events_ttl = self.events.get_events_time_to_live();

DirectChatSummary {
them: self.them,
Expand All @@ -98,7 +99,8 @@ impl DirectChat {
.map(|m| m.hydrate())
.unwrap_or_default(),
archived: self.archived.value,
events_ttl: self.events.get_events_time_to_live().value,
events_ttl: events_ttl.value,
events_ttl_last_updated: events_ttl.timestamp,
}
}

Expand All @@ -111,6 +113,7 @@ impl DirectChat {
let latest_message_index = if has_new_events { events_reader.latest_message_index() } else { None };
let notifications_muted = self.notifications_muted.if_set_after(updates_since).copied();
let metrics = if has_new_events { Some(self.events.metrics().hydrate()) } else { None };
let events_ttl = self.events.get_events_time_to_live();
let updated_events: Vec<_> = self
.events
.iter_recently_updated_events()
Expand All @@ -134,12 +137,11 @@ impl DirectChat {
.user_metrics(&my_user_id, Some(updates_since))
.map(|m| m.hydrate()),
archived: self.archived.if_set_after(updates_since).copied(),
events_ttl: self
.events
.get_events_time_to_live()
events_ttl: events_ttl
.if_set_after(updates_since)
.copied()
.map_or(OptionUpdate::NoChange, OptionUpdate::from_update),
events_ttl_last_updated: (events_ttl.timestamp > updates_since).then_some(events_ttl.timestamp),
}
}
}
1 change: 1 addition & 0 deletions backend/canisters/user/impl/src/queries/initial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn hydrate_cached_summary(cached: &GroupCanisterGroupChatSummary, user_details:
date_last_pinned: cached.date_last_pinned,
date_read_pinned: user_details.messages_read.date_read_pinned.value,
events_ttl: cached.events_ttl,
events_ttl_last_updated: cached.events_ttl_last_updated,
gate: cached.gate.clone(),
rules_accepted: cached.rules_accepted,
}
Expand Down
7 changes: 4 additions & 3 deletions backend/libraries/group_chat_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl GroupChatCore {
let mentions = member
.map(|m| m.most_recent_mentions(Some(since), &self.events))
.unwrap_or_default();
let events_ttl = self.events.get_events_time_to_live();
let mut updated_events: Vec<_> = self
.events
.iter_recently_updated_events()
Expand Down Expand Up @@ -205,12 +206,11 @@ impl GroupChatCore {
updated_events,
is_public: self.is_public.if_set_after(since).copied(),
date_last_pinned: self.date_last_pinned.filter(|ts| *ts > since),
events_ttl: self
.events
.get_events_time_to_live()
events_ttl: events_ttl
.if_set_after(since)
.copied()
.map_or(OptionUpdate::NoChange, OptionUpdate::from_update),
events_ttl_last_updated: (events_ttl.timestamp > since).then_some(events_ttl.timestamp),
gate: self
.gate
.if_set_after(since)
Expand Down Expand Up @@ -1867,6 +1867,7 @@ pub struct SummaryUpdates {
pub is_public: Option<bool>,
pub date_last_pinned: Option<TimestampMillis>,
pub events_ttl: OptionUpdate<Milliseconds>,
pub events_ttl_last_updated: Option<TimestampMillis>,
pub gate: OptionUpdate<AccessGate>,
pub rules_changed: bool,
}
Expand Down
8 changes: 8 additions & 0 deletions backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type DirectChatSummary = record {
my_metrics : ChatMetrics;
archived : bool;
events_ttl : opt Milliseconds;
events_ttl_last_updated : TimestampMillis;
};

type DirectChatSummaryUpdates = record {
Expand All @@ -146,6 +147,7 @@ type DirectChatSummaryUpdates = record {
my_metrics : opt ChatMetrics;
archived : opt bool;
events_ttl : EventsTimeToLiveUpdate;
events_ttl_last_updated : opt TimestampMillis;
};

type DirectMessageNotification = record {
Expand Down Expand Up @@ -275,6 +277,7 @@ type GroupChatSummary = record {
date_last_pinned : opt TimestampMillis;
date_read_pinned : opt TimestampMillis;
events_ttl : opt Milliseconds;
events_ttl_last_updated : TimestampMillis;
gate : opt AccessGate;
rules_accepted : bool;
};
Expand Down Expand Up @@ -306,6 +309,7 @@ type GroupCanisterGroupChatSummary = record {
wasm_version : BuildVersion;
date_last_pinned : opt TimestampMillis;
events_ttl : opt Milliseconds;
events_ttl_last_updated : TimestampMillis;
gate : opt AccessGate;
rules_accepted : bool;
};
Expand Down Expand Up @@ -335,6 +339,7 @@ type GroupCanisterGroupChatSummaryUpdates = record {
wasm_version : opt BuildVersion;
date_last_pinned : opt TimestampMillis;
events_ttl : EventsTimeToLiveUpdate;
events_ttl_last_updated : opt TimestampMillis;
gate : AccessGateUpdate;
rules_accepted : opt bool;
};
Expand Down Expand Up @@ -392,6 +397,7 @@ type CommunityCanisterChannelSummary = record {
metrics : ChatMetrics;
date_last_pinned : opt TimestampMillis;
events_ttl : opt Milliseconds;
events_ttl_last_updated : TimestampMillis;
gate : opt AccessGate;
membership : opt ChannelMembership;
};
Expand Down Expand Up @@ -453,6 +459,7 @@ type CommunityCanisterChannelSummaryUpdates = record {
metrics : opt ChatMetrics;
date_last_pinned : opt TimestampMillis;
events_ttl : EventsTimeToLiveUpdate;
events_ttl_last_updated : opt TimestampMillis;
gate : AccessGateUpdate;
membership : opt ChannelMembershipUpdates;
};
Expand Down Expand Up @@ -714,6 +721,7 @@ type PublicGroupSummary = record {
is_public : bool;
frozen : opt FrozenGroupInfo;
events_ttl : opt Milliseconds;
events_ttl_last_updated : TimestampMillis;
gate : opt AccessGate;
wasm_version : BuildVersion;
};
Expand Down
4 changes: 4 additions & 0 deletions backend/libraries/types/src/channel_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct CommunityCanisterChannelSummary {
pub metrics: ChatMetrics,
pub date_last_pinned: Option<TimestampMillis>,
pub events_ttl: Option<Milliseconds>,
#[serde(default)]
pub events_ttl_last_updated: TimestampMillis,
pub gate: Option<AccessGate>,
pub membership: Option<ChannelMembership>,
}
Expand Down Expand Up @@ -60,6 +62,8 @@ pub struct CommunityCanisterChannelSummaryUpdates {
pub metrics: Option<ChatMetrics>,
pub date_last_pinned: Option<TimestampMillis>,
pub events_ttl: OptionUpdate<Milliseconds>,
#[serde(default)]
pub events_ttl_last_updated: Option<TimestampMillis>,
pub gate: OptionUpdate<AccessGate>,
pub membership: Option<ChannelMembershipUpdates>,
}
Expand Down
Loading

0 comments on commit 9500891

Please sign in to comment.