From 2842c89befc84845e8caf22fabfbedffcc247d42 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 11 Sep 2026 15:07:30 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20Unterst=C3=BCtzung=20f=C3=BCr=20QTT?= =?UTF-8?q?R-Listenaktualisierungen=20hinzu:=20Implementiere=20Push-Benach?= =?UTF-8?q?richtigung=20f=C3=BCr=20aktualisierte=20QTTR-Listen=20und=20ver?= =?UTF-8?q?bessere=20die=20Importlogik.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notifications/HarheimerNotifications.kt | 1 + server/utils/push-notifications.js | 13 +++++++++++++ server/utils/qttr-import.js | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/android-app/app/src/main/java/de/harheimertc/notifications/HarheimerNotifications.kt b/android-app/app/src/main/java/de/harheimertc/notifications/HarheimerNotifications.kt index 634d79d..18c6762 100755 --- a/android-app/app/src/main/java/de/harheimertc/notifications/HarheimerNotifications.kt +++ b/android-app/app/src/main/java/de/harheimertc/notifications/HarheimerNotifications.kt @@ -81,6 +81,7 @@ object HarheimerNotifications { "news", "news_expiring" -> Destinations.MemberNews.route "event", "events_today", "events_tomorrow" -> Destinations.Termine.route "team_matches" -> Destinations.Spielplan.route + "qttr_list_updated", "ttr_change" -> Destinations.Qttr.route "birthdays" -> Destinations.MemberArea.route "contact_request" -> Destinations.CmsContactRequests.route "user_registration" -> Destinations.CmsBenutzer.route diff --git a/server/utils/push-notifications.js b/server/utils/push-notifications.js index 56137c7..67b4c30 100755 --- a/server/utils/push-notifications.js +++ b/server/utils/push-notifications.js @@ -334,6 +334,19 @@ export async function sendOwnTtrChangePush(changes = []) { }) } +export async function sendQttrListUpdatedPush({ importedAt, rowCount }) { + return sendPushToUsers({ + title: 'QTTR-Liste aktualisiert', + body: `Die aktuelle TTR- und QTTR-Liste wurde aktualisiert (${rowCount} Einträge).`, + data: { + type: 'qttr_list_updated', + importedAt: importedAt || '', + notificationId: notificationIdFor(`qttr-list:${importedAt || Date.now()}`) + }, + failureLabel: 'FCM QTTR-Listen-Push' + }) +} + export async function sendTestPushToUser(userId) { return sendPushToUsers({ title: 'Harheimer TC: Push-Test', diff --git a/server/utils/qttr-import.js b/server/utils/qttr-import.js index 92a0d19..96ee9ab 100755 --- a/server/utils/qttr-import.js +++ b/server/utils/qttr-import.js @@ -1,6 +1,6 @@ import { promises as fs } from 'fs' import { getServerDataPath } from './paths.js' -import { sendOwnTtrChangePush } from './push-notifications.js' +import { sendOwnTtrChangePush, sendQttrListUpdatedPush } from './push-notifications.js' import { fetchClubRankings } from './mytischtennis-client.js' import { readMyTischtennisConnection, saveMyTischtennisConnection } from './mytischtennis-connection.js' @@ -244,6 +244,8 @@ async function importAuthenticatedTtrValues(connection) { }).filter(row => row.playerName && (row.currentTtr != null || row.currentQttr != null)) if (!rows.length) throw new Error('Keine verwertbaren TTR-Werte in der myTischtennis-Rangliste gefunden.') + const previousQttrSignature = qttrListSignature(previousPayload.rows) + const nextQttrSignature = qttrListSignature(rows) const importedAt = new Date().toISOString() const payload = { format: 'harheimertc.qttr.v2', importedAt, @@ -262,6 +264,21 @@ async function importAuthenticatedTtrValues(connection) { : [] }) await sendOwnTtrChangePush(changes) + if (previousQttrSignature && previousQttrSignature !== nextQttrSignature) { + await sendQttrListUpdatedPush({ importedAt, rowCount: rows.length }) + } await saveMyTischtennisConnection({ ...connection, lastSuccessfulImportAt: importedAt, lastImportError: null }) return { outputFile: OUTPUT_FILE, tableCount: 1, ...payload } } + +function qttrListSignature(rows) { + if (!Array.isArray(rows) || rows.length === 0) return '' + return rows + .map(row => [ + String(row?.playerName || '').trim().toLocaleLowerCase('de-DE'), + row?.rank ?? '', + row?.currentQttr ?? '' + ].join('|')) + .sort() + .join('\n') +}