forked from owncast/owncast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update chat message visibility for moderation (owncast#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 3a83df3. * 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 <[email protected]> Co-authored-by: Owncast <[email protected]>
- Loading branch information
1 parent
0452c4c
commit 8a74af2
Showing
18 changed files
with
375 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ webroot/static/content.md | |
hls/ | ||
dist/ | ||
data/ | ||
admin/ | ||
transcoder.log | ||
chat.db | ||
.yp.key | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package admin | ||
|
||
// this is endpoint logic | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/owncast/owncast/controllers" | ||
"github.com/owncast/owncast/core" | ||
"github.com/owncast/owncast/core/chat" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// UpdateMessageVisibility updates an array of message IDs to have the same visiblity. | ||
func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
controllers.WriteSimpleResponse(w, false, r.Method+" not supported") | ||
return | ||
} | ||
|
||
decoder := json.NewDecoder(r.Body) | ||
var request messageVisibilityUpdateRequest // creates an empty struc | ||
|
||
err := decoder.Decode(&request) // decode the json into `request` | ||
if err != nil { | ||
log.Errorln(err) | ||
controllers.WriteSimpleResponse(w, false, "") | ||
return | ||
} | ||
|
||
// // make sql update call here. | ||
// // := means create a new var | ||
// _db := data.GetDatabase() | ||
// updateMessageVisibility(_db, request) | ||
|
||
if err := chat.SetMessagesVisibility(request.IDArray, request.Visible); err != nil { | ||
controllers.WriteSimpleResponse(w, false, err.Error()) | ||
return | ||
} | ||
|
||
controllers.WriteSimpleResponse(w, true, "changed") | ||
} | ||
|
||
type messageVisibilityUpdateRequest struct { | ||
IDArray []string `json:"idArray"` | ||
Visible bool `json:"visible"` | ||
} | ||
|
||
// GetChatMessages returns all of the chat messages, unfiltered. | ||
func GetChatMessages(w http.ResponseWriter, r *http.Request) { | ||
// middleware.EnableCors(&w) | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
messages := core.GetAllChatMessages(false) | ||
|
||
if err := json.NewEncoder(w).Encode(messages); err != nil { | ||
log.Errorln(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package chat | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func SetMessagesVisibility(messageIDs []string, visibility bool) error { | ||
// Save new message visibility | ||
if err := saveMessageVisibility(messageIDs, visibility); err != nil { | ||
log.Errorln(err) | ||
return err | ||
} | ||
|
||
// Send an update event to all clients for each message. | ||
// Note: Our client expects a single message at a time, so we can't just | ||
// send an array of messages in a single update. | ||
for _, id := range messageIDs { | ||
message, err := getMessageById(id) | ||
if err != nil { | ||
log.Errorln(err) | ||
continue | ||
} | ||
message.MessageType = VISIBILITYUPDATE | ||
_server.sendAll(message) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.