Files
multica/server/internal/handler/issue_reaction.go
c375f83c2e MUL-7418: add issue event and time wakeups (#8467)
* feat: add issue event and time wakeups (MUL-7418)

Co-authored-by: multica-agent <[email protected]>

* feat(wakeups): capture issue collaboration event lifecycle

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): preserve reply source when reopening threads

Co-authored-by: multica-agent <[email protected]>

* feat(wakeups): summarize sidebar and issue activity cues

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): restore disabled configurations with a two-way toggle

Co-authored-by: multica-agent <[email protected]>

* feat(wakeups): manage workspace wakeups in Autopilot

Co-authored-by: multica-agent <[email protected]>

* chore(wakeups): reserve migrations after current main

Co-authored-by: multica-agent <[email protected]>

* test(wakeups): align inventory fixtures with shared contracts

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): distinguish trigger conditions and execution results

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): suppress registration feedback and drain bounded evidence

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): align sidebar actions with titles

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): bound database work and unify shared issue visibility

Co-authored-by: multica-agent <[email protected]>

* feat(wakeups): filter mutation events by member or agent actor

Co-authored-by: multica-agent <[email protected]>

* refactor(wakeups): merge structured evidence and narrow receipt locks

Co-authored-by: multica-agent <[email protected]>

* feat(wakeups): let people edit wakeup instructions

Co-authored-by: multica-agent <[email protected]>

* fix(wakeups): align inventory controls and compact prompt editing

Co-authored-by: multica-agent <[email protected]>

* fix(mobile): handle deferred agent run status

Co-authored-by: multica-agent <[email protected]>

---------

Co-authored-by: Lambda <[email protected]>
Co-authored-by: multica-agent <[email protected]>
2026-09-21 04:17:12 +08:00

161 lines
4.4 KiB
Go

package handler
import (
"encoding/json"
"log/slog"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/multica-ai/multica/server/internal/logger"
db "github.com/multica-ai/multica/server/pkg/db/generated"
"github.com/multica-ai/multica/server/pkg/protocol"
)
type IssueReactionResponse struct {
ID string `json:"id"`
IssueID string `json:"issue_id"`
ActorType string `json:"actor_type"`
ActorID string `json:"actor_id"`
Emoji string `json:"emoji"`
CreatedAt string `json:"created_at"`
IssueRevision *int64 `json:"issue_revision,omitempty"`
}
func issueReactionToResponse(r db.IssueReaction) IssueReactionResponse {
return IssueReactionResponse{
ID: uuidToString(r.ID),
IssueID: uuidToString(r.IssueID),
ActorType: r.ActorType,
ActorID: uuidToString(r.ActorID),
Emoji: r.Emoji,
CreatedAt: timestampToString(r.CreatedAt),
}
}
func addedIssueReactionToResponse(r db.AddIssueReactionRow) IssueReactionResponse {
response := IssueReactionResponse{
ID: uuidToString(r.ID),
IssueID: uuidToString(r.IssueID),
ActorType: r.ActorType,
ActorID: uuidToString(r.ActorID),
Emoji: r.Emoji,
CreatedAt: timestampToString(r.CreatedAt),
}
if r.IssueRevision > 0 {
response.IssueRevision = &r.IssueRevision
}
return response
}
func (h *Handler) AddIssueReaction(w http.ResponseWriter, r *http.Request) {
r = h.withWakeupActor(r)
issueID := chi.URLParam(r, "id")
issue, ok := h.loadIssueForUser(w, r, issueID)
if !ok {
return
}
userID, ok := requireUserID(w, r)
if !ok {
return
}
var req struct {
Emoji string `json:"emoji"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "invalid request body")
return
}
if req.Emoji == "" {
writeError(w, http.StatusBadRequest, "emoji is required")
return
}
workspaceID := uuidToString(issue.WorkspaceID)
actorType, actorID := h.resolveActor(r, userID, workspaceID)
reaction, err := wakeupWrite(h, r, func(q *db.Queries) (db.AddIssueReactionRow, error) {
return q.AddIssueReaction(r.Context(), db.AddIssueReactionParams{
IssueID: issue.ID,
WorkspaceID: issue.WorkspaceID,
ActorType: actorType,
ActorID: parseUUID(actorID),
Emoji: req.Emoji,
})
})
if err != nil {
slog.Warn("add issue reaction failed", append(logger.RequestAttrs(r), "error", err, "issue_id", issueID)...)
writeError(w, http.StatusInternalServerError, "failed to add reaction")
return
}
resp := addedIssueReactionToResponse(reaction)
if reaction.IssueRevision > 0 {
h.publish(protocol.EventIssueReactionAdded, workspaceID, actorType, actorID, map[string]any{
"reaction": resp,
"issue_id": uuidToString(issue.ID),
"issue_title": issue.Title,
"issue_status": issue.Status,
"creator_type": issue.CreatorType,
"creator_id": uuidToString(issue.CreatorID),
"issue_revision": reaction.IssueRevision,
})
}
writeJSON(w, http.StatusCreated, resp)
}
func (h *Handler) RemoveIssueReaction(w http.ResponseWriter, r *http.Request) {
r = h.withWakeupActor(r)
issueID := chi.URLParam(r, "id")
issue, ok := h.loadIssueForUser(w, r, issueID)
if !ok {
return
}
userID, ok := requireUserID(w, r)
if !ok {
return
}
var req struct {
Emoji string `json:"emoji"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "invalid request body")
return
}
if req.Emoji == "" {
writeError(w, http.StatusBadRequest, "emoji is required")
return
}
workspaceID := uuidToString(issue.WorkspaceID)
actorType, actorID := h.resolveActor(r, userID, workspaceID)
removed, err := wakeupWrite(h, r, func(q *db.Queries) (db.RemoveIssueReactionRow, error) {
return q.RemoveIssueReaction(r.Context(), db.RemoveIssueReactionParams{
IssueID: issue.ID,
ActorType: actorType,
ActorID: parseUUID(actorID),
Emoji: req.Emoji,
})
})
if err != nil {
slog.Warn("remove issue reaction failed", append(logger.RequestAttrs(r), "error", err, "issue_id", issueID)...)
writeError(w, http.StatusInternalServerError, "failed to remove reaction")
return
}
if removed.Changed {
h.publish(protocol.EventIssueReactionRemoved, workspaceID, actorType, actorID, map[string]any{
"issue_id": uuidToString(issue.ID),
"emoji": req.Emoji,
"actor_type": actorType,
"actor_id": actorID,
"issue_revision": removed.IssueRevision,
})
}
w.WriteHeader(http.StatusNoContent)
}