add client adding logic

This commit is contained in:
gitGnome
2026-03-25 13:46:53 +01:00
parent defed9c268
commit ca0b85cdb7
4 changed files with 48 additions and 2 deletions
+22
View File
@@ -2,7 +2,9 @@ package main
import (
"context"
"time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
@@ -121,3 +123,23 @@ func DbSetGroupById(ctx context.Context, group *Group) error {
}
return rows.Err()
}
func DbAddClientsToGroup(ctx context.Context, groupId uint32, clientIds []uint32) error {
batch := &pgx.Batch{}
now := time.Now()
for _, cid := range clientIds {
batch.Queue(`
INSERT INTO chat_group_members (group_id, user_id, joined_at)
VALUES ($1, $2, $3)
ON CONFLICT DO NOTHING
`, groupId, cid, now)
}
br := dbConn.SendBatch(ctx, batch)
defer br.Close()
for range clientIds {
if _, err := br.Exec(); err != nil {
return err
}
}
return nil
}