Füge Unterstützung für die Installation-ID in Push-Token-Registrierung hinzu: Aktualisiere API- und Datenbank-Logik zur Speicherung der Installation-ID.
This commit is contained in:
@@ -85,16 +85,21 @@ function pushTokensForUser(user) {
|
||||
: []
|
||||
}
|
||||
|
||||
export function upsertPushToken(user, { token, platform = 'android', appVersion = null }) {
|
||||
export function upsertPushToken(user, { token, platform = 'android', appVersion = null, installationId = null }) {
|
||||
const normalizedToken = String(token || '').trim()
|
||||
if (!normalizedToken) return user
|
||||
const normalizedInstallationId = String(installationId || '').trim().slice(0, 200) || null
|
||||
const now = new Date().toISOString()
|
||||
const tokens = Array.isArray(user.pushTokens) ? user.pushTokens : []
|
||||
const next = tokens.filter(entry => entry?.token !== normalizedToken)
|
||||
// A Firebase token can rotate for the same app installation. Retain tokens
|
||||
// from other devices, but replace the previous token of this installation.
|
||||
const next = tokens.filter(entry => entry?.token !== normalizedToken &&
|
||||
(!normalizedInstallationId || entry?.installationId !== normalizedInstallationId))
|
||||
next.push({
|
||||
token: normalizedToken,
|
||||
platform: String(platform || 'android').slice(0, 30),
|
||||
appVersion: appVersion ? String(appVersion).slice(0, 80) : null,
|
||||
installationId: normalizedInstallationId,
|
||||
updatedAt: now,
|
||||
createdAt: tokens.find(entry => entry?.token === normalizedToken)?.createdAt || now
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user