Add comment threads, reactions, notifications and page watching
Comments are now threads: replies hang off a thread's first comment, which alone points at text and can be resolved. Authors can edit their own comments, and anyone who can comment can react with an emoji. Resolved threads stop lighting text in the editor and fold away in the panel. Comments can @mention people. People watch the pages they create or comment on, and can watch or mute a page from its menu. Muting is remembered. The inbox collects comments on watched pages, replies in your threads, mentions (in comments and in page text), pages shared with you and resolved threads. It shows an unread badge in the sidebar, polled every minute, and links straight to the thread. Nobody hears about their own actions or about pages they cannot open, and a notification hides its text once access is lost. Unread notifications are emailed as a digest every few minutes unless the person turns that off. Read ones are pruned after 90 days. The jobs registry can now run jobs on a timer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7968e82cc2
commit
2b78c167e2
31 files changed
+3083
-166
No files matched your search
@@ -5,16 +5,29 @@ package httpapi
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/directory"
|
||||
)
|
||||
|
||||
// CommentService is the part of directory.Service for inline comments.
|
||||
// CommentService is the part of directory.Service for comments, page
|
||||
// watching and notifications.
|
||||
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)
|
||||
UpdateComment(ctx context.Context, c access.Caller, id, body string) (directory.Comment, error)
|
||||
ResolveComment(ctx context.Context, c access.Caller, id string, resolved bool) (directory.Comment, error)
|
||||
ReactToComment(ctx context.Context, c access.Caller, id, emoji string, on bool) (directory.Comment, error)
|
||||
DeleteComment(ctx context.Context, c access.Caller, id string) error
|
||||
|
||||
GetWatch(ctx context.Context, c access.Caller, pageID string) (directory.WatchState, error)
|
||||
SetWatch(ctx context.Context, c access.Caller, pageID string, on bool) (directory.WatchState, error)
|
||||
|
||||
ListNotifications(ctx context.Context, c access.Caller, unreadOnly bool, limit int) (directory.NotificationList, error)
|
||||
MarkNotificationsRead(ctx context.Context, c access.Caller, ids []string, all bool) (int, error)
|
||||
GetNotificationSettings(ctx context.Context, c access.Caller) (directory.NotificationSettings, error)
|
||||
SetNotificationSettings(ctx context.Context, c access.Caller, in directory.NotificationSettings) (directory.NotificationSettings, error)
|
||||
}
|
||||
|
||||
func (a *api) commentRoutes(mux *routeMux) {
|
||||
@@ -30,7 +43,77 @@ func (a *api) commentRoutes(mux *routeMux) {
|
||||
cm, err := a.dir.CreateComment(r.Context(), caller(r), r.PathValue("id"), in)
|
||||
a.respondStatus(w, http.StatusCreated, cm, err)
|
||||
}))
|
||||
mux.HandleFunc("PATCH /api/v1/comments/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ Body string }
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
cm, err := a.dir.UpdateComment(r.Context(), caller(r), r.PathValue("id"), in.Body)
|
||||
a.respond(w, 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")))
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/comments/{id}/resolve", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ Resolved bool }
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
cm, err := a.dir.ResolveComment(r.Context(), caller(r), r.PathValue("id"), in.Resolved)
|
||||
a.respond(w, cm, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/comments/{id}/reactions", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
Emoji string
|
||||
On bool
|
||||
}
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
cm, err := a.dir.ReactToComment(r.Context(), caller(r), r.PathValue("id"), in.Emoji, in.On)
|
||||
a.respond(w, cm, err)
|
||||
}))
|
||||
|
||||
mux.HandleFunc("GET /api/v1/pages/{id}/watch", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
st, err := a.dir.GetWatch(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, st, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/pages/{id}/watch", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ Watching bool }
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
st, err := a.dir.SetWatch(r.Context(), caller(r), r.PathValue("id"), in.Watching)
|
||||
a.respond(w, st, err)
|
||||
}))
|
||||
|
||||
mux.HandleFunc("GET /api/v1/notifications", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
limit, _ := strconv.Atoi(q.Get("limit"))
|
||||
list, err := a.dir.ListNotifications(r.Context(), caller(r), q.Get("unread") == "true", limit)
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/notifications/read", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
IDs []string
|
||||
All bool
|
||||
}
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
n, err := a.dir.MarkNotificationsRead(r.Context(), caller(r), in.IDs, in.All)
|
||||
a.respond(w, map[string]int{"unread": n}, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/notifications/settings", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
st, err := a.dir.GetNotificationSettings(r.Context(), caller(r))
|
||||
a.respond(w, st, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/notifications/settings", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in directory.NotificationSettings
|
||||
if !a.decode(w, r, &in) {
|
||||
return
|
||||
}
|
||||
st, err := a.dir.SetNotificationSettings(r.Context(), caller(r), in)
|
||||
a.respond(w, st, err)
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user