Skip to content

Commit

Permalink
Don't set expiry on EventsTimeToLiveUpdated events (#4616)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Oct 18, 2023
1 parent 0c56948 commit 0fbdda4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Don't auto-join gated channels ([#4561](https://github.com/open-chat-labs/open-chat/pull/4561))
- Adjust `MemoryManager` bucket size ([#4601](https://github.com/open-chat-labs/open-chat/pull/4601))
- Set memo based on transaction type ([#4603](https://github.com/open-chat-labs/open-chat/pull/4603))
- Don't set expiry on `EventsTimeToLiveUpdated` events ([#4616](https://github.com/open-chat-labs/open-chat/pull/4616))

## [[2.0.875](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.875-community)] - 2023-10-06

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 @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Allow @everyone to be followed by some punctuation ([#4553](https://github.com/open-chat-labs/open-chat/pull/4553))
- Adjust `MemoryManager` bucket size ([#4601](https://github.com/open-chat-labs/open-chat/pull/4601))
- Set memo based on transaction type ([#4603](https://github.com/open-chat-labs/open-chat/pull/4603))
- Don't set expiry on `EventsTimeToLiveUpdated` events ([#4616](https://github.com/open-chat-labs/open-chat/pull/4616))

### Removed

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

- Don't set expiry on `EventsTimeToLiveUpdated` events ([#4616](https://github.com/open-chat-labs/open-chat/pull/4616))

### Fixed

- Add `serde(default)` attribute to fix a few failed upgrades ([#4610](https://github.com/open-chat-labs/open-chat/pull/4610))
Expand Down
6 changes: 3 additions & 3 deletions backend/libraries/chat_events/src/chat_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ impl ChatEvents {
panic!("Event type is not valid: {event:?}");
}

let expires_at = self.expiry_date(thread_root_message_index.is_some(), now);
let expires_at = self.expiry_date(&event, thread_root_message_index.is_some(), now);

let events_list = if let Some(root_message_index) = thread_root_message_index {
self.threads.get_mut(&root_message_index).unwrap()
Expand Down Expand Up @@ -1280,8 +1280,8 @@ impl ChatEvents {
.and_then(|e| e.event.as_message())
}

fn expiry_date(&self, is_thread_event: bool, now: TimestampMillis) -> Option<TimestampMillis> {
if is_thread_event {
fn expiry_date(&self, event: &ChatEventInternal, is_thread_event: bool, now: TimestampMillis) -> Option<TimestampMillis> {
if is_thread_event || matches!(event, ChatEventInternal::EventsTimeToLiveUpdated(_)) {
None
} else {
self.events_ttl.value.map(|d| now + d)
Expand Down
19 changes: 9 additions & 10 deletions backend/libraries/group_chat_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,17 +1470,11 @@ impl GroupChatCore {
);
}

if let Some(new_events_ttl) = events_ttl.expand() {
if new_events_ttl != events.get_events_time_to_live().value {
events.set_events_time_to_live(user_id, new_events_ttl, now);
}
}

if let Some(gate) = gate.expand() {
if self.gate.value != gate {
self.gate = Timestamped::new(gate.clone(), now);

self.events.push_main_event(
events.push_main_event(
ChatEventInternal::GroupGateUpdated(Box::new(GroupGateUpdated {
updated_by: user_id,
new_gate: gate,
Expand All @@ -1501,17 +1495,22 @@ impl GroupChatCore {
};

let push_event_result =
self.events
.push_main_event(ChatEventInternal::GroupVisibilityChanged(Box::new(event)), 0, now);
events.push_main_event(ChatEventInternal::GroupVisibilityChanged(Box::new(event)), 0, now);

if self.is_public {
self.min_visible_indexes_for_new_members =
Some((push_event_result.index, self.events.main_events_list().next_message_index()));
Some((push_event_result.index, events.main_events_list().next_message_index()));
result.newly_public = true;
}
}
}

if let Some(new_events_ttl) = events_ttl.expand() {
if new_events_ttl != events.get_events_time_to_live().value {
events.set_events_time_to_live(user_id, new_events_ttl, now);
}
}

result
}

Expand Down

0 comments on commit 0fbdda4

Please sign in to comment.