diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index 5a5abefb2a..5ee4cbd3a7 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -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 diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 7c6008c287..5f4551eed6 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -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 diff --git a/backend/canisters/user/CHANGELOG.md b/backend/canisters/user/CHANGELOG.md index 047034da93..66d4c55013 100644 --- a/backend/canisters/user/CHANGELOG.md +++ b/backend/canisters/user/CHANGELOG.md @@ -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)) diff --git a/backend/libraries/chat_events/src/chat_events.rs b/backend/libraries/chat_events/src/chat_events.rs index 0b692ca8ff..430f984570 100644 --- a/backend/libraries/chat_events/src/chat_events.rs +++ b/backend/libraries/chat_events/src/chat_events.rs @@ -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() @@ -1280,8 +1280,8 @@ impl ChatEvents { .and_then(|e| e.event.as_message()) } - fn expiry_date(&self, is_thread_event: bool, now: TimestampMillis) -> Option { - if is_thread_event { + fn expiry_date(&self, event: &ChatEventInternal, is_thread_event: bool, now: TimestampMillis) -> Option { + if is_thread_event || matches!(event, ChatEventInternal::EventsTimeToLiveUpdated(_)) { None } else { self.events_ttl.value.map(|d| now + d) diff --git a/backend/libraries/group_chat_core/src/lib.rs b/backend/libraries/group_chat_core/src/lib.rs index 8ab4309f64..f08aa3c425 100644 --- a/backend/libraries/group_chat_core/src/lib.rs +++ b/backend/libraries/group_chat_core/src/lib.rs @@ -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, @@ -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 }