Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-07-08 15:22:11 +0300
committerJoas Schilling <coding@schilljs.com>2020-07-08 15:30:49 +0300
commit91648c874e0e556ee343e6860afffcfa82df23a4 (patch)
tree832814a8ac3adbca91f9433b7687c01b77acfc25 /lib
parent21955ac0dbb7ab383878ac8ca6b45e42d783fded (diff)
Use the L10N factory to get the users language
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/EndpointController.php27
-rw-r--r--lib/Push.php10
2 files changed, 13 insertions, 24 deletions
diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php
index f184fd9..f568fde 100644
--- a/lib/Controller/EndpointController.php
+++ b/lib/Controller/EndpointController.php
@@ -27,10 +27,10 @@ use OCA\Notifications\Push;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
-use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
use OCP\Notification\IAction;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
@@ -40,35 +40,25 @@ class EndpointController extends OCSController {
private $handler;
/** @var IManager */
private $manager;
- /** @var IConfig */
- private $config;
+ /** @var IFactory */
+ private $l10nFactory;
/** @var IUserSession */
private $session;
/** @var Push */
private $push;
-
- /**
- * @param string $appName
- * @param IRequest $request
- * @param Handler $handler
- * @param IManager $manager
- * @param IConfig $config
- * @param IUserSession $session
- * @param Push $push
- */
public function __construct(string $appName,
IRequest $request,
Handler $handler,
IManager $manager,
- IConfig $config,
+ IFactory $l10nFactory,
IUserSession $session,
Push $push) {
parent::__construct($appName, $request);
$this->handler = $handler;
$this->manager = $manager;
- $this->config = $config;
+ $this->l10nFactory = $l10nFactory;
$this->session = $session;
$this->push = $push;
}
@@ -89,9 +79,7 @@ class EndpointController extends OCSController {
$filter = $this->manager->createNotification();
$filter->setUser($this->getCurrentUser());
- $language = $this->config->getUserValue($this->getCurrentUser(), 'core', 'lang', null);
- $language = $language ?? $this->config->getSystemValue('default_language', 'en');
-
+ $language = $this->l10nFactory->getUserLanguage($this->session->getUser());
$notifications = $this->handler->get($filter);
$data = [];
@@ -140,8 +128,7 @@ class EndpointController extends OCSController {
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}
- $language = $this->config->getUserValue($this->getCurrentUser(), 'core', 'lang', null);
- $language = $language ?? $this->config->getSystemValue('default_language', 'en');
+ $language = $this->l10nFactory->getUserLanguage($this->session->getUser());
try {
$notification = $this->manager->prepare($notification, $language);
diff --git a/lib/Push.php b/lib/Push.php
index 8e7c00e..717cf24 100644
--- a/lib/Push.php
+++ b/lib/Push.php
@@ -36,6 +36,7 @@ use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use Symfony\Component\Console\Output\OutputInterface;
@@ -57,6 +58,8 @@ class Push {
protected $clientService;
/** @var ICache */
protected $cache;
+ /** @var IFactory */
+ protected $l10nFactory;
/** @var ILogger */
protected $log;
/** @var OutputInterface */
@@ -70,6 +73,7 @@ class Push {
IUserManager $userManager,
IClientService $clientService,
ICacheFactory $cacheFactory,
+ IFactory $l10nFactory,
ILogger $log) {
$this->db = $connection;
$this->notificationManager = $notificationManager;
@@ -79,6 +83,7 @@ class Push {
$this->userManager = $userManager;
$this->clientService = $clientService;
$this->cache = $cacheFactory->createDistributed('pushtokens');
+ $this->l10nFactory = $l10nFactory;
$this->log = $log;
}
@@ -107,10 +112,7 @@ class Push {
$this->printInfo('Trying to push to ' . count($devices) . ' devices');
$this->printInfo('');
- $language = $this->config->getSystemValue('force_language', false);
- $language = \is_string($language) ? $language : $this->config->getUserValue($notification->getUser(), 'core', 'lang', null);
- $language = $language ?? $this->config->getSystemValue('default_language', 'en');
-
+ $language = $this->l10nFactory->getUserLanguage($user);
$this->printInfo('Language is set to ' . $language);
try {