3. Versuch bug fix FCM mit mehr Info im UI
This commit is contained in:
1 parent
df97539f27
commit
84aa7f9631
10 files changed
+178
-36
No files matched your search
+52
-13
@@ -233,9 +233,35 @@ def upsert_push_token(tenant_id, client_id, account_id, token, client_type,
|
||||
verschoben, statt ein zweites Token anzulegen. Ältere Tokens derselben
|
||||
Client-ID werden entfernt, damit nach einer Token-Rotation keine doppelten
|
||||
Wake-Signale entstehen.
|
||||
|
||||
Fehlt zur Client-ID noch ein ``ws_clients``-Eintrag (z. B. weil die
|
||||
Registrierung erfolgte, bevor die WebSocket-Verbindung stand), wird ein
|
||||
Platzhalter angelegt. Nur so erscheint das Token später als Wake-Kandidat
|
||||
und die Drosselung über ``last_wake_at`` greift. Der Platzhalter gilt als
|
||||
getrennt; eine echte WebSocket-Verbindung setzt den Status zurück.
|
||||
"""
|
||||
db = get_db()
|
||||
current = now()
|
||||
|
||||
client_row = get_client(tenant_id, client_id)
|
||||
if client_row is None:
|
||||
db.execute(
|
||||
'''INSERT OR IGNORE INTO ws_clients
|
||||
(tenant_id, client_id, account_id, client_type, worker_id,
|
||||
connected_at, disconnected_at, authenticated, last_seq)
|
||||
VALUES (?, ?, ?, ?, NULL, ?, ?, 0, 0)''',
|
||||
(tenant_id, client_id, account_id, client_type, current, current)
|
||||
)
|
||||
elif client_row['account_id'] != account_id:
|
||||
# Ein Token darf keine fremde Client-ID übernehmen.
|
||||
return False
|
||||
elif not client_row['client_type'] and client_type:
|
||||
db.execute(
|
||||
'UPDATE ws_clients SET client_type = ? '
|
||||
'WHERE tenant_id = ? AND client_id = ? AND client_type IS NULL',
|
||||
(client_type, tenant_id, client_id)
|
||||
)
|
||||
|
||||
db.execute(
|
||||
'DELETE FROM ws_push_tokens '
|
||||
'WHERE tenant_id = ? AND client_id = ? AND token <> ?',
|
||||
@@ -259,6 +285,7 @@ def upsert_push_token(tenant_id, client_id, account_id, token, client_type,
|
||||
platform, 1 if auto_position else 0, current, current)
|
||||
)
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
|
||||
def delete_push_token(tenant_id, token=None, client_id=None, account_id=None):
|
||||
@@ -363,22 +390,31 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
||||
re_wake_before=None, group_id=None,
|
||||
auto_position_only=False, client_id=None,
|
||||
include_connected=False, limit=500):
|
||||
# Maßgeblich ist das registrierte FCM-Token, nicht ein eventuell fehlender
|
||||
# oder veralteter ws_clients-Eintrag. Früher wurden Kandidaten über einen
|
||||
# INNER JOIN auf ws_clients ermittelt. Existierte dort kein Eintrag (z. B.
|
||||
# weil die Registrierung ohne offene WebSocket-Verbindung erfolgte), wurde
|
||||
# trotz gültigem Token kein Empfänger gefunden. Der LEFT JOIN erlaubt
|
||||
# solche Tokens ausdrücklich.
|
||||
sql = [
|
||||
'''SELECT c.tenant_id, c.client_id, c.account_id, c.client_type,
|
||||
'''SELECT p.tenant_id, p.client_id, p.account_id, p.client_type,
|
||||
c.disconnected_at, c.last_wake_at, c.last_wake_reason,
|
||||
p.token, p.platform, p.auto_position
|
||||
FROM ws_clients c
|
||||
JOIN ws_push_tokens p
|
||||
ON p.id = (
|
||||
FROM ws_push_tokens p
|
||||
LEFT JOIN ws_clients c
|
||||
ON c.tenant_id = p.tenant_id
|
||||
AND c.client_id = p.client_id
|
||||
WHERE p.tenant_id = ?
|
||||
AND p.invalid = 0
|
||||
AND p.client_type IN ('group_view', 'dispatcher_mobile')
|
||||
AND p.id = (
|
||||
SELECT p2.id FROM ws_push_tokens p2
|
||||
WHERE p2.tenant_id = c.tenant_id
|
||||
AND p2.client_id = c.client_id
|
||||
WHERE p2.tenant_id = p.tenant_id
|
||||
AND p2.client_id = p.client_id
|
||||
AND p2.invalid = 0
|
||||
ORDER BY p2.updated_at DESC, p2.id DESC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE c.tenant_id = ?
|
||||
AND p.client_type IN ('group_view', 'dispatcher_mobile')'''
|
||||
)'''
|
||||
]
|
||||
params = [tenant_id]
|
||||
|
||||
@@ -394,7 +430,7 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
||||
params.append(disconnected_before)
|
||||
|
||||
if client_id is not None:
|
||||
sql.append('AND c.client_id = ?')
|
||||
sql.append('AND p.client_id = ?')
|
||||
params.append(client_id)
|
||||
|
||||
if re_wake_before is not None:
|
||||
@@ -404,14 +440,17 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
||||
params.append(re_wake_before)
|
||||
|
||||
if auto_position_only:
|
||||
sql.append("AND (c.client_type = 'dispatcher_mobile' OR p.auto_position = 1)")
|
||||
sql.append(
|
||||
"AND (p.client_type = 'dispatcher_mobile' "
|
||||
'OR p.auto_position = 1)'
|
||||
)
|
||||
|
||||
if group_id is not None:
|
||||
sql.append(
|
||||
'''AND EXISTS (
|
||||
SELECT 1 FROM group_accounts ga
|
||||
WHERE ga.tenant_id = c.tenant_id
|
||||
AND ga.account_id = c.account_id
|
||||
WHERE ga.tenant_id = p.tenant_id
|
||||
AND ga.account_id = p.account_id
|
||||
AND ga.group_id = ?
|
||||
)'''
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user