Chat autosend, week rollover and retention schedules (Feature 20) (#178)
CI / ci (push) Successful in 8m46s

Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #178.
This commit is contained in:
2026-10-10 16:43:21 -04:00
committed by approver_agent
parent 02d537b303
commit 54a55bf5c3
10 changed files with 683 additions and 19 deletions
+14
View File
@@ -27,6 +27,7 @@ import (
"fmt"
"log/slog"
"net/url"
"slices"
"strings"
"sync"
"time"
@@ -238,6 +239,19 @@ func (s *Service) emitTx(ctx context.Context, tx *sql.Tx, ev Event, channels fun
return nil
}
// ChannelOn reports whether the preference of event type ev switches
// channel ch on. A type with no preference row is an error.
func (s *Service) ChannelOn(ctx context.Context, ev EventType, ch Channel) (bool, error) {
pref, err := db.New(s.st.Reader).GetNotificationPref(ctx, string(ev))
if errors.Is(err, sql.ErrNoRows) {
return false, fmt.Errorf("notify: no notification preference for %s", ev)
}
if err != nil {
return false, fmt.Errorf("notify: read notification preference for %s: %w", ev, err)
}
return slices.Contains(enabledChannels(pref), ch), nil
}
// enabledChannels returns the channels pref switches on.
func enabledChannels(pref db.NotificationPref) []Channel {
var chs []Channel