Skip to content

Commit 7de8dd7

Browse files
authored
min & max lifespan of a message
https://firebase.google.com/docs/cloud-messaging/concept-options#ttl `The value must be a duration from 0 to 2,419,200 seconds (28 days), and it corresponds to the maximum period of time for which FCM stores and attempts to deliver the message`
1 parent 034cff0 commit 7de8dd7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Fcm.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ public function notification(array $notification = [])
4141

4242
return $this;
4343
}
44-
44+
4545
public function timeToLive(int $timeToLive)
4646
{
47+
if ($timeToLive < 0) {
48+
$timeToLive = 0; // (0 seconds)
49+
}
50+
if ($timeToLive > 2419200) {
51+
$timeToLive = 2419200; // (28 days)
52+
}
53+
4754
$this->timeToLive = $timeToLive;
48-
55+
4956
return $this;
5057
}
5158

@@ -65,7 +72,7 @@ public function send()
6572
} else {
6673
$payloads['registration_ids'] = $this->recipients;
6774
}
68-
75+
6976
if ($this->timeToLive !== null && $this->timeToLive >= 0) {
7077
$payloads['time_to_live'] = (int) $this->timeToLive;
7178
}

0 commit comments

Comments
 (0)