From 1bc687eba69e77bfa7d0817e74d94a72f47777e8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 7 Aug 2024 18:39:38 +0800 Subject: [PATCH] :bug: Fix empty message... again --- pkg/internal/server/api/events_message_api.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/internal/server/api/events_message_api.go b/pkg/internal/server/api/events_message_api.go index 1437319..d632397 100644 --- a/pkg/internal/server/api/events_message_api.go +++ b/pkg/internal/server/api/events_message_api.go @@ -30,8 +30,9 @@ func newMessageEvent(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, "message uuid was not valid") } + data.Body.Text = strings.TrimSpace(data.Body.Text) if len(data.Body.Text) == 0 && len(data.Body.Attachments) == 0 { - return fiber.NewError(fiber.StatusBadRequest, "cannot send an empty message") + return fiber.NewError(fiber.StatusBadRequest, "empty message was not allowed") } var err error @@ -52,13 +53,6 @@ func newMessageEvent(c *fiber.Ctx) error { raw, _ := jsoniter.Marshal(data.Body) _ = jsoniter.Unmarshal(raw, &parsed) - if val, ok := parsed["text"].(string); ok { - val = strings.TrimSpace(val) - parsed["text"] = val - } else if files, ok := parsed["attachments"].([]any); (!ok || len(files) == 0) && len(val) == 0 { - return fiber.NewError(fiber.StatusBadRequest, "empty message was not allowed") - } - event := models.Event{ Uuid: data.Uuid, Body: parsed,