-
-
Notifications
You must be signed in to change notification settings - Fork 129
fix: sync own device list at login and parse server key-index in usync #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,10 +118,13 @@ impl Client { | |
| .iter() | ||
| .map(|d| wacore::store::traits::DeviceInfo { | ||
| device_id: d.device as u32, | ||
| key_index: existing_key_indices | ||
| .get(&(d.device as u32)) | ||
| .copied() | ||
| .flatten(), | ||
| // Server-returned key_index takes priority over cached | ||
| key_index: d.key_index.or_else(|| { | ||
| existing_key_indices | ||
| .get(&(d.device as u32)) | ||
| .copied() | ||
| .flatten() | ||
| }), | ||
| }) | ||
| .collect(); | ||
|
|
||
|
|
@@ -158,6 +161,35 @@ impl Client { | |
|
|
||
| Ok(all_devices) | ||
| } | ||
|
|
||
| /// Sync own device list from the server, bypassing cache. | ||
| /// Matches WA Web's `syncMyDeviceList()` called during bootstrap. | ||
| pub(crate) async fn sync_own_device_list(&self) -> Result<(), anyhow::Error> { | ||
| let device_snapshot = self.persistence_manager.get_device_snapshot().await; | ||
|
|
||
| let mut jids = Vec::with_capacity(2); | ||
| if let Some(ref pn) = device_snapshot.pn { | ||
| let pn_bare = pn.to_non_ad(); | ||
| self.invalidate_device_cache(&pn_bare.user).await; | ||
| jids.push(pn_bare); | ||
|
Comment on lines
+173
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
| if let Some(ref lid) = device_snapshot.lid { | ||
| let lid_bare = lid.to_non_ad(); | ||
| self.invalidate_device_cache(&lid_bare.user).await; | ||
| jids.push(lid_bare); | ||
| } | ||
|
|
||
| if jids.is_empty() { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let devices = self.get_user_devices(&jids).await?; | ||
|
Comment on lines
+173
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refresh discards the metadata source that
🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It deletes from DB at line 186. This means get_user_devices won't find the old record in DB either → existing_key_indices will be empty → key_index But now that we parse key-index from the server response (our fix), this is actually fine — the server provides key-index for companion devices. The Let me verify by checking the actual server response from the logs: ← no key-index (always kept) Server provides key-index for all companion devices. The existing_key_indices fallback is only for device 0, which doesn't need it. The invalidation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To summarize the reasoning for posterity:
The invalidation-before-fetch sequence is therefore safe given that the server supplies all necessary metadata in the response. I'll withdraw the concern. ✏️ Learnings added
|
||
| log::info!( | ||
| "Synced own device list from server: {} devices", | ||
| devices.len() | ||
| ); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.