feat: enforce tenant content moderation

This commit is contained in:
richjohnrambo
2026-09-16 22:21:25 +08:00
parent 0ae4af0c31
commit 0f8e3b82b7
26 changed files with 891 additions and 1 deletions
+16
View File
@@ -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{