Only include recently active sessions when sending FCM notifications #799
This commit is contained in:
parent
0800fc1066
commit
97ebaa05a0
1 changed files with 15 additions and 1 deletions
|
|
@ -12,6 +12,8 @@ use App\Entity\JobOrder;
|
||||||
use App\Entity\Subscription;
|
use App\Entity\Subscription;
|
||||||
use Exception;
|
use Exception;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use DateTime;
|
||||||
|
use DateInterval;
|
||||||
|
|
||||||
class FCMSender
|
class FCMSender
|
||||||
{
|
{
|
||||||
|
|
@ -246,11 +248,23 @@ class FCMSender
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get device timestamp cutoff
|
||||||
|
$oldest_timestamp = (new DateTime())->sub(new DateInterval('P1M'));
|
||||||
|
|
||||||
// send to every customer session
|
// send to every customer session
|
||||||
foreach ($sessions as $sess) {
|
foreach ($sessions as $sess) {
|
||||||
$device_id = $sess->getDevicePushID();
|
$device_id = $sess->getDevicePushID();
|
||||||
|
|
||||||
if (!empty($device_id) && !isset($device_ids[$device_id])) {
|
// ignore duplicates and empty device IDs
|
||||||
|
if (empty($device_id) || isset($device_ids[$device_id])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get latest device timestamp
|
||||||
|
$latest_timestamp = $sess->getDateLatestActivity();
|
||||||
|
|
||||||
|
// make sure we only send to devices that have been active on or after the cutoff
|
||||||
|
if ($latest_timestamp >= $oldest_timestamp) {
|
||||||
// send to this device
|
// send to this device
|
||||||
$device_ids[$device_id] = true;
|
$device_ids[$device_id] = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue