mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
fix(channel): allow attachment-only messages via WebSocket (#331)
The WebSocket handler rejected messages with empty text even when attachments were present, while the HTTP POST endpoint correctly used Message.IsEmpty(). Move the empty-check after attachment parsing so only truly empty messages are rejected.
This commit is contained in:
@@ -392,10 +392,6 @@ func (h *LocalChannelHandler) HandleWebSocket(c echo.Context) error {
|
||||
|
||||
case "message":
|
||||
text := strings.TrimSpace(msg.Text)
|
||||
if text == "" {
|
||||
writer.SendJSON(map[string]string{"type": "error", "message": "message text is required"})
|
||||
continue
|
||||
}
|
||||
|
||||
chatAttachments := make([]conversation.ChatAttachment, 0, len(msg.Attachments))
|
||||
for _, rawAtt := range msg.Attachments {
|
||||
@@ -405,6 +401,11 @@ func (h *LocalChannelHandler) HandleWebSocket(c echo.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if text == "" && len(chatAttachments) == 0 {
|
||||
writer.SendJSON(map[string]string{"type": "error", "message": "message text or attachments required"})
|
||||
continue
|
||||
}
|
||||
|
||||
// Drain any previous abort signal.
|
||||
select {
|
||||
case <-abortCh:
|
||||
|
||||
Reference in New Issue
Block a user