mirror of
https://github.com/yattee/yattee.git
synced 2026-10-23 21:22:53 +00:00
Make synced accounts usable the moment they arrive
A fresh device never adopted the synced context. The local value is a default stamped when the manager is built, so it is always newer than a choice made on another device, and ordering against it discarded that choice. With no local decision to protect, the first synced context is simply adopted. An account arriving mid-session sat at "sign in required" until the app was relaunched: nothing recomputed its status once the metadata — or its instance — turned up, even when iCloud Keychain had already delivered the credential. Both arrivals now recompute statuses and re-run the legacy mirror, which was similarly stuck whenever the instance had not arrived yet. Signing in again keeps the same account and the same context, so nothing downstream saw a change — but the credential may now belong to somebody else, and their subscriptions and feed stayed on screen. The provider and the account's caches are discarded on every credential replacement. The deletion repair also cancels a context upload the deleted choice had queued; sending it would have published the fallback under that choice's timestamp, which not stamping it "now" exists to prevent. Piped subscribe/unsubscribe and Invidious unsubscribe now report their outcome like every other authenticated call, so a credential rejected by one of them stops claiming to be signed in. Removing the last account updates the source screen, which kept offering authenticated imports that could only fail.
This commit is contained in:
@@ -186,6 +186,24 @@ struct AccountsManagerTests {
|
||||
#expect(manager.context(forLegacyInstanceID: instanceID) == .account(second.id))
|
||||
}
|
||||
|
||||
@Test("A fresh device adopts the synced context")
|
||||
func firstSyncedContextIsAdopted() {
|
||||
let manager = makeManager()
|
||||
let accountID = UUID()
|
||||
|
||||
// The local value is a default stamped when the manager was built, so
|
||||
// it is always "newer" than a choice made on another device yesterday.
|
||||
// Ordering against it would leave a fresh device on local forever.
|
||||
let synced = StoredDataContext(
|
||||
context: .account(accountID),
|
||||
changedAt: Date().addingTimeInterval(-86_400)
|
||||
)
|
||||
|
||||
#expect(!manager.applySyncedContext(synced))
|
||||
#expect(manager.currentContext == .account(accountID))
|
||||
#expect(!manager.pendingContextUpload)
|
||||
}
|
||||
|
||||
@Test("Correcting away from a deleted account never outranks a real choice")
|
||||
func deletionCorrectionIsNotAChoice() {
|
||||
let manager = makeManager()
|
||||
@@ -202,6 +220,7 @@ struct AccountsManagerTests {
|
||||
// device hearing about it. Timestamping the fallback "now" would sink
|
||||
// that choice — and publishing it would push the fallback over it.
|
||||
#expect(manager.storedContext.changedAt == chosenAt)
|
||||
// Including any upload the deleted choice had queued.
|
||||
#expect(!manager.pendingContextUpload)
|
||||
|
||||
let elsewhere = StoredDataContext(
|
||||
|
||||
Reference in New Issue
Block a user