Update chat message visibility for moderation (#524)

* 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>
This commit is contained in:
gingervitis
2020-12-29 13:35:33 -08:00
committed by GitHub
parent 0452c4c5fc
commit 8a74af202d
18 changed files with 375 additions and 64 deletions

View File

@@ -30,7 +30,7 @@ type Client struct {
socketID string // How we identify a single websocket client.
ws *websocket.Conn
ch chan models.ChatMessage
ch chan models.ChatEvent
pingch chan models.PingMessage
usernameChangeChannel chan models.NameChangeEvent
@@ -38,10 +38,11 @@ type Client struct {
}
const (
CHAT = "CHAT"
NAMECHANGE = "NAME_CHANGE"
PING = "PING"
PONG = "PONG"
CHAT = "CHAT"
NAMECHANGE = "NAME_CHANGE"
PING = "PING"
PONG = "PONG"
VISIBILITYUPDATE = "VISIBILITY-UPDATE"
)
// NewClient creates a new chat client.
@@ -50,7 +51,7 @@ func NewClient(ws *websocket.Conn) *Client {
log.Panicln("ws cannot be nil")
}
ch := make(chan models.ChatMessage, channelBufSize)
ch := make(chan models.ChatEvent, channelBufSize)
doneCh := make(chan bool)
pingch := make(chan models.PingMessage)
usernameChangeChannel := make(chan models.NameChangeEvent)
@@ -68,7 +69,7 @@ func (c *Client) GetConnection() *websocket.Conn {
return c.ws
}
func (c *Client) Write(msg models.ChatMessage) {
func (c *Client) Write(msg models.ChatEvent) {
select {
case c.ch <- msg:
default:
@@ -176,7 +177,7 @@ func (c *Client) userChangedName(data []byte) {
}
func (c *Client) chatMessageReceived(data []byte) {
var msg models.ChatMessage
var msg models.ChatEvent
err := json.Unmarshal(data, &msg)
if err != nil {
log.Errorln(err)