Skip to content

fix: Stop multiple notifications being sometimes displayed for one chess notification - #16

Open
Happy0 wants to merge 1 commit into
soapdog:masterfrom
Happy0:chess_notifications_squashed
Open

Happy0 wants to merge 1 commit into
soapdog:masterfrom
Happy0:chess_notifications_squashed

Conversation

@Happy0

@Happy0 Happy0 commented Nov 16, 2026 •

Copy link
Copy Markdown

There's currently a bug with notifications in the poncho-wonky client causing multiple chess notifications to sometimes be displayed for one notifiable event (such as it being the player's move.) The root cause is:

*Poncho Wonky has an internal list of ‘views’ that it has a cache of rendered DOM for. If a view hasn’t been visited in 5 minutes, it’s removed from the cache and the next time the route is visited again it’s re-rendered and attached to the DOM.

  • ssb-chess-mithril, at startup, initiates a pull stream where the ‘source’ is events that the user might want a notification about and the ‘sink’ is displaying a notification. There’s nothing that aborts this stream when the chess view is removed from the cache (even though the chess component’s ‘destroy’ function is called to unmount the chess view and clear up some of its internal state.)
  • So if you switch between the chess view and other poncho views you’ll get multiple notification streams (a new one each time the view is remounted freshly after it’s been removed from the cache.)
  • This means multiple notifications will be displayed

This PR solves this problem by:

  • Exposing notifications as a separate stream from ssb-chess-mithril
  • Creating a depject 'gives' exposing this stream alongside the chess component 'render' dependency and loading it at Patchwork startup so that notifications are displayed even if the chess component isn't mounted. This only happens once so multiple notifications will no longer be displayed.

Other changes:

  • I cleaned up the initialisation code for the chess page rendering so that we don't have to loop (with a back-off) until mutant has put the chess component on the DOM
  • Patchwork already seemed to have something in place for passing extra arguments to views through its routes/view system (via an 'anchor' parameter.) I've re-used that for setting the target for the game that should be opened in the chess view when the user clicks a notification.

Request for Feedback

  • There's currently a scuttlebutt-server / scuttlebot server plugin in lib/plugins/notifier.js that communicates over IPC from the server process to the electron rendering process to tell it to display a notification if the scuttlebutt feed message newly arriving should result in a notification. I didn't make my changes in this plugin because internally ssb-chess-mithril decides whether to notify based on whether the user is currently looking at the chess app (which isn't possible on the server side because there's no DOM document.)
  • I thought it would be acceptable to have two paths for notifications - the core patchwork path (for replies, etc) via the scuttlebutt-server plugin and another path (which ultimately sends the same IPC message with the same notification schema on the message bus) for views (like chess) that are not core patchwork 'social media' type functionality and are 'plugged in' via patchwork's dependency injection system and could conceivably be external plugins one day.

Let me know if you'd prefer me to try and come up with an alternative approach 😅

… when using ssb-chess-mithril that follows this pattern:

*Poncho Wonky has an internal list of ‘views’ that it has a cache of rendered DOM for. If a view hasn’t been visited in 5 minutes, it’s removed from the cache and the next time the route is visited again it’s re-rendered and attached to the DOM.
* ssb-chess-mithril, at startup, initiates a pull stream where the ‘source’ is events that the user might want a notification about and the ‘sink’ is displaying a notification. There’s nothing that aborts this stream when the chess view is removed from the cache (even though the chess component’s ‘destroy’ function is called to unmount the chess view and clear up some of its internal state.)
* So if you switch between the chess view and other poncho views you’ll get multiple notification streams (a new one each time the view is remounted freshly after it’s been removed from the cache.)
* This means multiple notifications will be displayed

This PR solves this problem by:
* Exposing notifications as a separate stream from ssb-chess-mithril
* Creating a depject 'gives' exposing this stream alongside the chess
  component 'render' dependency and loading it at Patchwork startup so
  that notifications are displayed even if the chess component isn't
  mounted. This only happens once so multiple notifications will no
  longer be displayed.

Other changes:
* I cleaned up the initialisation code for the chess page rendering so
  that we don't have to loop (with a back-off) until
  mutant has put the chess component on the DOM
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