diff --git a/pkg/internal/server/api/channel_members_api.go b/pkg/internal/server/api/channel_members_api.go index 0b4c472..1cfb6d1 100644 --- a/pkg/internal/server/api/channel_members_api.go +++ b/pkg/internal/server/api/channel_members_api.go @@ -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 { diff --git a/pkg/internal/server/api/channels_api.go b/pkg/internal/server/api/channels_api.go index 6936360..0f9aa25 100644 --- a/pkg/internal/server/api/channels_api.go +++ b/pkg/internal/server/api/channels_api.go @@ -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()) diff --git a/pkg/internal/server/api/direct_channels_api.go b/pkg/internal/server/api/direct_channels_api.go index 21712b5..ec06491 100644 --- a/pkg/internal/server/api/direct_channels_api.go +++ b/pkg/internal/server/api/direct_channels_api.go @@ -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{