Better pulling available channel api by dividing dm and non-dm

This commit is contained in:
2024-10-05 17:46:39 +08:00
parent f958201097
commit a3ef3d52d7
4 changed files with 16 additions and 15 deletions

View File

@@ -98,12 +98,20 @@ func listAvailableChannel(c *fiber.Ctx) error {
}
user := c.Locals("user").(models.Account)
tx := database.C
isDirect := c.QueryBool("direct", false)
if isDirect {
tx = tx.Where("type = ?", models.ChannelTypeDirect)
} else {
tx = tx.Where("type = ?", models.ChannelTypeCommon)
}
var err error
var channels []models.Channel
if val, ok := c.Locals("realm").(models.Realm); ok {
channels, err = services.ListAvailableChannel(user, val.ID)
channels, err = services.ListAvailableChannel(tx, user, val.ID)
} else {
channels, err = services.ListAvailableChannel(user)
channels, err = services.ListAvailableChannel(tx, user)
}
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())