feat(reactions): add emoji reactions for comments and issue descriptions

Add Slack-style emoji reactions to comments and issue descriptions with
full-stack support: database tables, REST API endpoints, real-time
WebSocket sync, optimistic UI updates, and inbox notifications.

- New `comment_reaction` and `issue_reaction` tables with migrations
- POST/DELETE endpoints for adding/removing reactions on both comments
  and issue descriptions
- Real-time WS events (reaction:added/removed, issue_reaction:added/removed)
- Shared ReactionBar component with quick emoji picker and full emoji-mart
  picker (lazy-loaded)
- Optimistic add/remove with rollback on failure
- Inbox notifications for comment author and issue creator when reacted to
- Reactions included in timeline, comment list, and issue detail responses
This commit is contained in:
Jiayuan 2026-03-30 22:37:59 +08:00
parent 72e3ccfe33
commit 7c1aabbe3a
32 changed files with 1221 additions and 49 deletions

View file

@ -0,0 +1,104 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: issue_reaction.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const addIssueReaction = `-- name: AddIssueReaction :one
INSERT INTO issue_reaction (issue_id, workspace_id, actor_type, actor_id, emoji)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (issue_id, actor_type, actor_id, emoji) DO UPDATE SET created_at = issue_reaction.created_at
RETURNING id, issue_id, workspace_id, actor_type, actor_id, emoji, created_at
`
type AddIssueReactionParams struct {
IssueID pgtype.UUID `json:"issue_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
}
func (q *Queries) AddIssueReaction(ctx context.Context, arg AddIssueReactionParams) (IssueReaction, error) {
row := q.db.QueryRow(ctx, addIssueReaction,
arg.IssueID,
arg.WorkspaceID,
arg.ActorType,
arg.ActorID,
arg.Emoji,
)
var i IssueReaction
err := row.Scan(
&i.ID,
&i.IssueID,
&i.WorkspaceID,
&i.ActorType,
&i.ActorID,
&i.Emoji,
&i.CreatedAt,
)
return i, err
}
const listIssueReactions = `-- name: ListIssueReactions :many
SELECT id, issue_id, workspace_id, actor_type, actor_id, emoji, created_at FROM issue_reaction
WHERE issue_id = $1
ORDER BY created_at ASC
`
func (q *Queries) ListIssueReactions(ctx context.Context, issueID pgtype.UUID) ([]IssueReaction, error) {
rows, err := q.db.Query(ctx, listIssueReactions, issueID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []IssueReaction{}
for rows.Next() {
var i IssueReaction
if err := rows.Scan(
&i.ID,
&i.IssueID,
&i.WorkspaceID,
&i.ActorType,
&i.ActorID,
&i.Emoji,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const removeIssueReaction = `-- name: RemoveIssueReaction :exec
DELETE FROM issue_reaction
WHERE issue_id = $1 AND actor_type = $2 AND actor_id = $3 AND emoji = $4
`
type RemoveIssueReactionParams struct {
IssueID pgtype.UUID `json:"issue_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
}
func (q *Queries) RemoveIssueReaction(ctx context.Context, arg RemoveIssueReactionParams) error {
_, err := q.db.Exec(ctx, removeIssueReaction,
arg.IssueID,
arg.ActorType,
arg.ActorID,
arg.Emoji,
)
return err
}

View file

@ -91,6 +91,16 @@ type Comment struct {
WorkspaceID pgtype.UUID `json:"workspace_id"`
}
type CommentReaction struct {
ID pgtype.UUID `json:"id"`
CommentID pgtype.UUID `json:"comment_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type DaemonConnection struct {
ID pgtype.UUID `json:"id"`
AgentID pgtype.UUID `json:"agent_id"`
@ -173,6 +183,16 @@ type IssueLabel struct {
Color string `json:"color"`
}
type IssueReaction struct {
ID pgtype.UUID `json:"id"`
IssueID pgtype.UUID `json:"issue_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type IssueSubscriber struct {
IssueID pgtype.UUID `json:"issue_id"`
UserType string `json:"user_type"`

View file

@ -0,0 +1,104 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: reaction.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const addReaction = `-- name: AddReaction :one
INSERT INTO comment_reaction (comment_id, workspace_id, actor_type, actor_id, emoji)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (comment_id, actor_type, actor_id, emoji) DO UPDATE SET created_at = comment_reaction.created_at
RETURNING id, comment_id, workspace_id, actor_type, actor_id, emoji, created_at
`
type AddReactionParams struct {
CommentID pgtype.UUID `json:"comment_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
}
func (q *Queries) AddReaction(ctx context.Context, arg AddReactionParams) (CommentReaction, error) {
row := q.db.QueryRow(ctx, addReaction,
arg.CommentID,
arg.WorkspaceID,
arg.ActorType,
arg.ActorID,
arg.Emoji,
)
var i CommentReaction
err := row.Scan(
&i.ID,
&i.CommentID,
&i.WorkspaceID,
&i.ActorType,
&i.ActorID,
&i.Emoji,
&i.CreatedAt,
)
return i, err
}
const listReactionsByCommentIDs = `-- name: ListReactionsByCommentIDs :many
SELECT id, comment_id, workspace_id, actor_type, actor_id, emoji, created_at FROM comment_reaction
WHERE comment_id = ANY($1::uuid[])
ORDER BY created_at ASC
`
func (q *Queries) ListReactionsByCommentIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]CommentReaction, error) {
rows, err := q.db.Query(ctx, listReactionsByCommentIDs, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
items := []CommentReaction{}
for rows.Next() {
var i CommentReaction
if err := rows.Scan(
&i.ID,
&i.CommentID,
&i.WorkspaceID,
&i.ActorType,
&i.ActorID,
&i.Emoji,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const removeReaction = `-- name: RemoveReaction :exec
DELETE FROM comment_reaction
WHERE comment_id = $1 AND actor_type = $2 AND actor_id = $3 AND emoji = $4
`
type RemoveReactionParams struct {
CommentID pgtype.UUID `json:"comment_id"`
ActorType string `json:"actor_type"`
ActorID pgtype.UUID `json:"actor_id"`
Emoji string `json:"emoji"`
}
func (q *Queries) RemoveReaction(ctx context.Context, arg RemoveReactionParams) error {
_, err := q.db.Exec(ctx, removeReaction,
arg.CommentID,
arg.ActorType,
arg.ActorID,
arg.Emoji,
)
return err
}