Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function __construct(
) {
}

public function setOutput(OutputInterface $output): void {
$this->push->setOutput($output);
public function setOutput(OutputInterface $output, bool $limitedOutput = true): void {
$this->push->setOutput($output, $limitedOutput);
}

#[\Override]
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/TestPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function sendNotification(OutputInterface $output, IUser $user, string
->setObject('admin_notifications', dechex($datetime->getTimestamp()))
->setSubject('cli', ['Testing push notifications']);

$this->app->setOutput($output);
$this->app->setOutput($output, false);
$this->notificationManager->notify($notification);
} catch (\InvalidArgumentException) {
$output->writeln('Error while sending the notification');
Expand Down
20 changes: 13 additions & 7 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
class Push {
protected ICache $cache;
protected ?OutputInterface $output = null;
protected bool $limitedOutput = true;

/**
* @psalm-var array<string, list<string>>
*/
Expand Down Expand Up @@ -89,13 +91,17 @@ public function __construct(
$this->cache = $cacheFactory->createDistributed('pushtokens');
}

public function setOutput(OutputInterface $output): void {
public function setOutput(OutputInterface $output, bool $limitedOutput = true): void {
$this->output = $output;
$this->limitedOutput = $limitedOutput;
}

protected function printInfo(string $message): void {
protected function printInfo(string $message, string $verboseMessage = ''): void {
if ($this->output) {
$this->output->writeln($message);
if ($verboseMessage !== '' && !$this->limitedOutput) {
$this->output->writeln($verboseMessage);
}
}
}

Expand Down Expand Up @@ -196,7 +202,7 @@ public function filterDeviceList(array $devices, string $app): array {
return $talkDevices;
}

public function pushToDevice(int $id, INotification $notification, ?OutputInterface $output = null): void {
public function pushToDevice(int $id, INotification $notification): void {
if (!$this->config->getSystemValueBool('has_internet_connection', true)) {
$this->printInfo('<error>Internet connectivity is disabled in configuration file - no push notifications will be sent</error>');

Expand Down Expand Up @@ -485,15 +491,15 @@ protected function sendNotificationsToProxies(): void {
'app' => 'notifications',
]);

$this->printInfo('<error>Could not send notification to push server [' . $proxyServer . ']: ' . $error . '</error>');
$this->printInfo('<error>Could not send notification to push server [' . $proxyServer . ']</error>', '<error>' . $error . '</error>');
continue;
} catch (\Exception $e) {
$this->log->error($e->getMessage(), [
'exception' => $e,
]);

$error = $e->getMessage() ?: 'no reason given';
$this->printInfo('<error>Could not send notification to push server [' . $e::class . ']: ' . $error . '</error>');
$this->printInfo('<error>Could not send notification to push server [' . $e::class . ']</error>', '<error>' . $error . '</error>');
continue;
}

Expand All @@ -516,15 +522,15 @@ protected function sendNotificationsToProxies(): void {
$this->config->setAppValue(Application::APP_ID, 'rate_limit_reached', (string)$this->timeFactory->getTime());
}
$error = $body && $bodyData === null ? $body : 'no reason given';
$this->printInfo('<error>Could not send notification to push server [' . $proxyServer . ']: ' . $error . '</error>');
$this->printInfo('<error>Could not send notification to push server [' . $proxyServer . ']</error>', '<error>' . $error . '</error>');
$this->log->warning('Could not send notification to push server [{url}]: {error}', [
'error' => $error,
'url' => $proxyServer,
'app' => 'notifications',
]);
} else {
$error = $body && $bodyData === null ? $body : 'no reason given';
$this->printInfo('<comment>Push notification sent but response was not parsable, using an outdated push proxy? [' . $proxyServer . ']: ' . $error . '</comment>');
$this->printInfo('<comment>Push notification sent but response was not parsable, using an outdated push proxy? [' . $proxyServer . ']</comment>', '<comment>' . $error . '</comment>');
$this->log->info('Push notification sent but response was not parsable, using an outdated push proxy? [{url}]: {error}', [
'error' => $error,
'url' => $proxyServer,
Expand Down
Loading