From 54739cd11ea1293f99fc33ebe3d8d056820d8295 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 7 Aug 2024 18:34:44 +0800 Subject: [PATCH] :bug: Fix empty message --- pkg/internal/server/api/events_message_api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/internal/server/api/events_message_api.go b/pkg/internal/server/api/events_message_api.go index e3fc165..1437319 100644 --- a/pkg/internal/server/api/events_message_api.go +++ b/pkg/internal/server/api/events_message_api.go @@ -1,6 +1,8 @@ package api import ( + "strings" + "git.solsynth.dev/hydrogen/messaging/pkg/internal/gap" "git.solsynth.dev/hydrogen/messaging/pkg/internal/models" "git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts" @@ -50,6 +52,13 @@ 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,