Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(files_sharing): dark avatar support
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv authored and backportbot[bot] committed Jun 12, 2024
commit 732780381641a1ba535a90796a3e99726ee694c9
6 changes: 5 additions & 1 deletion apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ import { getCurrentUser } from '@nextcloud/auth'

import './sharingStatusAction.scss'

const isDarkMode = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches === true
|| document.querySelector('[data-themes*=dark]') !== null

const generateAvatarSvg = (userId: string, isGuest = false) => {
const avatarUrl = generateUrl(isGuest ? '/avatar/guest/{userId}/32' : '/avatar/{userId}/32?guestFallback=true', { userId })
const url = isDarkMode ? '/avatar/{userId}/32/dark' : '/avatar/{userId}/32'
const avatarUrl = generateUrl(isGuest ? url : url + '?guestFallback=true', { userId })
return `<svg width="32" height="32" viewBox="0 0 32 32"
xmlns="http://www.w3.org/2000/svg" class="sharing-status__avatar">
<image href="${avatarUrl}" height="32" width="32" />
Expand Down
10 changes: 5 additions & 5 deletions core/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\IAvatarManager;
use OCP\ICache;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

Expand All @@ -66,7 +65,6 @@ public function __construct(
protected LoggerInterface $logger,
protected ?string $userId,
protected TimeFactory $timeFactory,
protected IURLGenerator $urlGenerator,
protected GuestAvatarController $guestAvatarController,
) {
parent::__construct($appName, $request);
Expand All @@ -82,7 +80,8 @@ public function __construct(
*
* @param string $userId ID of the user
* @param int $size Size of the avatar
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @param bool $guestFallback Fallback to guest avatar if not found
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar?: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Avatar returned
* 404: Avatar not found
Expand Down Expand Up @@ -132,7 +131,8 @@ public function getAvatarDark(string $userId, int $size, bool $guestFallback = f
*
* @param string $userId ID of the user
* @param int $size Size of the avatar
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @param bool $guestFallback Fallback to guest avatar if not found
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar?: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Avatar returned
* 404: Avatar not found
Expand Down
15 changes: 13 additions & 2 deletions tests/Core/Controller/AvatarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function is_uploaded_file($filename) {

use OC\AppFramework\Utility\TimeFactory;
use OC\Core\Controller\AvatarController;
use OC\Core\Controller\GuestAvatarController;
use OCP\AppFramework\Http;
use OCP\Files\File;
use OCP\Files\IRootFolder;
Expand All @@ -56,13 +57,15 @@ function is_uploaded_file($filename) {
class AvatarControllerTest extends \Test\TestCase {
/** @var AvatarController */
private $avatarController;
/** @var GuestAvatarController */
private $guestAvatarController;

/** @var IAvatar|\PHPUnit\Framework\MockObject\MockObject */
private $avatarMock;
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
private $userMock;
/** @var ISimpleFile|\PHPUnit\Framework\MockObject\MockObject */
private $avatarFile;

/** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
private $avatarManager;
/** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
Expand Down Expand Up @@ -97,6 +100,13 @@ protected function setUp(): void {
$this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock();
$this->userMock = $this->getMockBuilder(IUser::class)->getMock();

$this->guestAvatarController = new GuestAvatarController(
'core',
$this->request,
$this->avatarManager,
$this->logger
);

$this->avatarController = new AvatarController(
'core',
$this->request,
Expand All @@ -107,7 +117,8 @@ protected function setUp(): void {
$this->rootFolder,
$this->logger,
'userid',
$this->timeFactory
$this->timeFactory,
$this->guestAvatarController,
);

// Configure userMock
Expand Down