Skip to content

Add live notifications for platform events via SSE - #140

Merged
Abd-Standard merged 2 commits into
Core-Foundry:mainfrom
Osuochasam:feat/live-notifications
Jul 30, 2026
Merged

Add live notifications for platform events via SSE#140
Abd-Standard merged 2 commits into
Core-Foundry:mainfrom
Osuochasam:feat/live-notifications

Conversation

@Osuochasam

Copy link
Copy Markdown
Contributor

Here is a clear, PR-ready description based on your implementation:

Real-Time Platform Notifications Feature
Summary
Implemented a real-time notification engine using Server-Sent Events (SSE) and an in-memory pub/sub store to notify users instantly of key task and bounty lifecycle events. Includes full state persistence (read/unread management), workflow event triggers, API routes, a navbar UI component, and test coverage.

What Was Built

  1. Core Logic & State Management
    lib/notification-store.ts: Built an in-memory pub/sub notification engine supporting both targeted per-user delivery and system broadcasts. Manages notification history, unread counters, and state transitions (read / read-all).

lib/task-workflow.ts: Extended workflow logic to include approveSubmission, rejectSubmission, and addComment. Injected notification triggers into createTask, submitTaskWork, and all newly added task action handlers.

  1. Supported Event Types
    bounty_created

submission_received

submission_approved

submission_rejected

reward_paid

comment_added

  1. API Endpoints
    GET /api/notifications: Retrieves user notification history and unread count.

GET /api/notifications/stream: Server-Sent Events (SSE) endpoint providing instant event delivery and active connection heartbeats.

POST /api/notifications/[id]/read: Marks a single notification as read.

POST /api/notifications/read-all: Marks all notifications for a user as read.

POST /api/tasks/[taskId]/[approve|reject|comment]: Endpoint routes for task submission actions and commenting.

  1. Frontend Integration
    hooks/useNotifications.ts: Custom SSE client hook managing active stream connections, automatic reconnection handling, and local state updates.

components/NotificationBell.tsx: Interactive UI bell component displaying real-time unread badges and a notification list drawer.

Navbar.tsx: Integrated NotificationBell directly adjacent to the wallet connector, dynamically scoped to the user's connected wallet address.

Test Coverage
Added unit and integration test suites (all passing):

notification-store.test.ts — Validates pub/sub delivery, state mutations, and unread counts.

notifications-api.test.ts — Tests API route response shapes and SSE connection streaming.

task-workflow-notifications.test.ts — Confirms end-to-end event triggering when tasks are created, submitted, approved, rejected, or commented on.

Closes #132

Implements an in-memory notification store with pub/sub, wired into the
task workflow so bounty creation, submission receipt, approval/rejection,
reward payout, and comments each emit a notification. Notifications are
delivered instantly over a Server-Sent Events stream, persisted for later
viewing via a list endpoint, and tracked with a per-user unread count that
updates as notifications are read individually or in bulk. Adds a
NotificationBell UI in the navbar backed by a useNotifications hook.
- useNotificationPreferences: load persisted prefs via a useState lazy
  initializer instead of setState in an effect body, and defer the
  loading-flag flip to a microtask to satisfy react-hooks/set-state-in-effect.
- useNotificationPreferences.test.ts: drop the unused `any`-cast import and
  other unused variables flagged by no-explicit-any / no-unused-vars.
- rate-limit.test.ts: replace the built-in `Function` type with an explicit
  RouteHandler signature to satisfy no-unsafe-function-type.
@Abd-Standard
Abd-Standard merged commit 07eaa83 into Core-Foundry:main Jul 30, 2026
2 of 3 checks passed
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.

Real-Time Notifications for Bounty Activities

2 participants