Activity badges: count only what needs you; clear per account - #113
Merged
BitcoinErrorLog merged 7 commits intoSep 24, 2026
Merged
Conversation
…d per account Activity rows badge only while their order or offer still waits on the signed-in account; informational rows never count, and one subject counts once on the marketplace icon. Opening Activity or Orders saves the checkpoint in the account's private homeserver document so every browser clears.
…wsers Each save adds an immutable entry named by its checkpoint under a per-side private directory, and the checkpoint is the largest name. Saves are debounced, skipped when the homeserver already holds a newer checkpoint, and prune only entries below the one just written.
The Orders page saves when the list becomes ready, when the account changes, and when the tab becomes visible again. A refreshed order list no longer triggers a homeserver write.
…/activity-badge-actionable-58ad
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes both badge problems Pav reported on v0.6.25 in pubky-marketplace#54:
No marketplace-service change was needed.
What counts as needing you
The set comes from the service's order state model (
next_actor, the same value the order cards show as "Waiting on you") and from the offer state model.Orders tab badge. One per order, when both of these hold:
next_actorfor the order is this account (as buyer or seller), andBy state, that is:
pending_paymentholdExpiresAthas already passed does not count.paid,processing,cancel_requested,return_requested,return_approved,return_receivedshipped,ready_for_pickupdelivered,completed,cancelled,refunded_external,closedActivity tab badge. One per subject: an order, an offer, or a message row. It counts only rows of these action types, only while their subject still needs this account:
return_updated,pickup_ready,payment_refund_required,bitcoin_manual_reviewoffer_received,offer_counteredpendingorcountered, has not expired, and this account is the party who did not make the latest amount.offer_acceptedactive, so checkout is still open.message_receivedorder_created("Checkout started"),order_cancelled,order_cancelled_terms_change,payment_confirmed,payment_method_bound,fiat_payment_reported,order_shipped,order_delivered,order_delivery_assumed,order_completed,refund_recorded,review_received,outbid,auction_won,auction_ended,offer_rejected,pickup_details_updated,pickup_details_cleared,bitcoin_prepare_voided,drop_sold_out.Marketplace icon (header and footer). This is the union of the Activity and Orders subjects. An order with a return row on Activity and a badge on Orders counts once.
Clearing works as before. Opening Activity clears Activity rows created before that moment, and opening Orders clears orders updated before that moment. A new event on something that still needs you raises the badge again. The sandbox keeps using each row's real
readAtfor Activity.Per-account "seen" checkpoint
The durable service has no user-settings, last-seen, or read-state endpoint. Its
notifications.read_atcolumn exists, but no command writes it, and/v1/notification-preferencesis sandbox-only. So the checkpoint lives in a small private homeserver file, following the private watchlist pattern:pubky://<account>/priv/pubky.app/marketplace/v1/attention_seen.json={ "version": 1, "activitySeenAt": <ms>, "ordersSeenAt": <ms> }/priv/pubky.app/. Otherwise, such as a legacy public-only grant or the sandbox, the badge keeps its per-browser behaviour and makes no network calls./priv/, so the timestamps are not public.Changes
src/libs/commerce/marketplace-attention.ts: adds the actionable set. That coversorderNeedsCurrentUser(with the lapsed-hold rule),offerNeedsCurrentUser,activityNeedingAttentionKeys, andordersNeedingAttentionKeys. It removescountOrdersNeedingAttentionandmarkOrdersAttentionSeen, which no longer have callers.src/hooks/useMarketplaceActivityAttentionKeysandsrc/hooks/useMarketplaceOrdersAttentionKeysreturn subject keys.useMarketplaceActivityUnreadanduseMarketplaceOrdersAttentionwrap them and return counts, so existing mocks and imports keep working.useMarketplaceNavAttentionreturns the size of the union.src/core/application/commerce/attention-seen.tshandles the private checkpoint file. It is wired throughCommerceApplicationandCommerceController(markActivityRead,markOrdersAttentionSeen,syncAttentionSeen).CommerceRecordNormalizer.attentionSeenUribuilds the path.useMarkMarketplaceOrdersSeenhook.MarketplaceOrdersnow clears through the controller instead of writing local storage directly. A stubbed or missing controller counts as a failed write, not a render error.activity-badge-actionable.fixed.md.Tests (each fails when its change is reverted)
src/libs/commerce/marketplace-attention.test.ts: checks that "Checkout started", "Order cancelled", "Payment confirmed", and "Order completed" rows never count. Return and offer rows count only while their order or offer still waits on the account, and several rows about one subject count once. It also covers the lapsed-hold rule, offer turn-taking and expiry, and the accepted-offer award.src/hooks/useMarketplaceActivityUnread/useMarketplaceActivityUnread.test.ts: an answered offer stops badging, order rows follow order state, and the hook pulls the account checkpoint.src/hooks/useMarketplaceNavAttention/useMarketplaceNavAttention.test.tsx: an order that badges both tabs counts once on the icon. The existing identity-switch test is updated for the new reads.src/core/application/commerce/attention-seen.test.tscovers:/privwrite, for another account, or in the sandbox.Six reverts were each run against these tests, and each one made at least one test fail:
order_createdandorder_cancelledadded back to the action set;Verification
npx vitest related --run --project unit <changed files>on the rebased head: 177 files, 2115 tests passed.npm run typecheck, andeslintandprettier --checkon the changed files, are clean.mcr.microsoft.com/playwright:v1.60.0-noble(scripts/vrt-linux.sh, everysrc/test/vrt/marketplace/*.vrt.test.tsx, Chromium and Firefox). 802 of 804 passed. The two failures were one Pickup scene in both browsers. Its mocked controller had nomarkOrdersAttentionSeen, and the new orders hook threw during render. The hook now treats a stubbed controller as a failed write, the same as the other badge hooks, anduseMarkMarketplaceOrdersSeen.test.tspins that behaviour; the test fails on the old hook. A re-run of the eight marketplace VRT files that render Orders, Activity, or the nav badges passed: 16 files, 168 tests.Known limits
/priv/pubky.app/:rwkeep per-browser clearing until the user signs in again with the wider grant.