Skip to content

feat: add activity discussion/comments system with threaded replies#20

Open
ayesha1145 wants to merge 1 commit intoalphaonelabs:mainfrom
ayesha1145:feat/activity-comments
Open

feat: add activity discussion/comments system with threaded replies#20
ayesha1145 wants to merge 1 commit intoalphaonelabs:mainfrom
ayesha1145:feat/activity-comments

Conversation

@ayesha1145
Copy link
Copy Markdown
Contributor

@ayesha1145 ayesha1145 commented Mar 25, 2026

Adds a threaded discussion/comments system to activity pages, allowing enrolled users and hosts to discuss activities in real time.

Changes:

  • schema.sql: new comments table with parent_id for threaded replies, encrypted body, indexes on activity/user/parent
  • src/worker.py: 3 new API endpoints:
    • GET /api/activities/:id/comments — list all comments (public)
    • POST /api/activities/:id/comments — post a comment or reply (auth required, 2000 char limit)
    • DELETE /api/comments/:id — delete own comment or any comment as host/admin
    • DDL added to /api/init so comments table is created on initialization
  • public/course.html: Discussion section below activity details
    • Threaded replies with visual indentation
    • Reply button per comment (auth only)
    • Login CTA for unauthenticated users
    • Avatar initials, author name, date
    • XSS-safe rendering via escHtml()

Features:

  • Nested replies (one level deep rendered, unlimited depth stored)
  • Comment body encrypted at rest (matches platform security model)
  • Permission-based deletion: own comment, activity host, or admin
  • Input validation: body required, max 2000 characters, parent must exist in same activity

Pull Request Summary: Add Activity Discussion/Comments System with Threaded Replies

Purpose

Adds a threaded discussion/comments system to activity pages, enabling enrolled users and hosts to discuss activities in real time with hierarchical parent-child comment relationships.

Key Changes

Database (schema.sql)

  • Added comments table with support for threaded replies via optional parent_id self-reference and ON DELETE CASCADE
  • Encrypted body storage (at-rest encryption matching platform security model)
  • Added three indexes on activity_id, parent_id, and user_id for performance
  • Includes created_at and updated_at timestamps

Backend API (src/worker.py)

  • Implemented three comment handler functions:
    • api_get_comments: Fetches and decrypts all comments for an activity
    • api_post_comment: Creates new comments with 2000-character limit and optional parent_id for replies; requires authentication
    • api_delete_comment: Allows deletion by comment author, activity host, or admin
  • Updated _DDL schema to include comments table and indexes
  • Updated API documentation to describe the three new endpoints

Frontend (public/course.html)

  • Added "Discussion" UI section with comment form, reply indicator, and login CTA placeholder
  • Implements threaded reply rendering (one level deep visually; unlimited depth storage)
  • Loads comments via GET /api/activities/{actId}/comments and posts via POST with bearer token authentication
  • Reply flow: reply button per comment → focus textarea → post with parent_id
  • XSS-safe rendering via escHtml() and conditional form visibility based on authentication

Input Validation

  • Comment body required, max 2000 characters
  • Parent comment (if provided) must exist and belong to the same activity

⚠️ Critical Implementation Gap

The API routes are not wired into the dispatcher. While all three handler functions are fully implemented and the database schema is complete, no route matchers have been added to the _dispatch function. The _dispatch function will return 404 "API endpoint not found" for all comment requests because the routes checking for /api/activities/:id/comments and /api/comments/:id are missing. The feature is currently non-functional and requires routing to be added to _dispatch before the API endpoints can be accessed.

Loading
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