Skip to content
Open
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
26 changes: 26 additions & 0 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserBackend;
use OCP\IUserManager;
Expand All @@ -37,6 +38,7 @@
use OCP\UserInterface;
use OCP\Util;
use Psr\Log\LoggerInterface;
use RuntimeException;

/**
* Class Manager
Expand Down Expand Up @@ -70,6 +72,9 @@ class Manager extends PublicEmitter implements IUserManager {

private DisplayNameCache $displayNameCache;

// IURLGenerator can't be injected through DI
private ?IURLGenerator $urlGenerator;

// This constructor can't autoload any class requiring a DB connection.
public function __construct(
private IConfig $config,
Expand Down Expand Up @@ -862,4 +867,25 @@ public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator {
public function getExistingUser(string $userId, ?string $displayName = null): IUser {
return new LazyUser($userId, $this, $displayName);
}


#[\Override]
public function getAvatarUrlLight(string $userId, int $size): string {
$url = ($this->urlGenerator ??= Server::get(IURLGenerator::class))->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $userId, 'size' => $size]);
if ($url === '') {
throw new RuntimeException('The URL is empty.');
}

return $url;
}

#[\Override]
public function getAvatarUrlDark(string $userId, int $size): string {
$url = ($this->urlGenerator ??= Server::get(IURLGenerator::class))->linkToRouteAbsolute('core.avatar.getAvatarDark', ['userId' => $userId, 'size' => $size]);
if ($url === '') {
throw new RuntimeException('The URL is empty.');
}

return $url;
}
}
15 changes: 15 additions & 0 deletions lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,19 @@ public function getSeenUsers(int $offset = 0, ?int $limit = null): \Iterator;
* @since 33.0.0
*/
public function getExistingUser(string $userId, ?string $displayName = null): IUser;


/**
* @param 64|512 $size
* @return non-empty-string
* @since 34.0.0
*/
public function getAvatarUrlLight(string $userId, int $size): string;

/**
* @param 64|512 $size
* @return non-empty-string
* @since 34.0.0
*/
public function getAvatarUrlDark(string $userId, int $size): string;
}
Loading
Loading