$recipients Already permission-checked by the caller. * @param array $context Whatever the mail class needs. */ public function queue(string $typeKey, iterable $recipients, string $subjectName, array $context = []): void { $type = $this->types->get($typeKey); if ($type?->digestMail === null) { return; } if ($this->settings->get(Setting::EmailNotificationsEnabled) !== true) { return; } foreach ($recipients as $recipient) { if (! $this->preferences->emailEnabledFor($recipient, $type)) { continue; } PendingNotification::query()->create([ 'user_id' => $recipient->getKey(), 'type' => $type->key, 'subject_name' => $subjectName, 'context' => $context === [] ? null : $context, ]); SendNotificationDigest::dispatch($recipient->getKey(), $type->key) ->delay(now()->addSeconds(self::DEBOUNCE_SECONDS)); } } }