Skip to content

Commit

Permalink
Merge pull request #32 from NWN-Software/feature/add-metadata
Browse files Browse the repository at this point in the history
Feature/add metadata
  • Loading branch information
rupadana authored Jun 21, 2024
2 parents 0932fdf + be36cdf commit 47c3d6c
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,43 @@ class Announce extends Notification

protected Alignment | string | Closure | null $bodyAlignment = null;

protected array | null $metadata = null;

public function announceTo(Model | Authenticatable | Collection | array $users): void
{
if (! $this->getColor()) {
if (!$this->getColor()) {
$this->color(app(FilamentAnnounce::class)->getColor());
}

if (! is_iterable($users)) {
if (!is_iterable($users)) {
$users = [$users];
}

foreach ($users as $user) {
$notification = new AnnounceNotification($this->getDatabaseMessage());
$data = $this->getDatabaseMessage();

if ($this->metadata) {
$data['metadata'] = $this->metadata;
}

$notification = new AnnounceNotification($data);

$user->notify($notification);
}
}

public function metadata(array $metadata): static
{
if (count($metadata) > 0) {
$this->metadata = $metadata;
}

return $this;
}

public function disableCloseButton(bool | Closure $condition = true): static
{
$this->closeButton = ! $condition;
$this->closeButton = !$condition;

return $this;
}
Expand Down Expand Up @@ -73,7 +90,7 @@ public static function fromArray(array $data): static
{
$static = parent::fromArray($data);

$static->disableCloseButton(! $data['closeButton']);
$static->disableCloseButton(!$data['closeButton']);
$static->titleAlignment($data['titleAlignment'] ?? null);
$static->bodyAlignment($data['bodyAlignment'] ?? null);

Expand Down

0 comments on commit 47c3d6c

Please sign in to comment.