-
Notifications
You must be signed in to change notification settings - Fork 336
fix(sdk): Mark tracked users as dirty when the SS connection is reset. #3965
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
Merged
Hywan
merged 5 commits into
matrix-org:main
from
Hywan:fix-sdk-sliding-sync-no-since-must-reset-devices
Sep 11, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8b2014
feat(crypto): Implement OldMachine::mark_all_tracked_users_as_dirty.
Hywan 781d3d0
fix(sdk): Mark tracked users as dirty when the SS connection is reset.
Hywan ef18c13
doc(crypto): Improve documentation.
Hywan df8d8ac
chore(sdk): Add an `info` log in sliding sync.
Hywan 943c46f
Merge branch 'main' into fix-sdk-sliding-sync-no-since-must-reset-dev…
Hywan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::{collections::BTreeMap, iter, sync::Arc, time::Duration}; | ||
use std::{collections::BTreeMap, iter, ops::Not, sync::Arc, time::Duration}; | ||
|
||
use assert_matches2::assert_matches; | ||
use futures_util::{pin_mut, FutureExt, StreamExt}; | ||
|
@@ -1528,6 +1528,43 @@ async fn test_unsigned_decryption() { | |
assert_matches!(thread_encryption_result, UnsignedDecryptionResult::Decrypted(_)); | ||
} | ||
|
||
#[async_test] | ||
async fn test_mark_all_tracked_users_as_dirty() { | ||
let store = MemoryStore::new(); | ||
let account = vodozemac::olm::Account::new(); | ||
|
||
// Put some tracked users | ||
let damir = user_id!("@damir:localhost"); | ||
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. ❤️ 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. ❤️ |
||
let ben = user_id!("@ben:localhost"); | ||
let ivan = user_id!("@ivan:localhost"); | ||
|
||
// Mark them as not dirty. | ||
store.save_tracked_users(&[(damir, false), (ben, false), (ivan, false)]).await.unwrap(); | ||
|
||
// Let's imagine the migration has been done: this is useful so that tracked | ||
// users are not marked as dirty when creating the `OlmMachine`. | ||
store | ||
.set_custom_value(OlmMachine::key_for_has_migrated_verification_latch(), vec![0]) | ||
.await | ||
.unwrap(); | ||
|
||
let alice = | ||
OlmMachine::with_store(user_id(), alice_device_id(), store, Some(account)).await.unwrap(); | ||
|
||
// All users are marked as not dirty. | ||
alice.store().load_tracked_users().await.unwrap().iter().for_each(|tracked_user| { | ||
assert!(tracked_user.dirty.not()); | ||
}); | ||
|
||
// Now, mark all tracked users as dirty. | ||
alice.mark_all_tracked_users_as_dirty().await.unwrap(); | ||
|
||
// All users are now marked as dirty. | ||
alice.store().load_tracked_users().await.unwrap().iter().for_each(|tracked_user| { | ||
assert!(tracked_user.dirty); | ||
}); | ||
} | ||
|
||
#[async_test] | ||
async fn test_verified_latch_migration() { | ||
let store = MemoryStore::new(); | ||
|
@@ -1544,20 +1581,22 @@ async fn test_verified_latch_migration() { | |
let alice = | ||
OlmMachine::with_store(user_id(), alice_device_id(), store, Some(account)).await.unwrap(); | ||
|
||
let alice_store = alice.store(); | ||
|
||
// A migration should have occurred and all users should be marked as dirty | ||
alice.store().load_tracked_users().await.unwrap().iter().for_each(|tu| { | ||
alice_store.load_tracked_users().await.unwrap().iter().for_each(|tu| { | ||
assert!(tu.dirty); | ||
}); | ||
|
||
// Ensure it does so only once | ||
alice.store().save_tracked_users(&to_track_not_dirty).await.unwrap(); | ||
alice_store.save_tracked_users(&to_track_not_dirty).await.unwrap(); | ||
|
||
OlmMachine::migration_post_verified_latch_support(alice.store().crypto_store().as_ref()) | ||
OlmMachine::migration_post_verified_latch_support(alice_store, alice.identity_manager()) | ||
.await | ||
.unwrap(); | ||
|
||
// Migration already done, so user should not be marked as dirty | ||
alice.store().load_tracked_users().await.unwrap().iter().for_each(|tu| { | ||
alice_store.load_tracked_users().await.unwrap().iter().for_each(|tu| { | ||
assert!(!tu.dirty); | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.