Skip to content

fix(shared-decks): show login snackbar when AnkiWeb rate-limits deck downloads - #22153

Open
sanjaysargam wants to merge 4 commits into
ankidroid:mainfrom
sanjaysargam:fix/19876-shared-decks-429-login-prompt
Open

sanjaysargam wants to merge 4 commits into
ankidroid:mainfrom
sanjaysargam:fix/19876-shared-decks-429-login-prompt

Conversation

@sanjaysargam

Copy link
Copy Markdown
Member

Note

Assisted-by: Opus 5.5

Purpose / Description

Downloading a second shared deck while logged out fails with a generic "Something went wrong" toast. AnkiWeb actually replies HTTP 429, asking the user to log in

Fixes

Approach

Android's Downloads puts the raw HTTP status code in COLUMN_REASON for 4xx/5xx failures, so that download-failure path now reads the reason and detects 429

How Has This Been Tested?

Regression Test

Physical Device

WhatsApp.Video.2026-09-28.at.11.10.08.PM.mp4

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@sanjaysargam
sanjaysargam marked this pull request as ready for review September 28, 2026 17:41

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this is buggy if it occurs while the activity is backgrounded

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Sep 28, 2026
@sanjaysargam
sanjaysargam force-pushed the fix/19876-shared-decks-429-login-prompt branch from d9257d6 to 92f73db Compare September 29, 2026 10:23
@sanjaysargam sanjaysargam added Needs Review and removed Has Conflicts Needs Author Reply Waiting for a reply from the original author labels Sep 29, 2026
@sanjaysargam

Copy link
Copy Markdown
Member Author

I believe this is buggy if it occurs while the activity is backgrounded

@david-allison Fixed this by moving the UI out of the receiver, it now only records state using ViewModel

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cheers! Logic seems good, but it feels like a lot of code churn in a single commit for this.

*
* The redirect is not performed if [redirectTimes] is 3 or more
*/
private fun redirectUserToSignUpOrLogin() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Look into reusing this

Comment on lines +551 to +553
isSuccessful: Boolean,
isInvalidDeckFile: Boolean = false,
isRateLimited: Boolean = false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This has become too complex, add a commit to convert it to an enum

Timber.i("Download failed, offer a retry")
if (isVisible) {
context?.let { showThemedToast(it, CommonString.something_wrong, false) }
// A 429 from AnkiWeb is only actionable for a logged-out user; a logged-in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Find one place for these explanations to live, the comments are repeated and it feels excessive

@sanjaysargam
sanjaysargam force-pushed the fix/19876-shared-decks-429-login-prompt branch from 92f73db to 22db50d Compare September 30, 2026 02:48
@mikehardy
mikehardy force-pushed the fix/19876-shared-decks-429-login-prompt branch from 22db50d to 849407b Compare September 30, 2026 22:32
@david-allison
david-allison dismissed their stale review September 30, 2026 22:37

Didn't get to re-review this one today, sorry!

Please ping me - I'll aim to have it done within 24 hours

@mikehardy mikehardy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for splitting the commits, moving the snackbar off the receiver, and covering backgrounded 429. The 429 detection looks right.

Request changes

  1. Login path incomplete — WebView 429 calls redirectUserToSignUpOrLogin() (snackbar + login URL). Download 429 only shows the snackbar and popBackStack(). showLoginRequiredSnackbar() adds Sign up only when AnkiDroid isLoggedIn() is false, so a user with an AnkiDroid account and no AnkiWeb WebView session gets a message with nothing to tap. Please reuse the existing redirect after leaving the download screen (or add a Login action that loads shared_decks_login_url), and add a regression for AnkiDroid-logged-in + WebView-logged-out.

  2. AI_POLICY — PR NOTE has Assisted-by: Opus 5.5, but none of the four commits have an Assisted-by: trailer. Please add trailers (and preferably note what Opus wrote).

Local on rebased tip 849407b6 (4 commits): lint / unit / package / emulator (API36_GAPI_PS16K) all green.

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show relevant toast message as "Please login to download more decks"

3 participants