fix(bots): intercept /confess so original never hits chat
Root cause of "not anonymous": 1. Confess deleted via raw SQL with no MESSAGE_DELETE broadcast 2. Frontend extractIds only accepted message_id, but deletes send id so live clients never removed deleted messages without refresh Fix: - Intercept /confess at message create: never store or broadcast the original; post only the anonymous bot message - Accept both id and message_id on MESSAGE_DELETE in the WS store - Include both fields on delete broadcasts
This commit is contained in:
@@ -27,6 +27,13 @@ type Handler struct {
|
||||
pushHandler *push.Handler
|
||||
logger *slog.Logger
|
||||
checker *permissions.Checker
|
||||
// Optional: intercepts /confess so the original message is never stored/broadcast.
|
||||
confess ConfessHandler
|
||||
}
|
||||
|
||||
// ConfessHandler posts an anonymous confession and returns the bot message payload.
|
||||
type ConfessHandler interface {
|
||||
TryConfess(ctx context.Context, serverID, authorID, content string) (payload map[string]interface{}, handled bool)
|
||||
}
|
||||
|
||||
func NewHandler(db *sql.DB, hub *gateway.Hub, pushHandler *push.Handler, logger *slog.Logger, checker *permissions.Checker) *Handler {
|
||||
@@ -40,6 +47,11 @@ func NewHandler(db *sql.DB, hub *gateway.Hub, pushHandler *push.Handler, logger
|
||||
}
|
||||
}
|
||||
|
||||
// SetConfessHandler wires the built-in confess interceptor (optional).
|
||||
func (h *Handler) SetConfessHandler(c ConfessHandler) {
|
||||
h.confess = c
|
||||
}
|
||||
|
||||
func (h *Handler) RegisterRoutes(r chi.Router) {
|
||||
r.Get("/", h.List)
|
||||
r.Post("/", h.Create)
|
||||
@@ -119,6 +131,7 @@ func (h *Handler) BulkDelete(w http.ResponseWriter, r *http.Request) {
|
||||
Type: gateway.EventMessageDelete,
|
||||
Data: map[string]string{
|
||||
"id": id,
|
||||
"message_id": id,
|
||||
"channel_id": channelID,
|
||||
},
|
||||
})
|
||||
@@ -243,6 +256,16 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Anonymous confessions: never store/broadcast the original /confess message.
|
||||
if h.confess != nil {
|
||||
if payload, handled := h.confess.TryConfess(r.Context(), serverID, userID, req.Content); handled {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(payload)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var msg messageResponse
|
||||
var editedAt sql.NullString
|
||||
var createdAt sql.NullString
|
||||
@@ -467,6 +490,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
Type: gateway.EventMessageDelete,
|
||||
Data: map[string]string{
|
||||
"id": messageID,
|
||||
"message_id": messageID,
|
||||
"channel_id": channelID,
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user