From 6628f924ba4aefa8f8361ebc252fb225718359c2 Mon Sep 17 00:00:00 2001 From: bt Date: Thu, 4 Jun 2026 17:13:39 +0200 Subject: [common] Add channels list query --- storage/storage.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'storage/storage.go') diff --git a/storage/storage.go b/storage/storage.go index a32c4a0..6455876 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -169,6 +169,31 @@ func (db *Database) GetChannelUsers(channel string) (users []string, err error) return users, nil } +func (db *Database) GetUserChannels(user string, count, offset int) (channels []string, err error) { + rows, err := db.Query("SELECT channel FROM permissions WHERE user = ? AND write = 1;", user) + defer func() { + if rows == nil { + return + } + if err := rows.Close(); err != nil { + log.Println("cannot close database row:", err) + } + }() + if err != nil { + return channels, err + } + + for rows.Next() { + var channel string + if err := rows.Scan(&channel); err != nil { + return channels, err + } + channels = append(channels, channel) + } + + return channels, nil +} + func itob(v int) bool { if v == 1 { return true -- cgit v1.2.3