feat: enforce tenant content moderation
This commit is contained in:
@@ -10,11 +10,13 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tinode/chat/server/moderation"
|
||||
"github.com/tinode/chat/server/store/types"
|
||||
)
|
||||
|
||||
@@ -1619,6 +1621,20 @@ func ErrPolicyReply(msg *ClientComMessage, ts time.Time) *ServerComMessage {
|
||||
return ErrPolicyExplicitTs(msg.Id, msg.Original, ts, msg.Timestamp)
|
||||
}
|
||||
|
||||
func ErrContentModerationReply(msg *ClientComMessage, ts time.Time, err error, result *moderation.Result) *ServerComMessage {
|
||||
reply := ErrPolicyReply(msg, ts)
|
||||
reason := "CONTENT_REJECTED"
|
||||
if errors.Is(err, moderation.ErrUnavailable) {
|
||||
reason = "CONTENT_REVIEW_UNAVAILABLE"
|
||||
}
|
||||
reply.Ctrl.Text = "content rejected"
|
||||
reply.Ctrl.Params = map[string]any{"reason": reason}
|
||||
if result != nil && strings.TrimSpace(result.BlockMessage) != "" {
|
||||
reply.Ctrl.Params.(map[string]any)["message"] = result.BlockMessage
|
||||
}
|
||||
return reply
|
||||
}
|
||||
|
||||
// ErrCallBusyExplicitTs indicates a "busy" reply to a video call request (486).
|
||||
func ErrCallBusyExplicitTs(id, topic string, serverTs, incomingReqTs time.Time) *ServerComMessage {
|
||||
return &ServerComMessage{
|
||||
|
||||
Reference in New Issue
Block a user