This commit is contained in:
ponzischeme89
2026-08-19 06:57:59 +12:00
parent 8c847c59b8
commit 2b43b9ef12
94 changed files with 6359 additions and 778 deletions
+37 -17
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/ponzischeme89/memby/server/internal/notify"
"github.com/ponzischeme89/memby/server/internal/scheduler"
"github.com/ponzischeme89/memby/server/internal/store"
)
@@ -138,19 +139,31 @@ func (s *Server) sendWeeklyWatchTime(
if total < watchTimeDigestFloor {
continue
}
if !s.watchTimeDigestWanted(ctx, account.ID) {
continue
}
monthWatched := lookupWatchTimeRange(monthByID, monthByName, identity, account.Username)
message := weeklyDigestMessage(
total, time.Duration(monthWatched.Ms)*time.Millisecond, watched.TopTitle)
if err := s.store.UpsertNotification(
ctx, account.ID, key, watchTimeWeeklyKind, "", "Your week in Memby", message, &eventAt,
); err != nil {
s.log.Warn("weekly watch-time summary failed", "user", account.ID, "error", err)
notification := notify.Notification{
Kind: watchTimeWeeklyKind,
Source: notifySourceWatchTime,
UserID: account.ID,
Username: account.Username,
Title: "Your week in Memby",
Body: message,
SourceKey: key,
EventAt: &eventAt,
Metadata: map[string]any{"watchedMs": watched.Ms, "topTitle": watched.TopTitle},
}
// The floor above is a judgement about the news; this is a judgement about the
// person, and only the second one is worth recording. "You have summaries switched
// off" is the answer to somebody reporting that they never get one, and it is not
// findable anywhere else.
if !s.watchTimeDigestWanted(ctx, account.ID) {
s.declineUser(ctx, notification, "this viewer has watch-time summaries switched off")
continue
}
sent++
if s.notifyUser(ctx, notification) {
sent++
}
}
if sent > 0 {
s.log.Info("weekly watch-time summaries sent", "viewers", sent, "week", weekKey(now, location))
@@ -183,18 +196,25 @@ func (s *Server) sendMonthlyWatchTime(
if total < watchTimeDigestFloor {
continue
}
if !s.watchTimeDigestWanted(ctx, account.ID) {
continue
}
message := monthlyDigestMessage(total, monthName, watched.TopTitle)
if err := s.store.UpsertNotification(
ctx, account.ID, key, watchTimeMonthlyKind,
"", monthName+" in Memby", message, &eventAt,
); err != nil {
s.log.Warn("monthly watch-time summary failed", "user", account.ID, "error", err)
notification := notify.Notification{
Kind: watchTimeMonthlyKind,
Source: notifySourceWatchTime,
UserID: account.ID,
Username: account.Username,
Title: monthName + " in Memby",
Body: message,
SourceKey: key,
EventAt: &eventAt,
Metadata: map[string]any{"watchedMs": watched.Ms, "topTitle": watched.TopTitle, "month": monthID},
}
if !s.watchTimeDigestWanted(ctx, account.ID) {
s.declineUser(ctx, notification, "this viewer has watch-time summaries switched off")
continue
}
sent++
if s.notifyUser(ctx, notification) {
sent++
}
}
if sent > 0 {
s.log.Info("monthly watch-time summaries sent", "viewers", sent, "month", monthID)