{@inheritdoc}

@param \Flarum\Notification\Notification $notification
@throws InvalidArgumentException
18123
protected function getDefaultAttributes($notification)
    {
        if (! ($notification instanceof Notification)) {
            throw new InvalidArgumentException(
                get_class($this).' can only serialize instances of '.Notification::class
            );
        }

        return [
            'contentType' => $notification->type,
            'content'     => $notification->data,
            'createdAt'   => $this->formatDate($notification->created_at),
            'isRead'      => (bool) $notification->read_at
        ];
    }
798100
public function sendNotification($notification)
    {
        $subscriberIds = $notification->subscriberIds->toArray();
        $query = $this->getService('repos:people.person')
                       ->getQuery(true)
                       ->id($subscriberIds);

        $people = $query->fetchSet();

        $settings = $this->getService('repos:notifications.setting')
                         ->getQuery(true, array('actor.id' => $notification->target->id))
                         ->fetchSet();

        $settings = AnHelperArray::indexBy($settings, 'person.id');

        $mails = $this->_renderMails(array(
                        'notification' => $notification,
                        'people' => $people,
                        'settings' => $settings
                    ));

        $this->mail($mails);
    }
1274147
public function send($notifiable, Notification $notification)
    {
        if (! $userIds = $notifiable->routeNotificationFor('OneSignal', $notification)) {
            return;
        }

        /** @var ResponseInterface $response */
        $response = $this->oneSignal->sendNotificationCustom(
            $this->payload($notifiable, $notification, $userIds)
        );

        if ($response->getStatusCode() !== 200) {
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
        }

        return $response;
    }
617410
public function send(string $recipientID, Notification $notification): void
    {
        $app = App::get();

        if ($notification->id === null) {
            $notification->id = 'n' . uniqid() . 'x' . base_convert(rand(0, 999999999), 10, 16);
        }
        if ($notification->dateCreated === null) {
            $notification->dateCreated = time();
        }

        if ($this->hasEventListeners('beforeSendNotification')) {
            $eventDetails = new \IvoPetkov\BearFrameworkAddons\Notifications\BeforeSendNotificationEventDetails($recipientID, $notification);
            $this->dispatchEvent('beforeSendNotification', $eventDetails);
            if ($eventDetails->preventDefault) {
                return;
            }
        }

        if (strlen($notification->type) > 0) {
            $otherNotifications = $this->getList($recipientID);
            foreach ($otherNotifications as $otherNotification) {
                if ((string) $notification->type === (string) $otherNotification->type) {
                    $this->delete($recipientID, $otherNotification->id);
                }
            }
        }

        $this->set($recipientID, $notification);

        if ($this->hasEventListeners('sendNotification')) {
            $eventDetails = new \IvoPetkov\BearFrameworkAddons\Notifications\SendNotificationEventDetails($recipientID, $notification);
            $this->dispatchEvent('sendNotification', $eventDetails);
        }
    }
320603
public function setMessage(NotificationInterface $notification, $message, $flush = false)
    {
        $notification->setMessage($message);
        $this->flush($flush);

        $event = new NotificationEvent($notification);
        $this->dispatcher->dispatch(MgiletNotificationEvents::MODIFIED, $event);

        return $notification;
    }
284484
private function generateMessage($notification)
    {
        $message = ucfirst($notification['type']) . '\n\n';

        if ( ! is_null($notification['title'])) {
            $message .= $this->escapeTitle($notification['title']) . '\n\n';
        }

        return $this->escapeMessage($message . $notification['message']);
    }
27384
protected function runNotificationListener(string $event, array $notification)
    {
        app('events')->listen($event, function(array $variables = null, array $recipients = null) use($notification) {
            $this->eventDispatcher->run($notification, $variables, $recipients);
        });
    }
987185
public function send($notifiable, Notification $notification)
    {
        if (! $pushoverReceiver = $notifiable->routeNotificationFor('pushover')) {
            return;
        }

        if (is_string($pushoverReceiver)) {
            $pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver);
        }

        $message = $notification->toPushover($notifiable);

        try {
            $this->pushover->send(array_merge($message->toArray(), $pushoverReceiver->toArray()));
        } catch (ServiceCommunicationError $serviceCommunicationError) {
            $this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage());
        }
    }
131453
public function setNotification($notification = '')
    {
        if ('' == $notification) {
            $notification = 'General Notification';
        }

        if (!is_string($notification)) {
            throw new BuildException(
                '"notification" attribute is invalid.' .
                ' Expect to be a string, actual is ' . gettype($notification)
            );
        }

        $this->notification = $notification;
    }
1100729
public function withNotification($notification)
    {
        $notification = $notification instanceof Notification
            ? $notification
            : Notification::fromArray((array) $notification);

        $message = clone $this;
        $message->notification = $notification;

        return $message;
    }
897862
protected function isValidNotificationType(string $notificationType): void
    {
        $allowedNotificationType = $this->getAllowedNotificationType();
        if (!\in_array($notificationType, $allowedNotificationType, true)) {
            throw new InvalidTypeException(sprintf(
                'notificationType must be either "%s".',
                implode(', ', $allowedNotificationType)
            ));
        }
    }
1243875
public function send($notifiable, Notification $notification)
    {
        $message = $notification->toFacebook($notifiable);

        if (is_string($message)) {
            $message = FacebookMessage::create($message);
        }

        if ($message->toNotGiven()) {
            if (! $to = $notifiable->routeNotificationFor('facebook')) {
                throw CouldNotCreateMessage::recipientNotProvided();
            }

            $message->to($to);
        }

        $this->fb->send($message->toArray());
    }
953740
public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }

        $message = $notification->toNexmo($notifiable);

        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }

        $this->nexmo->message()->send([
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
        ]);
    }
577744
public function handle(NotificationInterface $notification, $level)
    {
        return $this->logger->log($level, $notification->message());
    }
344351
protected function queueNotification($notifiables, $notification)
    {
        $notifiables = $this->formatNotifiables($notifiables);

        $original = clone $notification;

        foreach ($notifiables as $notifiable) {
            $notificationId = Str::uuid()->toString();

            foreach ((array) $original->via($notifiable) as $channel) {
                $notification = clone $original;

                $notification->id = $notificationId;

                if (! is_null($this->locale)) {
                    $notification->locale = $this->locale;
                }

                $this->bus->dispatch(
                    (new SendQueuedNotifications($notifiable, $notification, [$channel]))
                            ->onConnection($notification->connection)
                            ->onQueue($notification->queue)
                            ->delay($notification->delay)
                );
            }
        }
    }
415507
public function push(Notification $notification)
    {
        /**
         * Init curl, execute and close
         */
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, self::ENDPOINT);
        curl_setopt($curl, CURLOPT_USERAGENT, self::USER_AGENT);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $this->createPostFields($notification));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        curl_exec($curl);
        $info = curl_getinfo($curl);
        curl_close($curl);

        /**
         * Handle result
         */
        switch ($info['http_code']) {
            case 201:
                return true;

            case 401:
                throw new InvalidAccessTokenException('Not Authorized: Access token not recognized');

            case 404:
                throw new NoDeviceAssociatedException('Not Found: No device associated with provided access token');
        }

        return false;
    }
785795
protected function setNotificationsAsSent(array $notifications)
    {
        foreach ($notifications as $notification) {
            $notification->setSent(new \DateTime());
            $this->managerRegistry->getManager()->persist($notification);
        }
        $this->managerRegistry->getManager()->flush();
    }