Fixed some problems
All checks were successful
Code Analysis and Production Deploy / analyze (push) Successful in 6m38s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Successful in 2m37s

This commit is contained in:
Torsten Schulz (local)
2026-06-12 11:42:22 +02:00
parent da1efa5a74
commit 44d441811c
3 changed files with 21 additions and 5 deletions

View File

@@ -73,7 +73,7 @@ object HarheimerNotifications {
private fun destinationRoute(data: Map<String, String>): String = when (data["type"]) {
"news" -> Destinations.MemberNews.route
"event", "events_today", "events_tomorrow" -> Destinations.Termine.route
"event", "events_today", "events_tomorrow", "news_expiring" -> Destinations.Termine.route
"team_matches" -> Destinations.Spielplan.route
"birthdays" -> Destinations.MemberArea.route
"contact_request" -> Destinations.CmsContactRequests.route

View File

@@ -69,7 +69,7 @@ function userDisplayName(user) {
function hasTimedSettings(user) {
const settings = notificationSettingsForUser(user)
return settings.eventsToday || settings.eventsTomorrow || settings.ownTeamMatches ||
return settings.newNews || settings.eventsToday || settings.eventsTomorrow || settings.ownTeamMatches ||
settings.allTeamMatches || settings.selectedTeamSlugs.length > 0 || settings.birthdays
}
@@ -126,6 +126,11 @@ function expiringNewsOn(news, dateKey) {
.map(entry => ({ title: entry.item.title, source: 'news', item: entry.item }))
}
function formatNewsExpirySummary(news, fallback) {
if (news.length === 1) return String(news[0].title || fallback).slice(0, 140)
return `${news.length} News laufen heute ab: ${news.slice(0, 3).map(item => item.title).filter(Boolean).join(', ')}`.slice(0, 140)
}
function formatEventSummary(events, fallback) {
if (events.length === 1) return String(events[0].title || fallback).slice(0, 140)
return `${events.length} Einträge: ${events.slice(0, 3).map(event => event.title).filter(Boolean).join(', ')}`.slice(0, 140)
@@ -285,8 +290,11 @@ export async function runNotificationSchedulerTick(now = new Date()) {
const tomorrowKey = berlinDateKey(addDays(now, 1))
const [termine, news, season] = await Promise.all([readTermine(), readNews(), getDefaultSpielplanSeason()])
const [spielplan, teamRows] = await Promise.all([readSpielplanData({ season }), readTeamMembers(season)])
const todayEvents = [...eventsOn(termine, dateKey), ...expiringNewsOn(news, dateKey)]
const tomorrowEvents = [...eventsOn(termine, tomorrowKey), ...expiringNewsOn(news, tomorrowKey)]
const todayTermine = eventsOn(termine, dateKey)
const tomorrowTermine = eventsOn(termine, tomorrowKey)
const expiringNewsToday = expiringNewsOn(news, dateKey)
const todayEvents = [...todayTermine, ...expiringNewsToday]
const tomorrowEvents = tomorrowTermine
const todayMatches = matchesOn(spielplan.data || [], dateKey)
const tomorrowMatches = matchesOn(spielplan.data || [], tomorrowKey)
const todaysBirthdays = await birthdaysOn(dateKey)
@@ -301,6 +309,14 @@ export async function runNotificationSchedulerTick(now = new Date()) {
failureLabel: 'FCM Termine-heute-Push'
}))
results.expiringNews = await sendIfDue(state, dateKey, time, 'expiringNews', expiringNewsToday.length > 0, () => sendPushToUsers({
title: 'News laufen heute ab',
body: formatNewsExpirySummary(expiringNewsToday, 'Heute laufen News ab.'),
data: { type: 'news_expiring', date: dateKey },
predicate: (_user, settings) => settings.notificationTime === time && settings.newNews && !settings.eventsToday,
failureLabel: 'FCM News-Ablauf-Push'
}))
results.eventsTomorrow = await sendIfDue(state, dateKey, time, 'eventsTomorrow', tomorrowEvents.length > 0, () => sendPushToUsers({
title: 'Termine morgen',
body: formatEventSummary(tomorrowEvents, 'Morgen stehen Termine an.'),

View File

@@ -182,7 +182,7 @@ export async function sendPushToUsers({ title, body, data = {}, predicate, failu
validTokens.push(entry)
} catch (error) {
failed += 1
console.error(`${failureLabel} fehlgeschlagen:`, error.message)
console.error('FCM Push fehlgeschlagen:', { failureLabel, message: error.message })
if (!/UNREGISTERED|NOT_FOUND|INVALID_ARGUMENT/.test(String(error.message))) {
validTokens.push(entry)
} else {