🐛 Fix empty message
This commit is contained in:
parent
9b76311462
commit
25578f83f3
@ -5,7 +5,6 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/external"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/services"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
@ -44,7 +43,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Connect other services
|
||||
external.SetupLiveKit()
|
||||
services.SetupLiveKit()
|
||||
if err := grpc.ConnectPassport(); err != nil {
|
||||
log.Fatal().Err(err).Msg("An error occurred when connecting to passport...")
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package models
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
const (
|
||||
MessageTextType = "m.text"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
BaseModel
|
||||
|
||||
|
@ -2,11 +2,11 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/database"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/models"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func listMessage(c *fiber.Ctx) error {
|
||||
@ -54,8 +54,12 @@ func newMessage(c *fiber.Ctx) error {
|
||||
|
||||
if err := BindAndValidate(c, &data); err != nil {
|
||||
return err
|
||||
} else if len(data.Attachments) == 0 && len(data.Content) == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "you must write or upload some content in a single message")
|
||||
} 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 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "message uuid was not valid")
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/database"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/external"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/models"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/livekit/protocol/auth"
|
||||
@ -80,7 +79,7 @@ func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call,
|
||||
return call, fmt.Errorf("this channel already has an ongoing call")
|
||||
}
|
||||
|
||||
_, err := external.Lk.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
|
||||
_, err := Lk.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
|
||||
Name: call.ExternalID,
|
||||
EmptyTimeout: viper.GetUint32("calling.empty_timeout_duration"),
|
||||
MaxParticipants: viper.GetUint32("calling.max_participants"),
|
||||
@ -123,7 +122,7 @@ func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call,
|
||||
func EndCall(call models.Call) (models.Call, error) {
|
||||
call.EndedAt = lo.ToPtr(time.Now())
|
||||
|
||||
if _, err := external.Lk.DeleteRoom(context.Background(), &livekit.DeleteRoomRequest{
|
||||
if _, err := Lk.DeleteRoom(context.Background(), &livekit.DeleteRoomRequest{
|
||||
Room: call.ExternalID,
|
||||
}); err != nil {
|
||||
log.Error().Err(err).Msg("Unable to delete room at livekit side")
|
||||
|
@ -1,4 +1,4 @@
|
||||
package external
|
||||
package services
|
||||
|
||||
import (
|
||||
lksdk "github.com/livekit/server-sdk-go"
|
Loading…
Reference in New Issue
Block a user