feat: host the BM chat context
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.
This commit is contained in:
36
controllers/api/chat.go
Normal file
36
controllers/api/chat.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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})
|
||||
}
|
||||
Reference in New Issue
Block a user