Files
Docwell/Server/internal/directory/people.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

66 lines
1.9 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package directory
import (
"context"
"fmt"
"sort"
"strings"
"docwell/server/internal/access"
"docwell/server/internal/auth"
"docwell/server/internal/store/pocketbase"
)
// ListPeople finds people in a workspace by name or email, for mentions. Any
// member may look; it lists the explicit members and the organization's
// admins (who are in every workspace through the cascade).
func (s *Service) ListPeople(ctx context.Context, c access.Caller, wsID, query string, limit int) ([]MemberUser, error) {
ws, _, err := s.workspaceFor(ctx, c, wsID)
if err != nil {
return nil, err
}
if limit <= 0 || limit > 50 {
limit = 10
}
q := filterValue(query)
match := ""
if q != "" {
match = fmt.Sprintf(" && (user.name ~ '%s' || user.email ~ '%s')", q, q)
}
members, err := pocketbase.List[memberRecord](ctx, s.pb, "workspace_members", pocketbase.ListOptions{
PerPage: limit, Filter: fmt.Sprintf("workspace = '%s'", ws.ID) + match, Expand: "user",
})
if err != nil {
return nil, err
}
seen := map[string]bool{}
out := []MemberUser{}
add := func(u *auth.UserRecord) {
if u == nil || seen[u.ID] || u.Status == "disabled" {
return
}
seen[u.ID] = true
out = append(out, MemberUser{ID: u.ID, Email: u.Email, Name: u.Name})
}
for _, m := range members.Items {
add(m.Expand.User)
}
adminMatch := ""
if q != "" {
adminMatch = fmt.Sprintf(" && (name ~ '%s' || email ~ '%s')", q, q)
}
admins, err := pocketbase.List[auth.UserRecord](ctx, s.pb, "users", pocketbase.ListOptions{
PerPage: limit, Filter: fmt.Sprintf("organization = '%s' && role = 'admin'", ws.Organization) + adminMatch,
})
if err != nil {
return nil, err
}
for i := range admins.Items {
add(&admins.Items[i])
}
sort.Slice(out, func(i, j int) bool { return strings.ToLower(out[i].Name) < strings.ToLower(out[j].Name) })
return out[:min(limit, len(out))], nil
}