🐛 Bug fixes on community channel
This commit is contained in:
parent
e6d09ab41b
commit
f6482225ab
@ -211,14 +211,16 @@ func joinChannel(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
|
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
|
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
|
||||||
} else if channel.RealmID == nil {
|
} else if channel.RealmID == nil && !channel.IsCommunity {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "you was impossible to join a channel without related realm")
|
return fiber.NewError(fiber.StatusBadRequest, "you were impossible to join a channel without related realm and non-community")
|
||||||
}
|
}
|
||||||
|
|
||||||
if realm, err := services.GetRealmWithExtID(channel.Realm.ExternalID); err != nil {
|
if channel.RealmID != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("invalid channel, related realm was not found: %v", err))
|
if realm, err := services.GetRealmWithExtID(channel.Realm.ExternalID); err != nil {
|
||||||
} else if _, err := services.GetRealmMember(realm.ExternalID, user.ID); err != nil {
|
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("invalid channel, related realm was not found: %v", err))
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a part of the realm: %v", err))
|
} else if _, err := services.GetRealmMember(realm.ExternalID, user.ID); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a part of the realm: %v", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := services.AddChannelMember(user, channel); err != nil {
|
if err := services.AddChannelMember(user, channel); err != nil {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getChannel(c *fiber.Ctx) error {
|
func getChannel(c *fiber.Ctx) error {
|
||||||
@ -52,12 +53,17 @@ func getChannelIdentity(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func listChannel(c *fiber.Ctx) error {
|
func listChannel(c *fiber.Ctx) error {
|
||||||
|
var user *models.Account
|
||||||
|
if err := gap.H.EnsureAuthenticated(c); err == nil {
|
||||||
|
user = lo.ToPtr(c.Locals("user").(models.Account))
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var channels []models.Channel
|
var channels []models.Channel
|
||||||
if val, ok := c.Locals("realm").(models.Realm); ok {
|
if val, ok := c.Locals("realm").(models.Realm); ok {
|
||||||
channels, err = services.ListChannel(val.ID)
|
channels, err = services.ListChannel(user, val.ID)
|
||||||
} else {
|
} else {
|
||||||
channels, err = services.ListChannel()
|
channels, err = services.ListChannel(user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
@ -58,7 +58,8 @@ func createDirectChannel(c *fiber.Ctx) error {
|
|||||||
Alias: data.Alias,
|
Alias: data.Alias,
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Description: data.Description,
|
Description: data.Description,
|
||||||
IsEncrypted: data.IsEncrypted,
|
IsPublic: false,
|
||||||
|
IsCommunity: false,
|
||||||
AccountID: user.ID,
|
AccountID: user.ID,
|
||||||
Type: models.ChannelTypeDirect,
|
Type: models.ChannelTypeDirect,
|
||||||
Members: []models.ChannelMember{
|
Members: []models.ChannelMember{
|
||||||
|
Loading…
Reference in New Issue
Block a user