fix: emails sending despite online status

Closes #140
This commit is contained in:
talksik
2026-04-09 16:30:07 -07:00
parent 66aec4478f
commit 762c0ccf6e
7 changed files with 432 additions and 123 deletions
+9 -11
View File
@@ -26,7 +26,7 @@ const (
// Minimum time a message must be unread before we consider notifying
unreadThreshold = 10 * time.Minute
// Minimum time between emails to the same user
emailCooldown = 1 * time.Hour
emailCooldown = 12 * time.Hour
)
func main() {
@@ -107,17 +107,15 @@ func runNotificationCycle(
behindCounts := map[string]int{}
latestActivity := map[string]time.Time{}
// Get all currently connected humans (empty channel_ids = all connections)
// Get all currently connected humans
allOnline := map[string]bool{}
presenceResp, err := pusherSvc.BulkGetPresence(ctx, &pbpusher.BulkGetPresenceRequest{})
onlineResp, err := pusherSvc.GetOnlineHumanIds(ctx, &pbpusher.GetOnlineHumanIdsRequest{})
if err != nil {
slog.Error("failed to get connected humans", "error", err)
// Continue without presence data — worst case we send an email to someone who's online
} else if ch, ok := presenceResp.Presences["_all"]; ok {
slog.Info("gathered bulk presence", "# of humans present", fmt.Sprintf("%d", len(ch.HumanIds)))
for _, id := range ch.HumanIds {
allOnline[id] = true
}
return fmt.Errorf("failed to get online humans: %w", err)
}
slog.Info("gathered online presence", "onlineCount", len(onlineResp.HumanIds), "humanIds", onlineResp.HumanIds)
for _, id := range onlineResp.HumanIds {
allOnline[id] = true
}
for _, net := range networks {
@@ -288,7 +286,7 @@ func buildEmailHTML(name string, count int, streamsWord string) string {
<p>You have unread messages in <strong>%d %s</strong> on Flowy.llink.</p>
<p>Open the app to catch up with your team.</p>
<p style="color: #666; font-size: 13px; margin-top: 32px;">
Best,<br>Flowy Team
Best,<br>Flowy Team <br>Note: disable email notifications from in-app settings.
</p>
</body>
</html>`, name, count, streamsWord)