When golem15.chat is active, Boot registers the context alias bm (id 1) on its registry. Membership is the user group jz.bm.chat.group (default studenci); CanOverseeChats is always false, so nobody reads other people's DMs or edits their messages; the broadcast channel is chat:context:1, never empty. GET /_bm/api/v1/chat answers the caller's membership behind jwt.auth and the per-user bucket jz.bm.chat (240 a minute). The chat config block (group, moderator_group, max_upload_bytes, max_embeds) is added. jz.bm still Requires only golem15.user; all chat wiring is gated by HasPlugin.
37 lines
763 B
Go
37 lines
763 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
userclasses "git.golem15.com/golem15/sm-user-plugin/classes"
|
|
)
|
|
|
|
// chatBootstrapJSON is the answer of /chat. A user outside the chat group
|
|
// gets only member: false.
|
|
type chatBootstrapJSON struct {
|
|
Member bool `json:"member"`
|
|
}
|
|
|
|
// Chat answers GET /chat, the chat bootstrap: whether the caller is in the
|
|
// chat group.
|
|
func (h *Handlers) Chat(w http.ResponseWriter, r *http.Request) {
|
|
userID, ok := h.caller(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
db, ok := h.db(w, r)
|
|
if !ok {
|
|
return
|
|
}
|
|
member := false
|
|
if h.ChatGroup != "" {
|
|
var err error
|
|
member, err = userclasses.HasGroupCode(r.Context(), db, userID, h.ChatGroup)
|
|
if err != nil {
|
|
writeOpaque500(w)
|
|
return
|
|
}
|
|
}
|
|
writeData(w, chatBootstrapJSON{Member: member})
|
|
}
|