diff --git a/controller/channel.go b/controller/channel.go index eb95ccc364e..9eef9f0ed84 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -85,6 +85,8 @@ func GetAllChannels(c *gin.Context) { typeFilter = t } } + // group filter + groupFilter := c.Query("group") var total int64 @@ -114,6 +116,11 @@ func GetAllChannels(c *gin.Context) { if typeFilter >= 0 && ch.Type != typeFilter { continue } + if groupFilter != "" && groupFilter != "null" { + if !strings.Contains(","+ch.Group+",", ","+groupFilter+",") { + continue + } + } filtered = append(filtered, ch) } channelData = append(channelData, filtered...) @@ -129,6 +136,14 @@ func GetAllChannels(c *gin.Context) { } else if statusFilter == 0 { baseQuery = baseQuery.Where("status != ?", common.ChannelStatusEnabled) } + if groupFilter != "" && groupFilter != "null" { + if common.UsingMySQL { + baseQuery = baseQuery.Where("CONCAT(',', `group`, ',') LIKE ?", "%,"+groupFilter+",%") + } else { + // SQLite, PostgreSQL + baseQuery = baseQuery.Where("(',' || \"group\" || ',') LIKE ?", "%,"+groupFilter+",%") + } + } baseQuery.Count(&total)