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