✨ Global wide channels api
This commit is contained in:
parent
a8dbcfdb05
commit
0756806f20
@ -114,6 +114,20 @@ func listOwnedChannel(c *fiber.Ctx) error {
|
||||
return c.JSON(channels)
|
||||
}
|
||||
|
||||
func listOwnedChannelGlobalWide(c *fiber.Ctx) error {
|
||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
}
|
||||
user := c.Locals("user").(authm.Account)
|
||||
|
||||
channels, err := services.ListChannelWithUser(user, 0)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(channels)
|
||||
}
|
||||
|
||||
func listAvailableChannel(c *fiber.Ctx) error {
|
||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
@ -142,6 +156,20 @@ func listAvailableChannel(c *fiber.Ctx) error {
|
||||
return c.JSON(channels)
|
||||
}
|
||||
|
||||
func listAvailableChannelGlobalWide(c *fiber.Ctx) error {
|
||||
if err := sec.EnsureAuthenticated(c); err != nil {
|
||||
return err
|
||||
}
|
||||
user := c.Locals("user").(authm.Account)
|
||||
|
||||
channels, err := services.ListAvailableChannel(database.C, user, 0)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(channels)
|
||||
}
|
||||
|
||||
func createChannel(c *fiber.Ctx) error {
|
||||
if err := sec.EnsureGrantedPerm(c, "CreateChannels", true); err != nil {
|
||||
return err
|
||||
|
@ -12,6 +12,9 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
quick.Post("/:channelId/reply/:eventId", quickReply)
|
||||
}
|
||||
|
||||
api.Get("/channels/me", listOwnedChannelGlobalWide)
|
||||
api.Get("/channels/me/available", listAvailableChannelGlobalWide)
|
||||
|
||||
channels := api.Group("/channels/:realm").Use(realmMiddleware).Name("Channels API")
|
||||
{
|
||||
channels.Get("/", listChannel)
|
||||
|
@ -228,7 +228,9 @@ func ListChannelWithUser(user authm.Account, realmId ...uint) ([]models.Channel,
|
||||
var channels []models.Channel
|
||||
tx := database.C.Where(&models.Channel{AccountID: user.ID})
|
||||
if len(realmId) > 0 {
|
||||
tx = tx.Where("realm_id = ?", realmId)
|
||||
if realmId[0] != 0 {
|
||||
tx = tx.Where("realm_id = ?", realmId)
|
||||
}
|
||||
}
|
||||
|
||||
tx = PreloadDirectChannelMembers(tx)
|
||||
@ -255,7 +257,9 @@ func ListAvailableChannel(tx *gorm.DB, user authm.Account, realmId ...uint) ([]m
|
||||
|
||||
tx = tx.Where("id IN ?", idx)
|
||||
if len(realmId) > 0 {
|
||||
tx = tx.Where("realm_id = ?", realmId)
|
||||
if realmId[0] != 0 {
|
||||
tx = tx.Where("realm_id = ?", realmId)
|
||||
}
|
||||
} else {
|
||||
tx = tx.Where("realm_id IS NULL")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user