From 4da282012dc6d93b2bec5dfdbea27c319f1fc483 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 8 Jun 2024 23:59:25 +0800 Subject: [PATCH] :bug: Fix cannot get channel properly --- pkg/server/channel_members_api.go | 10 ++++++++-- pkg/server/startup.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/server/channel_members_api.go b/pkg/server/channel_members_api.go index abdd8c7..d513d0b 100644 --- a/pkg/server/channel_members_api.go +++ b/pkg/server/channel_members_api.go @@ -135,7 +135,7 @@ func removeChannelMember(c *fiber.Ctx) error { } } -func editChannelMembership(c *fiber.Ctx) error { +func editMyChannelMembership(c *fiber.Ctx) error { user := c.Locals("principal").(models.Account) alias := c.Params("channel") @@ -148,7 +148,13 @@ func editChannelMembership(c *fiber.Ctx) error { return err } - channel, err := services.GetChannelWithAlias(alias) + var err error + var channel models.Channel + if val, ok := c.Locals("realm").(models.Realm); ok { + channel, err = services.GetChannelWithAlias(alias, val.ID) + } else { + channel, err = services.GetChannelWithAlias(alias) + } if err != nil { return fiber.NewError(fiber.StatusNotFound, err.Error()) } diff --git a/pkg/server/startup.go b/pkg/server/startup.go index ea453ea..9117083 100644 --- a/pkg/server/startup.go +++ b/pkg/server/startup.go @@ -80,8 +80,8 @@ func NewServer() { channels.Delete("/:channelId", authMiddleware, deleteChannel) channels.Get("/:channel/members", listChannelMembers) - channels.Put("/:channel/members/me", authMiddleware, editChannelMembership) channels.Get("/:channel/members/me", authMiddleware, getMyChannelMembership) + channels.Put("/:channel/members/me", authMiddleware, editMyChannelMembership) channels.Post("/:channel/members", authMiddleware, addChannelMember) channels.Post("/:channel/members/me", authMiddleware, joinChannel) channels.Delete("/:channel/members", authMiddleware, removeChannelMember)