Files
Docwell/Server/internal/httpapi/comments.go
T
tajniak81andClaude Opus 5.5 92cd81fd96 Add the slash menu, bubble menu, mentions and inline comments
Editor:
- "/" opens a filterable block menu (text, headings, lists, quote, code,
  divider, and image or file upload when the host can store files).
- Selecting text shows a formatting toolbar (bold, italic, strike, code,
  link) and, for anyone who may comment, a Comment button.
- "@" finds people in the page's workspace; the mention node is always in
  the schema so documents with mentions open in every client.
- The popups are plain DOM in the design system's slash-menu style, so
  the framework-free mobile bridge keeps building and can use them.
- Menu words come from the host; the web app passes English or Polish.

Inline comments (basic): commenters cannot edit the document, so a
comment's anchor is a pair of Yjs relative positions stored with the
comment rather than a mark in the text. Highlights follow local edits by
mapping and are re-resolved when comments change or remote edits arrive.
Pages get a comments panel (side column, or a bottom sheet on narrow
screens). Authors and space admins can delete comments.

Server: comments collection and endpoints, and a people lookup any
workspace member may use for mentions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:25:19 +01:00

37 lines
1.3 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
"context"
"net/http"
"docwell/server/internal/access"
"docwell/server/internal/directory"
)
// CommentService is the part of directory.Service for inline comments.
type CommentService interface {
ListComments(ctx context.Context, c access.Caller, pageID string) ([]directory.Comment, error)
CreateComment(ctx context.Context, c access.Caller, pageID string, in directory.CreateCommentInput) (directory.Comment, error)
DeleteComment(ctx context.Context, c access.Caller, id string) error
}
func (a *api) commentRoutes(mux *routeMux) {
mux.HandleFunc("GET /api/v1/pages/{id}/comments", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
list, err := a.dir.ListComments(r.Context(), caller(r), r.PathValue("id"))
a.respond(w, list, err)
}))
mux.HandleFunc("POST /api/v1/pages/{id}/comments", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
var in directory.CreateCommentInput
if !a.decode(w, r, &in) {
return
}
cm, err := a.dir.CreateComment(r.Context(), caller(r), r.PathValue("id"), in)
a.respondStatus(w, http.StatusCreated, cm, err)
}))
mux.HandleFunc("DELETE /api/v1/comments/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
a.respondNoContent(w, a.dir.DeleteComment(r.Context(), caller(r), r.PathValue("id")))
}))
}