Fix FCM token registration and add queue reminder alerts
- Fix silent insert failure in FCM token registration (missing NOT NULL refresh_token column) so WebView app tokens are actually stored - Add 1-minute queue reminder cron that re-sends FCM alerts for calls still waiting, with transient-based throttle to prevent duplicates - Send FCM cancel on queue dequeue (answered/hangup/timeout), not just on final call status webhook - Clean up new cron hook on plugin deactivation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,17 +55,32 @@ class TWP_Mobile_Phone_Page {
|
||||
$user_id, $fcm_token
|
||||
));
|
||||
|
||||
if (!$existing) {
|
||||
if ($existing) {
|
||||
// Refresh the expiry on existing session
|
||||
$wpdb->update($table,
|
||||
array('expires_at' => date('Y-m-d H:i:s', time() + 7 * DAY_IN_SECONDS)),
|
||||
array('id' => $existing->id),
|
||||
array('%s'),
|
||||
array('%d')
|
||||
);
|
||||
} else {
|
||||
$wpdb->insert($table, array(
|
||||
'user_id' => $user_id,
|
||||
'fcm_token' => $fcm_token,
|
||||
'device_info' => 'WebView Mobile App',
|
||||
'is_active' => 1,
|
||||
'created_at' => current_time('mysql'),
|
||||
'expires_at' => date('Y-m-d H:i:s', time() + 7 * DAY_IN_SECONDS),
|
||||
'user_id' => $user_id,
|
||||
'refresh_token' => 'webview-' . wp_generate_password(32, false),
|
||||
'fcm_token' => $fcm_token,
|
||||
'device_info' => 'WebView Mobile App',
|
||||
'is_active' => 1,
|
||||
'created_at' => current_time('mysql'),
|
||||
'expires_at' => date('Y-m-d H:i:s', time() + 7 * DAY_IN_SECONDS),
|
||||
));
|
||||
|
||||
if ($wpdb->last_error) {
|
||||
error_log('TWP FCM: Failed to insert token: ' . $wpdb->last_error);
|
||||
wp_send_json_error('Failed to store token');
|
||||
}
|
||||
}
|
||||
|
||||
error_log("TWP FCM: Token registered for user $user_id");
|
||||
wp_send_json_success('FCM token registered');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user