🐛 Fix empty message
This commit is contained in:
parent
1867ff64f7
commit
54739cd11e
@ -1,6 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
||||||
@ -50,6 +52,13 @@ func newMessageEvent(c *fiber.Ctx) error {
|
|||||||
raw, _ := jsoniter.Marshal(data.Body)
|
raw, _ := jsoniter.Marshal(data.Body)
|
||||||
_ = jsoniter.Unmarshal(raw, &parsed)
|
_ = 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{
|
event := models.Event{
|
||||||
Uuid: data.Uuid,
|
Uuid: data.Uuid,
|
||||||
Body: parsed,
|
Body: parsed,
|
||||||
|
Loading…
Reference in New Issue
Block a user