-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for "filter" to conversation menu/multi-menu
Also improves Element::fromJson with exception throwing
- Loading branch information
1 parent
6e1f7ee
commit eed9f7f
Showing
9 changed files
with
336 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jeremeamia\Slack\BlockKit\Partials; | ||
|
||
use Jeremeamia\Slack\BlockKit\{Element, Exception, HydrationData}; | ||
|
||
class Filter extends Element | ||
{ | ||
private const CONVERSATION_TYPE_IM = 'im'; | ||
private const CONVERSATION_TYPE_MPIM = 'mpim'; | ||
private const CONVERSATION_TYPE_PRIVATE = 'private'; | ||
private const CONVERSATION_TYPE_PUBLIC = 'public'; | ||
|
||
/** @var string[]|array */ | ||
private $include = []; | ||
|
||
/** @var bool */ | ||
private $excludeExternalSharedChannels; | ||
|
||
/** @var bool */ | ||
private $excludeBotUsers; | ||
|
||
/** | ||
* @param string $conversationType | ||
* @return static | ||
*/ | ||
public function includeType(string $conversationType): self | ||
{ | ||
$this->include[] = $conversationType; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string[] $conversationTypes | ||
* @return static | ||
*/ | ||
public function includeTypes(array $conversationTypes): self | ||
{ | ||
$this->include = $conversationTypes; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function includeIm(): self | ||
{ | ||
return $this->includeType(self::CONVERSATION_TYPE_IM); | ||
} | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function includeMpim(): self | ||
{ | ||
return $this->includeType(self::CONVERSATION_TYPE_MPIM); | ||
} | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function includePrivate(): self | ||
{ | ||
return $this->includeType(self::CONVERSATION_TYPE_PRIVATE); | ||
} | ||
|
||
/** | ||
* @return static | ||
*/ | ||
public function includePublic(): self | ||
{ | ||
return $this->includeType(self::CONVERSATION_TYPE_PUBLIC); | ||
} | ||
|
||
/** | ||
* @param bool $excludeBotUsers | ||
* @return static | ||
*/ | ||
public function excludeBotUsers(bool $excludeBotUsers): self | ||
{ | ||
$this->excludeBotUsers = $excludeBotUsers; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param bool $excludeExternalSharedChannels | ||
* @return static | ||
*/ | ||
public function excludeExternalSharedChannels(bool $excludeExternalSharedChannels): self | ||
{ | ||
$this->excludeExternalSharedChannels = $excludeExternalSharedChannels; | ||
|
||
return $this; | ||
} | ||
|
||
public function validate(): void | ||
{ | ||
if (empty($this->include) && !isset($this->excludeExternalSharedChannels) && !isset($this->excludeBotUsers)) { | ||
throw new Exception('Filter must have at least one property set'); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
$data = parent::toArray(); | ||
|
||
if (!empty($this->include)) { | ||
$data['include'] = $this->include; | ||
} | ||
|
||
if (isset($this->excludeExternalSharedChannels)) { | ||
$data['exclude_external_shared_channels'] = $this->excludeExternalSharedChannels; | ||
} | ||
|
||
if (isset($this->excludeBotUsers)) { | ||
$data['exclude_bot_users'] = $this->excludeBotUsers; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
protected function hydrate(HydrationData $data): void | ||
{ | ||
if ($data->has('include')) { | ||
$this->includeTypes($data->useArray('include')); | ||
} | ||
|
||
if ($data->has('exclude_external_shared_channels')) { | ||
$this->excludeExternalSharedChannels($data->useValue('exclude_external_shared_channels')); | ||
} | ||
|
||
if ($data->has('exclude_bot_users')) { | ||
$this->excludeBotUsers($data->useValue('exclude_bot_users')); | ||
} | ||
|
||
parent::hydrate($data); | ||
} | ||
} |
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
Oops, something went wrong.