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
134 changes: 134 additions & 0 deletions lib/FakeUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Notifications;

use OCP\IUser;

class FakeUser implements IUser {
protected string $userId;

public function __construct(string $userId) {
$this->userId = $userId;
}

public function getUID(): string {
return $this->userId;
}

public function getCloudId() {
throw new \RuntimeException('Not implemented');
}

public function getSystemEMailAddress(): ?string {
throw new \RuntimeException('Not implemented');
}

public function getPrimaryEMailAddress(): ?string {
throw new \RuntimeException('Not implemented');
}

public function getDisplayName() {
throw new \RuntimeException('Not implemented');
}

public function setDisplayName($displayName) {
throw new \RuntimeException('Not implemented');
}

public function getLastLogin() {
throw new \RuntimeException('Not implemented');
}

public function updateLastLoginTimestamp() {
throw new \RuntimeException('Not implemented');
}

public function delete() {
throw new \RuntimeException('Not implemented');
}

public function setPassword($password, $recoveryPassword = null) {
throw new \RuntimeException('Not implemented');
}

public function getHome() {
throw new \RuntimeException('Not implemented');
}

public function getBackendClassName() {
throw new \RuntimeException('Not implemented');
}

public function getBackend() {
throw new \RuntimeException('Not implemented');
}

public function canChangeAvatar() {
throw new \RuntimeException('Not implemented');
}

public function canChangePassword() {
throw new \RuntimeException('Not implemented');
}

public function canChangeDisplayName() {
throw new \RuntimeException('Not implemented');
}

public function isEnabled() {
throw new \RuntimeException('Not implemented');
}

public function setEnabled(bool $enabled = true) {
throw new \RuntimeException('Not implemented');
}

public function getEMailAddress() {
throw new \RuntimeException('Not implemented');
}

public function getAvatarImage($size) {
throw new \RuntimeException('Not implemented');
}

public function setEMailAddress($mailAddress) {
throw new \RuntimeException('Not implemented');
}

public function getQuota() {
throw new \RuntimeException('Not implemented');
}

public function setQuota($quota) {
throw new \RuntimeException('Not implemented');
}

public function setSystemEMailAddress(string $mailAddress): void {
throw new \RuntimeException('Not implemented');
}

public function setPrimaryEMailAddress(string $mailAddress): void {
throw new \RuntimeException('Not implemented');
}
}
19 changes: 6 additions & 13 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
Expand All @@ -59,8 +58,6 @@ class Push {
protected $tokenProvider;
/** @var Manager */
private $keyManager;
/** @var IUserManager */
private $userManager;
/** @var IClientService */
protected $clientService;
/** @var ICache */
Expand All @@ -83,7 +80,6 @@ public function __construct(IDBConnection $connection,
IConfig $config,
IProvider $tokenProvider,
Manager $keyManager,
IUserManager $userManager,
IClientService $clientService,
ICacheFactory $cacheFactory,
IUserStatusManager $userStatusManager,
Expand All @@ -94,7 +90,6 @@ public function __construct(IDBConnection $connection,
$this->config = $config;
$this->tokenProvider = $tokenProvider;
$this->keyManager = $keyManager;
$this->userManager = $userManager;
$this->clientService = $clientService;
$this->cache = $cacheFactory->createDistributed('pushtokens');
$this->userStatusManager = $userStatusManager;
Expand Down Expand Up @@ -159,10 +154,7 @@ public function pushToDevice(int $id, INotification $notification, ?OutputInterf
return;
}

$user = $this->userManager->get($notification->getUser());
if (!($user instanceof IUser)) {
return;
}
$user = $this->createFakeUserObject($notification->getUser());

$userStatus = $this->userStatusManager->getUserStatuses([
$notification->getUser(),
Expand Down Expand Up @@ -245,10 +237,7 @@ public function pushDeleteToDevice(string $userId, int $notificationId, string $
return;
}

$user = $this->userManager->get($userId);
if (!($user instanceof IUser)) {
return;
}
$user = $this->createFakeUserObject($userId);

$devices = $this->getDevicesForUser($userId);
if ($notificationId !== 0 && $app !== '') {
Expand Down Expand Up @@ -550,4 +539,8 @@ protected function deletePushTokenByDeviceIdentifier(string $deviceIdentifier):

return $query->executeStatement() !== 0;
}

protected function createFakeUserObject(string $userId): IUser {
return new FakeUser($userId);
}
}
Loading