diff --git a/src/Conversations/Threads/Thread.php b/src/Conversations/Threads/Thread.php index 15b19d6..8aafe6b 100644 --- a/src/Conversations/Threads/Thread.php +++ b/src/Conversations/Threads/Thread.php @@ -62,6 +62,11 @@ class Thread implements Extractable, Hydratable */ private $assignedTo; + /** + * @var array|null + */ + private $associatedEntities; + /** * @var int|null */ @@ -116,6 +121,7 @@ public function hydrate(array $data, array $embedded = []) if (isset($data['action'])) { $this->actionType = $data['action']['type'] ?? null; $this->actionText = $data['action']['text'] ?? null; + $this->associatedEntities = $data['action']['associatedEntities'] ?? null; } if (isset($data['source']) && is_array($data['source'])) { @@ -192,6 +198,14 @@ public function extract(): array ]; } + if ($this->wasMerged()) { + $data['action'] = [ + 'type' => $this->getActionType(), + 'text' => $this->getActionText(), + 'associatedEntities' => $this->getAssociatedEntities(), + ]; + } + if ($this->wasCreatedByCustomer()) { $data['createdBy'] = [ 'id' => $this->getCreatedByCustomer()->getId(), @@ -265,6 +279,11 @@ public function wasCreatedByAction(): bool return \is_string($this->actionText); } + public function wasMerged(): bool + { + return $this->actionType === 'merged'; + } + public function getActionType(): ?string { return $this->actionType; @@ -297,6 +316,11 @@ public function getAssignedTo(): ?array return $this->assignedTo; } + public function getAssociatedEntities(): ?array + { + return $this->associatedEntities; + } + public function getTo(): ?array { return $this->to; diff --git a/tests/Conversations/Threads/ThreadTest.php b/tests/Conversations/Threads/ThreadTest.php index e69a790..5adf532 100644 --- a/tests/Conversations/Threads/ThreadTest.php +++ b/tests/Conversations/Threads/ThreadTest.php @@ -93,6 +93,28 @@ public function testHydrate() $this->assertTrue($thread->isImported()); } + public function testHydrateAssociatedEntities() + { + $thread = new Thread(); + $thread->hydrate([ + 'id' => 12, + 'type' => 'lineitem', + 'action' => [ + 'type' => 'merged', + 'text' => 'You merged threads from another conversation', + 'associatedEntities' => $associatedEntities = [ + 'originalConversation' => '12345', + ], + ] + ]); + + $this->assertSame(12, $thread->getId()); + $this->assertSame('lineitem', $thread->getType()); + $this->assertSame('merged', $thread->getActionType()); + $this->assertSame('You merged threads from another conversation', $thread->getActionText()); + $this->assertSame($associatedEntities, $thread->getAssociatedEntities()); + } + public function testHydrateTextFromBody() { $thread = new Thread();