Skip to content
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

prevent mixup of account timelines #4599

Merged
merged 9 commits into from
Aug 14, 2024
Merged

prevent mixup of account timelines #4599

merged 9 commits into from
Aug 14, 2024

Conversation

connyduck
Copy link
Collaborator

This does 2 things:

  • Removes AccountSwitchInterceptor, the main culprit for the bug. APIs can no longer change their base url after they have been created. As a result they are not Singletons anymore.
  • Additionally, I refactored how MainActivity handles Intents to make it less likely to have multiple instances of it active.

Here is how I could reliably reproduce the bug:

  • Be logged in with account A and B
  • Write a post with account A, cancel it before it sends (go into flight mode for that)
  • Switch to account B
  • Open the "this post failed to send" notification from account A, drafts will open
  • Go back. You are in the MainActivity of account A, everything seems fine.
  • Go back again. You are in the old, now broken MainActivity of account B. It uses the database of account B but the network of account A. Refreshing will show posts from A.

closes #4567
closes #4554
closes #4402
closes #4148
closes #2663
and possibly #4588

@connyduck connyduck requested review from Tak and charlag August 6, 2024 17:56
Comment on lines +71 to +82
@Provides
@Named("defaultPort")
fun providesDefaultPort(): Int {
return 443
}

@Provides
@Named("defaultScheme")
fun providesDefaultScheme(): String {
return "https://"
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda weird, but the only way I found to have tests run on a random port without https.
Better ideas very welcome!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we provide the whole URL depending on the current account?

@connyduck
Copy link
Collaborator Author

Ok, I perf tested this and found no problems. There are a few KBs more memory used, activity start time is the same as before.

I fixed a bug where sometimes the wrong api instance was used because the containing object was a Singleton and the api was not recreated after account switching.

And I refactored a bit to have less code in the NetworkModule and make the testing simpler.

Please have another look.

@connyduck connyduck requested review from charlag and Tak August 12, 2024 19:05
@connyduck connyduck merged commit c7387c7 into develop Aug 14, 2024
3 checks passed
@connyduck connyduck deleted the fix-account-switch branch August 14, 2024 16:58
connyduck added a commit that referenced this pull request Sep 10, 2024
regression from #4599

https://pug.ninja/@motoridersd/113102603349423738

The problem is, `MediaUploader` is no longer a singleton, so the state
is not correctly shared between `ComposeActivity` and
`SendStatusService.` But it can't be a singleton, since `MediaUploadApi`
(injected into `MediaUploader`) needs to be recreated on account change.
Let's share the state in the companion object instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants