🐛 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())
|
||||
} else if _, _, err := services.GetAvailableChannel(channel.ID, user); err == nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "you already joined the channel")
|
||||
} else if channel.RealmID == nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "you was impossible to join a channel without related realm")
|
||||
} else if channel.RealmID == nil && !channel.IsCommunity {
|
||||
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 {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("invalid channel, related realm was not found: %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 channel.RealmID != nil {
|
||||
if realm, err := services.GetRealmWithExtID(channel.Realm.ExternalID); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("invalid channel, related realm was not found: %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 {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func getChannel(c *fiber.Ctx) error {
|
||||
@ -52,12 +53,17 @@ func getChannelIdentity(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 channels []models.Channel
|
||||
if val, ok := c.Locals("realm").(models.Realm); ok {
|
||||
channels, err = services.ListChannel(val.ID)
|
||||
channels, err = services.ListChannel(user, val.ID)
|
||||
} else {
|
||||
channels, err = services.ListChannel()
|
||||
channels, err = services.ListChannel(user)
|
||||
}
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
|
@ -58,7 +58,8 @@ func createDirectChannel(c *fiber.Ctx) error {
|
||||
Alias: data.Alias,
|
||||
Name: data.Name,
|
||||
Description: data.Description,
|
||||
IsEncrypted: data.IsEncrypted,
|
||||
IsPublic: false,
|
||||
IsCommunity: false,
|
||||
AccountID: user.ID,
|
||||
Type: models.ChannelTypeDirect,
|
||||
Members: []models.ChannelMember{
|
||||
|
Loading…
Reference in New Issue
Block a user