🐛 Fix empty message detection
This commit is contained in:
		| @@ -54,16 +54,20 @@ func newMessage(c *fiber.Ctx) error { | |||||||
|  |  | ||||||
| 	if err := BindAndValidate(c, &data); err != nil { | 	if err := BindAndValidate(c, &data); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} else if len(data.Attachments) == 0 { |  | ||||||
| 		if val, ok := data.Content["type"]; ok && val == models.MessageTextType { |  | ||||||
| 			if val, ok := data.Content["value"].(string); ok && len(strings.TrimSpace(val)) == 0 { |  | ||||||
| 				return fiber.NewError(fiber.StatusBadRequest, "you cannot send an empty message") |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} else if len(data.Uuid) < 36 { | 	} else if len(data.Uuid) < 36 { | ||||||
| 		return fiber.NewError(fiber.StatusBadRequest, "message uuid was not valid") | 		return fiber.NewError(fiber.StatusBadRequest, "message uuid was not valid") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if len(data.Attachments) == 0 { | ||||||
|  | 		if data.Type == models.MessageTextType { | ||||||
|  | 			if val, ok := data.Content["value"].(string); ok && len(strings.TrimSpace(val)) == 0 { | ||||||
|  | 				return fiber.NewError(fiber.StatusBadRequest, "you cannot send an empty message") | ||||||
|  | 			} else if !ok { | ||||||
|  | 				return fiber.NewError(fiber.StatusBadRequest, "invalid content of text message") | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	for _, attachment := range data.Attachments { | 	for _, attachment := range data.Attachments { | ||||||
| 		if !services.CheckAttachmentByIDExists(attachment, "m.attachment") { | 		if !services.CheckAttachmentByIDExists(attachment, "m.attachment") { | ||||||
| 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %d not found", attachment)) | 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("attachment %d not found", attachment)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user