Skip to content

Commit

Permalink
Merge pull request #162 from jolamar/feature/live-activities
Browse files Browse the repository at this point in the history
Add keys that support live activities
  • Loading branch information
edamov authored Feb 15, 2023
2 parents 728157d + 645b462 commit 208f5e9
Showing 1 changed file with 178 additions and 1 deletion.
179 changes: 178 additions & 1 deletion src/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Payload implements \JsonSerializable
const PAYLOAD_CATEGORY_KEY = 'category';
const PAYLOAD_THREAD_ID_KEY = 'thread-id';
const PAYLOAD_URL_ARGS_KEY = 'url-args';
const PAYLOAD_TIMESTAMP_KEY = 'timestamp';
const PAYLOAD_EVENT_KEY = 'event';
const PAYLOAD_RELEVANCE_SCORE_KEY = 'relevance-score';
const PAYLOAD_STALE_DATE_KEY = 'stale-date';
const PAYLOAD_CONTENT_STATE_KEY = 'content-state';

const PAYLOAD_HTTP2_REGULAR_NOTIFICATION_MAXIMUM_SIZE = 4096;
const PAYLOAD_HTTP2_VOIP_NOTIFICATION_MAXIMUM_SIZE = 5120;
Expand Down Expand Up @@ -128,6 +133,42 @@ class Payload implements \JsonSerializable
*/
private $pushType;

/**
* Relevance score
*
* @var double
*/
private $relevanceScore;

/**
* Stale date
*
* @var double
*/
private $staleDate;

/**
* Timestamp
*
* @var double
*/
private $timestamp;

/**
* Event
*
* @var string
*/
private $event;


/**
* Content state
*
* @var array
*/
private $contentState;

protected function __construct()
{
}
Expand Down Expand Up @@ -381,7 +422,7 @@ public function setCustomValue(string $key, $value): Payload

return $this;
}

/**
* Merges custom value for Payload.
*
Expand Down Expand Up @@ -438,6 +479,122 @@ public function getPushType()
return $this->pushType;
}

/**
* Set relevance score for Payload.
*
* @param double $relevanceScore
* @return Payload
*/
public function setRelevanceScore($relevanceScore)
{
$this->relevanceScore = $relevanceScore;

return $this;
}

/**
* Get relevance score for Payload.
*
* @return double
*/
public function getRelevanceScore()
{
return $this->relevanceScore;
}

/**
* Set stale date for Payload.
*
* @param double $staleDate
* @return Payload
*/
public function setStaleDate($staleDate)
{
$this->staleDate = $staleDate;

return $this;
}

/**
* Get stale date for Payload.
*
* @return double
*/
public function getStaleDate()
{
return $this->staleDate;
}

/**
* Set timestamp for Payload.
*
* @param double $timestamp
* @return Payload
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;

return $this;
}

/**
* Get timestamp for Payload.
*
* @return double
*/
public function getTimestamp()
{
return $this->timestamp;
}

/**
* Set content-state for Payload.
*
* @param array $contentState
* @return Payload
*/

public function setContentState($contentState)
{
$this->contentState = $contentState;

return $this;
}

/**
* Get content-state for Payload.
*
* @return array
*/
public function getContentState()
{
return $this->contentState;
}

/**
* Set event for Payload.
*
* @param string $event
* @return Payload
*/
public function setEvent($event)
{
$this->event = $event;

return $this;
}

/**
* Get event for Payload.
*
* @return string
*/
public function getEvent()
{
return $this->event;
}

/**
* Convert Payload to JSON.
*
Expand Down Expand Up @@ -511,6 +668,26 @@ public function jsonSerialize(): array
$payload = array_merge($payload, $this->customValues);
}

if (is_countable($this->contentState) && count($this->contentState)) {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_CONTENT_STATE_KEY} = $this->contentState;
}

if (is_string($this->event)) {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_EVENT_KEY} = $this->event;
}

if (is_double($this->staleDate)) {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_STALE_DATE_KEY} = $this->staleDate;
}

if (is_double($this->timestamp)) {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_TIMESTAMP_KEY} = $this->timestamp;
}

if (is_double($this->relevanceScore)) {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_RELEVANCE_SCORE_KEY} = $this->relevanceScore;
}

return $payload;
}

Expand Down

0 comments on commit 208f5e9

Please sign in to comment.