Skip to content

Commit

Permalink
isolate logic to get current user language, remove unused startsWith …
Browse files Browse the repository at this point in the history
…function

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Mar 4, 2025
1 parent 9020e77 commit d9f9512
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
use Psr\Log\LoggerInterface;
use Throwable;

function startsWith(string $haystack, string $needle): bool {
$length = mb_strlen($needle);
return (mb_substr($haystack, 0, $length) === $needle);
}

class FileService {

public function __construct(private IRootFolder $root,
public function __construct(
private IRootFolder $root,
private IConfig $config,
private IURLGenerator $urlGenerator,
private LoggerInterface $logger,
Expand All @@ -47,17 +43,7 @@ public function __construct(private IRootFolder $root,
) {
}

/**
* @return File|null
* @throws NoUserException
* @throws NotFoundException
* @throws NotPermittedException
*/
private function getWidgetFile(): ?File {
$filePath = $this->config->getAppValue(Application::APP_ID, 'filePath');
$userName = $this->config->getAppValue(Application::APP_ID, 'userName');
$userId = $this->config->getAppValue(Application::APP_ID, 'userId');

private function getCurrentUserLanguage(): string {
// Get current user so we can get settings
$sessionUserId = \OC_User::getUser();
// Figure out system's default language, default to "en"
Expand Down Expand Up @@ -106,6 +92,21 @@ private function getWidgetFile(): ?File {
$userLocale = 'en_US';
}

return $userLang;
}

/**
* @return File|null
* @throws NoUserException
* @throws NotFoundException
* @throws NotPermittedException
*/
private function getWidgetFile(): ?File {
$filePath = $this->config->getAppValue(Application::APP_ID, 'filePath');
$userName = $this->config->getAppValue(Application::APP_ID, 'userName');
$userId = $this->config->getAppValue(Application::APP_ID, 'userId');
$userLang = $this->getCurrentUserLanguage();

/**
* Note: For some languagues, and German in particular, Nextcloud uses
* the full locale for the language setting. This is, apparently, for
Expand Down Expand Up @@ -165,7 +166,7 @@ public function getWidgetContent(): ?array {
$supportUserId = null;
$supportText = null;
}


$file = $this->getWidgetFile();
if ($file !== null) {
Expand Down

0 comments on commit d9f9512

Please sign in to comment.