Skip to content

Fix feed contamination, notification persistence, relay reconnection, and wallet reliability#18

Merged
barrydeen merged 1 commit intomainfrom
fix/feed-reliability-and-wallet
Feb 20, 2026
Merged

Fix feed contamination, notification persistence, relay reconnection, and wallet reliability#18
barrydeen merged 1 commit intomainfrom
fix/feed-reliability-and-wallet

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

  • Fix feed contamination: Events from user profile, thread, and bookmark subscriptions were being added to the follow feed via addEvent() in the catch-all else block of processRelayEvent. This caused posts from non-followed users to appear in the feed after viewing their profiles, and inflated the "new posts" counter (the count included every post loaded on profile screens). Now only feed-related subscriptions (feed, loadmore, feed-backfill) call addEvent() — everything else uses cacheEvent() which stores events for lookups without inserting into the feed list.

  • Fix UserProfileViewModel feed leakage: The profile screen was also calling eventRepo.addEvent() for kind 0/1/6 events, which inserted viewed users' posts into the global feed. Changed to cacheEvent() since the profile screen maintains its own local lists. Also chunked follow-profile requests into batches of 50 with proper subscription cleanup.

  • Persist notification read state: Unread notification badge now survives app restarts by persisting the last-read timestamp in SharedPreferences (per account). Notifications are only marked unread if they're newer than the stored timestamp.

  • Fix relay reconnection: WebSocket onClosed with non-normal close codes (anything other than 1000) now triggers reconnection. The socket reference is also nulled on close to prevent sends to dead connections.

  • Improve wallet connection reliability: Rewrote the NWC connection flow — initial connect uses a proper coroutine timeout, then a persistent monitor handles disconnect/reconnect state transitions. The NWC relay now receives a coroutine scope for proper lifecycle management. Removed initNwc() since wallet connects lazily when the tab is opened or on-demand when sending a zap.

Test plan

  • Pull to refresh the feed — verify the "new posts" counter starts at 0 and only counts genuinely new streaming events
  • Visit a non-followed user's profile, navigate back to feed — verify their posts don't appear in the follow feed
  • View notifications, restart app — verify unread badge reflects actual unread state
  • Disconnect from network briefly, reconnect — verify relays reconnect and feed resumes
  • Connect NWC wallet, navigate away and back — verify wallet stays connected and shows balance
  • Send a zap without visiting the wallet tab first — verify NWC connects on demand

… and wallet reliability

Feed:
- Gate eventRepo.addEvent() on feed-related subscription IDs only (feed,
  loadmore, feed-backfill) in processRelayEvent; other subs use cacheEvent()
  so user profile, thread, and bookmark events don't leak into the follow feed
- Fix inflated new-note count caused by profile/thread events incrementing
  the counter via binaryInsert
- UserProfileViewModel now uses cacheEvent() for kind 0/1/6 events instead
  of addEvent(), preventing viewed profiles from contaminating the global feed
- Chunk follow-profile requests into batches of 50 with proper sub cleanup
- Remove initNwc() — wallet connects lazily on tab open or on-demand via zap

Relay:
- Reconnect on non-normal WebSocket close (code != 1000) and null out the
  socket reference on close to prevent sends to dead connections

Notifications:
- Persist last-read timestamp in SharedPreferences per account so unread
  badge state survives app restarts
- Only mark notifications as unread if they're newer than the last-read time

Wallet:
- Rewrite connection flow: initial connect uses a proper timeout with
  first{}, then a persistent monitor handles disconnect/reconnect
- Pass coroutine scope to NWC relay for proper lifecycle management
- Track connection string in state for UI consistency
@barrydeen barrydeen merged commit 128b8a0 into main Feb 20, 2026
@barrydeen barrydeen deleted the fix/feed-reliability-and-wallet branch March 4, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant