Fixed semgrep error
This commit is contained in:
@@ -172,8 +172,55 @@ function dateKeyToGerman(dateKey) {
|
||||
return `${day}.${month}.${year}`
|
||||
}
|
||||
|
||||
function teamSlugsForMatch(match) {
|
||||
return matchTeams(match.row).map(slugify)
|
||||
function matchIdentity(match) {
|
||||
const row = match?.row || {}
|
||||
const explicit = row.BegegnungNr || row.MeetingId || row.meeting_id || row.SpielNr
|
||||
if (explicit) return `id:${explicit}`
|
||||
return [
|
||||
berlinDateKey(match?.date || matchDate(row) || new Date(0)),
|
||||
String(row.Timestamp || ''),
|
||||
...matchTeams(row).map(slugify)
|
||||
].join('|')
|
||||
}
|
||||
|
||||
function uniqueMatches(matches) {
|
||||
const seen = new Set()
|
||||
const unique = []
|
||||
for (const match of matches) {
|
||||
const identity = matchIdentity(match)
|
||||
if (seen.has(identity)) continue
|
||||
seen.add(identity)
|
||||
unique.push(match)
|
||||
}
|
||||
return unique
|
||||
}
|
||||
|
||||
function localTeamSlugForSide(row, side, teamRows) {
|
||||
const clubName = normalizeText(row?.[`${side}VereinName`] || row?.[`${side}Mannschaft`] || '')
|
||||
if (!clubName.includes('harheimer tc')) return []
|
||||
|
||||
const ageClass = String(row?.[`${side}MannschaftAltersklasse`] || row?.Altersklasse || '')
|
||||
const number = String(row?.[`${side}MannschaftNr`] || '1').trim() || '1'
|
||||
const base = /jugend/i.test(ageClass) ? 'Jugend' : 'Erwachsene'
|
||||
const candidate = slugify(`${base} ${number}`)
|
||||
const known = new Set(teamRows.map(row => slugify(row.team)).filter(Boolean))
|
||||
|
||||
if (!known.size || known.has(candidate)) return [candidate]
|
||||
if (/jugend/i.test(ageClass)) {
|
||||
return teamRows
|
||||
.map(row => slugify(row.team))
|
||||
.filter(slug => slug.startsWith('jugend'))
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function teamSlugsForMatch(match, teamRows = []) {
|
||||
const row = match?.row || {}
|
||||
return [...new Set([
|
||||
...matchTeams(row).map(slugify),
|
||||
...localTeamSlugForSide(row, 'Heim', teamRows),
|
||||
...localTeamSlugForSide(row, 'Gast', teamRows)
|
||||
].filter(Boolean))]
|
||||
}
|
||||
|
||||
async function readTeamMembers(season) {
|
||||
@@ -239,17 +286,25 @@ function ownTeamSlugsForUser(user, teamRows) {
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function selectedMatchesForUser(_user, settings, matches) {
|
||||
function selectedMatchesForUser(_user, settings, matches, teamRows = []) {
|
||||
const selected = new Set((settings.selectedTeamSlugs || []).map(slugify))
|
||||
if (selected.size === 0) return []
|
||||
return matches.filter(match => teamSlugsForMatch(match).some(slug => selected.has(slug)))
|
||||
return matches.filter(match => teamSlugsForMatch(match, teamRows).some(slug => selected.has(slug)))
|
||||
}
|
||||
|
||||
function ownMatchesForUser(user, settings, matches, teamRows) {
|
||||
if (settings.ownTeamMatches === false) return []
|
||||
const ownSlugs = new Set(ownTeamSlugsForUser(user, teamRows))
|
||||
if (ownSlugs.size === 0) return []
|
||||
return matches.filter(match => teamSlugsForMatch(match).some(slug => ownSlugs.has(slug)))
|
||||
return matches.filter(match => teamSlugsForMatch(match, teamRows).some(slug => ownSlugs.has(slug)))
|
||||
}
|
||||
|
||||
function matchesForUser(user, settings, context) {
|
||||
if (settings.allTeamMatches) return uniqueMatches(context.allMatches)
|
||||
return uniqueMatches([
|
||||
...selectedMatchesForUser(user, settings, context.allMatches, context.teamRows),
|
||||
...ownMatchesForUser(user, settings, context.allMatches, context.teamRows)
|
||||
])
|
||||
}
|
||||
|
||||
function notificationSeasonForSettings(settings, fallbackSeason) {
|
||||
@@ -309,9 +364,10 @@ async function birthdaysOn(dateKey) {
|
||||
return [...new Set(people.filter(Boolean))].sort((a, b) => a.localeCompare(b, 'de'))
|
||||
}
|
||||
|
||||
async function sendIfDue(state, dateKey, time, category, enabled, send) {
|
||||
async function sendIfDue(state, dateKey, time, category, enabled, send, equivalentCategories = []) {
|
||||
const key = runKey(dateKey, time, category)
|
||||
if (!enabled || state[key]) return null
|
||||
const equivalentKeys = equivalentCategories.map(equivalentCategory => runKey(dateKey, time, equivalentCategory))
|
||||
if (!enabled || state[key] || equivalentKeys.some(equivalentKey => state[equivalentKey])) return null
|
||||
const result = await send()
|
||||
state[key] = { at: new Date().toISOString(), result }
|
||||
return result
|
||||
@@ -363,48 +419,23 @@ export async function runNotificationSchedulerTick(now = new Date()) {
|
||||
failureLabel: 'FCM Termine-morgen-Push'
|
||||
}))
|
||||
|
||||
const allResults = []
|
||||
const selectedResults = []
|
||||
const ownResults = []
|
||||
const teamMatchResults = []
|
||||
for (const [season, context] of Object.entries(matchContexts)) {
|
||||
allResults.push(await sendIfDue(state, dateKey, time, 'allTeamMatches:' + season, context.allMatches.length > 0, () => sendPushToUsers({
|
||||
teamMatchResults.push(await sendIfDue(state, dateKey, time, 'teamMatches:' + season, context.allMatches.length > 0, () => sendPushToUsers({
|
||||
title: 'Punktspiele',
|
||||
body: matchSummary(context.allMatches, 'Es stehen Punktspiele an.'),
|
||||
data: { type: 'team_matches', date: dateKey, season },
|
||||
bodyForUser: (user, settings) => matchSummary(matchesForUser(user, settings, context), 'Es stehen Punktspiele an.'),
|
||||
predicate: (user, settings) => settings.notificationTime === time &&
|
||||
notificationSeasonForSettings(settings, defaultSeason) === season &&
|
||||
settings.allTeamMatches,
|
||||
matchesForUser(user, settings, context).length > 0,
|
||||
failureLabel: 'FCM Punktspiele-Push'
|
||||
})))
|
||||
|
||||
selectedResults.push(await sendIfDue(state, dateKey, time, 'selectedTeamMatches:' + season, context.allMatches.length > 0, () => sendPushToUsers({
|
||||
title: 'Punktspiele deiner Auswahl',
|
||||
body: 'Für eine abonnierte Mannschaft steht ein Punktspiel an.',
|
||||
bodyForUser: (user, settings) => matchSummary(selectedMatchesForUser(user, settings, context.allMatches), 'Für eine abonnierte Mannschaft steht ein Punktspiel an.'),
|
||||
data: { type: 'team_matches', date: dateKey, season },
|
||||
predicate: (user, settings) => settings.notificationTime === time &&
|
||||
notificationSeasonForSettings(settings, defaultSeason) === season &&
|
||||
settings.allTeamMatches === false &&
|
||||
selectedMatchesForUser(user, settings, context.allMatches).length > 0,
|
||||
failureLabel: 'FCM Mannschaftsauswahl-Push'
|
||||
})))
|
||||
|
||||
ownResults.push(await sendIfDue(state, dateKey, time, 'ownTeamMatches:' + season, context.allMatches.length > 0, () => sendPushToUsers({
|
||||
title: 'Punktspiel deiner Mannschaft',
|
||||
body: 'Für deine Mannschaft steht ein Punktspiel an.',
|
||||
bodyForUser: (user, settings) => matchSummary(ownMatchesForUser(user, settings, context.allMatches, context.teamRows), 'Für deine Mannschaft steht ein Punktspiel an.'),
|
||||
data: { type: 'team_matches', date: dateKey, season },
|
||||
predicate: (user, settings) => settings.notificationTime === time &&
|
||||
notificationSeasonForSettings(settings, defaultSeason) === season &&
|
||||
settings.allTeamMatches === false &&
|
||||
selectedMatchesForUser(user, settings, context.allMatches).length === 0 &&
|
||||
ownMatchesForUser(user, settings, context.allMatches, context.teamRows).length > 0,
|
||||
failureLabel: 'FCM eigene-Mannschaft-Push'
|
||||
})))
|
||||
}), ['allTeamMatches:' + season, 'selectedTeamMatches:' + season, 'ownTeamMatches:' + season]))
|
||||
}
|
||||
results.allTeamMatches = allResults.some(Boolean)
|
||||
results.selectedTeamMatches = selectedResults.some(Boolean)
|
||||
results.ownTeamMatches = ownResults.some(Boolean)
|
||||
results.teamMatches = teamMatchResults.some(Boolean)
|
||||
results.allTeamMatches = results.teamMatches
|
||||
results.selectedTeamMatches = results.teamMatches
|
||||
results.ownTeamMatches = results.teamMatches
|
||||
|
||||
results.birthdays = await sendIfDue(state, dateKey, time, 'birthdays', todaysBirthdays.length > 0, () => sendPushToUsers({
|
||||
title: 'Geburtstage heute',
|
||||
|
||||
Reference in New Issue
Block a user