Make the info available if the avatar was uploaded or generated

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/10481/head
Joas Schilling 8 years ago
parent 3e0668e348
commit decd196162
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
  1. 11
      core/Controller/AvatarController.php
  2. 11
      lib/private/Avatar.php
  3. 8
      lib/public/IAvatar.php

@ -132,12 +132,13 @@ class AvatarController extends Controller {
}
try {
$avatar = $this->avatarManager->getAvatar($userId)->getFile($size);
$avatar = $this->avatarManager->getAvatar($userId);
$avatarFile = $avatar->getFile($size);
$resp = new FileDisplayResponse(
$avatar,
Http::STATUS_OK,
['Content-Type' => $avatar->getMimeType()
]);
$avatarFile,
$avatar->isCustomAvatar() ? Http::STATUS_OK : Http::STATUS_CREATED,
['Content-Type' => $avatarFile->getMimeType()]
);
} catch (\Exception $e) {
$resp = new Http\Response();
$resp->setStatus(Http::STATUS_NOT_FOUND);

@ -119,6 +119,15 @@ class Avatar implements IAvatar {
return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
}
/**
* Check if the avatar of a user is a custom uploaded one
*
* @return bool
*/
public function isCustomAvatar(): bool {
return !$this->folder->fileExists('generated');
}
/**
* sets the users avatar
* @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
@ -362,7 +371,7 @@ class Avatar implements IAvatar {
* @param string $font font path
* @param int $size font size
* @param int $angle
* @return Array
* @return array
*/
protected function imageTTFCenter($image, string $text, string $font, int $size, $angle = 0): array {
// Image width & height

@ -53,6 +53,14 @@ interface IAvatar {
*/
public function exists();
/**
* Check if the avatar of a user is a custom uploaded one
*
* @return bool
* @since 14.0.0
*/
public function isCustomAvatar(): bool;
/**
* sets the users avatar
* @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar

Loading…
Cancel
Save