mirror of
https://github.com/owncast/owncast.git
synced 2024-11-29 11:39:08 +03:00
8a74af202d
* update message viz in db * create admin endpoint to update message visibility * convert UpdateMessageVisibility api to take in an array of IDs to change visibility on instead * Support requesting filtered or unfiltered chat messages * Handle UPDATE chat events on front and backend for toggling messages * Return entire message with UPDATE events * Remove the UPDATE message type * Revert "Remove the UPDATE message type" This reverts commit 3a83df3d492f7ecf2bab65e845aa2b0365d3a7f6. * update -> visibility update * completely remove messages when they turn hidden on VISIBILITY-UPDATEs, and insert them if they turn visible * Explicitly set visibility * Fix multi-id sql updates * increate scroll buffer a bit so chat scrolls when new large messages come in * Add automated test around chat moderation * Add new chat admin APIs to api spec * Commit updated API documentation Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: Owncast <owncast@owncast.online>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/owncast/owncast/core"
|
|
"github.com/owncast/owncast/models"
|
|
"github.com/owncast/owncast/router/middleware"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// GetChatMessages gets all of the chat messages.
|
|
func GetChatMessages(w http.ResponseWriter, r *http.Request) {
|
|
middleware.EnableCors(&w)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
messages := core.GetAllChatMessages(true)
|
|
|
|
err := json.NewEncoder(w).Encode(messages)
|
|
if err != nil {
|
|
log.Errorln(err)
|
|
}
|
|
case http.MethodPost:
|
|
var message models.ChatEvent
|
|
if err := json.NewDecoder(r.Body).Decode(&message); err != nil {
|
|
internalErrorHandler(w, err)
|
|
return
|
|
}
|
|
|
|
if err := core.SendMessageToChat(message); err != nil {
|
|
badRequestHandler(w, err)
|
|
return
|
|
}
|
|
|
|
if err := json.NewEncoder(w).Encode(j{"success": true}); err != nil {
|
|
internalErrorHandler(w, err)
|
|
return
|
|
}
|
|
default:
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
if err := json.NewEncoder(w).Encode(j{"error": "method not implemented (PRs are accepted)"}); err != nil {
|
|
internalErrorHandler(w, err)
|
|
}
|
|
}
|
|
}
|