-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from wotta/add-missing-embed-threads-option-f…
…or-conversation-filters feat(conversations): Added "missing" functionality to get truncated threads
- Loading branch information
Showing
4 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,15 @@ public static function getConversation(int $id): string | |
return json_encode(static::conversation($id)); | ||
} | ||
|
||
public static function getConversations(int $pageNumber, int $totalElements): string | ||
public static function getConversations(int $pageNumber, int $totalElements, bool $embedThread = false): string | ||
{ | ||
$pageSize = 10; | ||
$pageElements = min($totalElements, $pageSize); | ||
$totalPages = ceil($totalElements / $pageSize); | ||
|
||
// Create embedded resources | ||
$conversations = array_map(function ($id) { | ||
return static::conversation($id); | ||
$conversations = array_map(function ($id) use ($embedThread) { | ||
return static::conversation($id, $embedThread); | ||
}, range(1, $pageElements)); | ||
|
||
$data = [ | ||
|
@@ -60,9 +60,9 @@ public static function getConversations(int $pageNumber, int $totalElements): st | |
return json_encode($data); | ||
} | ||
|
||
private static function conversation(int $id): array | ||
private static function conversation(int $id, bool $embedThread = false): array | ||
{ | ||
return [ | ||
$conversation = [ | ||
'id' => $id, | ||
'number' => 15473, | ||
'threads' => 2, | ||
|
@@ -144,6 +144,61 @@ private static function conversation(int $id): array | |
], | ||
], | ||
]; | ||
|
||
if ($embedThread) { | ||
$conversation['_embedded']['threads'] = [ | ||
[ | ||
'id' => 1, | ||
'type' => 'customer', | ||
'status' => 'active', | ||
'state' => 'published', | ||
'action' => [ | ||
'type' => 'default', | ||
'associatedEntities' => [], | ||
], | ||
'body' => 'This is a test', | ||
'source' => [ | ||
'type' => 'email', | ||
'via' => 'user', | ||
], | ||
'customer' => [ | ||
'id' => 472611182, | ||
'first' => 'John', | ||
'last' => 'Doe', | ||
'photoUrl' => 'https://d33v4339jhl8k0.cloudfront.net/customer-avatar/05.png', | ||
'email' => '[email protected]', | ||
], | ||
'createdBy' => [ | ||
'id' => 1, | ||
'type' => 'user', | ||
'first' => 'John', | ||
'last' => 'Doe', | ||
'email' => '[email protected]', | ||
'to' => [], | ||
'cc' => [], | ||
'bcc' => [], | ||
'createdAt' => '2017-04-21T14:39:56Z', | ||
], | ||
'assignedTo' => [ | ||
'id' => 12, | ||
'first' => 'Help', | ||
'last' => 'Scout', | ||
'email' => '[email protected]', | ||
], | ||
'savedReplyId' => 0, | ||
'_embedded' => [ | ||
'attachments' => [], | ||
], | ||
'_links' => [ | ||
'createdByUser' => [ | ||
'href' => 'https://api.helpscout.net/v2/users/1', | ||
] | ||
] | ||
], | ||
]; | ||
} | ||
|
||
return $conversation; | ||
} | ||
|
||
public static function getThreads(int $conversationId): string | ||
|