Skip to content

Feat/390 activity feed#548

Open
Sage-senpai wants to merge 5 commits intoStreamFi-x:devfrom
Sage-senpai:feat/390-activity-feed
Open

Feat/390 activity feed#548
Sage-senpai wants to merge 5 commits intoStreamFi-x:devfrom
Sage-senpai:feat/390-activity-feed

Conversation

@Sage-senpai
Copy link
Copy Markdown

Description

Closes #390

Changes proposed

What were you told to do?

Implement a cursor-paginated user activity feed API with two endpoints:

  • GET /api/routes-f/activity — paginated feed of user activity events
  • GET /api/routes-f/activity/daily — aggregated daily summary

What did you do?

Schema & migration

  • Created route_f_activity_events table with columns: id, user_id, type, actor_id, metadata (JSONB), created_at
  • Added composite index on (user_id, created_at DESC) for efficient feed queries
  • Added both app/api/routes-f/activity/_lib/db.ts (lazy DDL) and db/migrations/20260330_add_activity_events.sql

Types (types/activity.ts)

  • ActivityEventType — union of 8 event types (tip_received, tip_sent, new_follower, stream_started, stream_ended, gift_received, gift_sent, recording_ready)
  • ActivityTypeFilter — query param filter values (all, tips, follows, streams, gifts)
  • FILTER_TO_TYPES — maps filter values to DB event types
  • Response interfaces: ActivityFeedResponse, DailySummaryResponse

GET /api/routes-f/activity

  • Requires authenticated session (401 if missing)
  • Query params: limit (1-100, default 20), cursor (ISO timestamp), type (all|tips|follows|streams|gifts)
  • Cursor pagination using created_at < $cursor with fetch limit + 1 trick to detect next page
  • JOINs users table to include actor username/avatar
  • Empty state returns { events: [], next_cursor: null } (not 404)

GET /api/routes-f/activity/daily?date=YYYY-MM-DD

  • Requires authenticated session and valid date param (400 if missing/invalid)
  • Single aggregation query using PostgreSQL FILTER (WHERE ...) clauses
  • Returns: tips_received, tips_received_xlm, followers_gained, stream_duration_s, peak_viewers
  • All fields default to 0/"0" — never null

Upstream side-effect inserts

  • app/api/users/follow/route.ts — inserts new_follower event after successful follow
  • app/api/streams/start/route.ts — inserts stream_started on POST, stream_ended on DELETE (with duration/peak_viewers from session)
  • app/api/routes-f/gifts/route.ts — inserts both gift_received and gift_sent events
  • All inserts wrapped in try/catch to never break the primary operation

Note: Tip events (tip_received/tip_sent) are not yet instrumented — there is no dedicated tip transaction route to hook into (only tips/refresh-total which is a read-only endpoint).

Check List

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the main branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

N/A — API-only changes. Example responses:

GET /api/routes-f/activity?type=tips&limit=2

{
  "events": [
    {
      "id": "uuid",
      "type": "tip_received",
      "actor": { "username": "alice", "avatar": "/img/alice.png" },
      "metadata": { "amount": "50", "currency": "XLM" },
      "created_at": "2026-03-30T12:00:00.000Z"
    }
  ],
  "next_cursor": null
}

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

@Sage-senpai is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Sage-senpai Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

feat(routes-f): user activity feed api (tips, follows, streams)

1 participant