pub async fn find_active_code_for_did(
pool: &SqlitePool,
intended_did: &str,
) -> Result<Option<String>>Expand description
The code of an outstanding (active, unexpired) invite minted FOR the
follower intended_did, if one exists — the app-side idempotency lookup for
POST /bot/claims. Some(code) means “return this existing code, do NOT mint
a second”; None means “no live code for this DID — mint one”.
S3 — this lookup ONLY returns active, UNEXPIRED codes; once a code passes
expires_at (or expire_old_codes flips it to expired) this returns None,
so the next POST /bot/claims MINTS A FRESH code for the DID. There is no
in-place “refresh” of an expired code (the partial-unique index only constrains
active rows, so a fresh mint after expiry is allowed). The bot then re-posts:
its record rkey is deterministic per DID, so the existing skeet is UPDATED in
place with the new claim URL (see the bot’s reconcile_stale_record, S1) rather
than a second skeet being posted. NOTE: a bot-delivered follower whose link
expired UNCLAIMED is only re-minted if the bot re-processes that DID (a re-seen
follow, a waitlisted retry, or a bot-store reset); manual recovery is to clear
the bot’s handled row for that DID so the next cycle re-mints + re-posts.
If several live codes somehow exist (a race), the soonest-expiring is returned.