BlueGit

ict rusty-teams

fix(chats): drop cached chats hidden by the chat service hidden time

- incremental syncs never re-check unchanged cached chats; the state refresh now removes them
- a fresh local unhide still wins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-09 · 3 weeks ago

Hash
90a519db5b140178a273990bea9259693b5cffd4
Parent
c708f2ca
2 files changed +28 −3
crates/core/src/hidden_chats.rs +1 −1
@@ -83,7 +83,7 @@ impl LocallyHidden {
83 83 self.unhidden_at.insert(chat_id.to_owned(), now);
84 84 }
85 85
86 fn unhide_override_active(&self, chat_id: &str, now: DateTime<Utc>) -> bool {
86 pub(crate) fn unhide_override_active(&self, chat_id: &str, now: DateTime<Utc>) -> bool {
87 87 self.unhidden_at
88 88 .get(chat_id)
89 89 .is_some_and(|at| now - *at < unhide_override_window())
@@ -83,7 +83,7 @@ impl LocallyHidden {
83 self.unhidden_at.insert(chat_id.to_owned(), now);
83 self.unhidden_at.insert(chat_id.to_owned(), now);
84 }
84 }
85
85
86 fn unhide_override_active(&self, chat_id: &str, now: DateTime<Utc>) -> bool {
86 pub(crate) fn unhide_override_active(&self, chat_id: &str, now: DateTime<Utc>) -> bool {
87 self.unhidden_at
87 self.unhidden_at
88 .get(chat_id)
88 .get(chat_id)
89 .is_some_and(|at| now - *at < unhide_override_window())
89 .is_some_and(|at| now - *at < unhide_override_window())
crates/core/src/sidebar_sync.rs +27 −2
@@ -141,18 +141,43 @@ impl<R: Remote> SyncEngine<R> {
141 141 .filter(|state| state.hidden == Some(true))
142 142 .map(|state| state.id.as_str())
143 143 .collect();
144 let hidden_by_time: Vec<&str> = states
145 .unwrap_or_default()
146 .iter()
147 .filter(|state| self.cached_chat_hidden_by_time(state))
148 .map(|state| state.id.as_str())
149 .collect();
144 150 let now = Utc::now();
145 151 let hidden: Vec<String> = self.with_locally_hidden(|locally| {
146 reported
152 let mut hidden: Vec<String> = reported
147 153 .iter()
148 154 .filter(|chat_id| locally.reported_hidden(chat_id, now))
149 155 .map(|chat_id| (*chat_id).to_owned())
150 .collect()
156 .collect();
157 hidden.extend(
158 hidden_by_time
159 .iter()
160 .filter(|chat_id| !locally.unhide_override_active(chat_id, now))
161 .map(|chat_id| (*chat_id).to_owned()),
162 );
163 hidden
151 164 })?;
152 165 self.store.remove_chats(&hidden)?;
153 166 Ok(())
154 167 }
155 168
169 fn cached_chat_hidden_by_time(&self, state: &ConversationState) -> bool {
170 let Some(hidden_at_ms) = state.hidden_at_ms else {
171 return false;
172 };
173 match self.store.chat(&state.id) {
174 Ok(Some(chat)) => chat
175 .last_message_at
176 .is_none_or(|last| last.timestamp_millis() <= hidden_at_ms),
177 _ => false,
178 }
179 }
180
156 181 async fn refresh_app_channel_horizon(&self) -> i64 {
157 182 match self.remote.app_consumption_horizon().await {
158 183 Ok(horizon) => {
@@ -141,18 +141,43 @@ impl<R: Remote> SyncEngine<R> {
141 .filter(|state| state.hidden == Some(true))
141 .filter(|state| state.hidden == Some(true))
142 .map(|state| state.id.as_str())
142 .map(|state| state.id.as_str())
143 .collect();
143 .collect();
144 let hidden_by_time: Vec<&str> = states
145 .unwrap_or_default()
146 .iter()
147 .filter(|state| self.cached_chat_hidden_by_time(state))
148 .map(|state| state.id.as_str())
149 .collect();
144 let now = Utc::now();
150 let now = Utc::now();
145 let hidden: Vec<String> = self.with_locally_hidden(|locally| {
151 let hidden: Vec<String> = self.with_locally_hidden(|locally| {
146 reported
152 let mut hidden: Vec<String> = reported
147 .iter()
153 .iter()
148 .filter(|chat_id| locally.reported_hidden(chat_id, now))
154 .filter(|chat_id| locally.reported_hidden(chat_id, now))
149 .map(|chat_id| (*chat_id).to_owned())
155 .map(|chat_id| (*chat_id).to_owned())
150 .collect()
156 .collect();
157 hidden.extend(
158 hidden_by_time
159 .iter()
160 .filter(|chat_id| !locally.unhide_override_active(chat_id, now))
161 .map(|chat_id| (*chat_id).to_owned()),
162 );
163 hidden
151 })?;
164 })?;
152 self.store.remove_chats(&hidden)?;
165 self.store.remove_chats(&hidden)?;
153 Ok(())
166 Ok(())
154 }
167 }
155
168
169 fn cached_chat_hidden_by_time(&self, state: &ConversationState) -> bool {
170 let Some(hidden_at_ms) = state.hidden_at_ms else {
171 return false;
172 };
173 match self.store.chat(&state.id) {
174 Ok(Some(chat)) => chat
175 .last_message_at
176 .is_none_or(|last| last.timestamp_millis() <= hidden_at_ms),
177 _ => false,
178 }
179 }
180
156 async fn refresh_app_channel_horizon(&self) -> i64 {
181 async fn refresh_app_channel_horizon(&self) -> i64 {
157 match self.remote.app_consumption_horizon().await {
182 match self.remote.app_consumption_horizon().await {
158 Ok(horizon) => {
183 Ok(horizon) => {