Skip to content

Commit 5d8f1a1

Browse files
author
Vincent Petry
committed
Merge pull request #13854 from owncloud/avatar-exists
Add a better way to check if an avatar exists for the user
2 parents dc475ab + c644ed8 commit 5d8f1a1

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

lib/private/avatar.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function get ($size = 64) {
4242
return $avatar;
4343
}
4444

45+
/**
46+
* Check if an avatar exists for the user
47+
*
48+
* @return bool
49+
*/
50+
public function exists() {
51+
return $this->view->file_exists('avatar.jpg') || $this->view->file_exists('avatar.png');
52+
}
53+
4554
/**
4655
* sets the users avatar
4756
* @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar

lib/private/helper.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,7 @@ public static function publicPreviewIcon( $path, $token ) {
289289
**/
290290
public static function userAvatarSet($user) {
291291
$avatar = new \OC_Avatar($user);
292-
$image = $avatar->get(1);
293-
if ($image instanceof \OC_Image) {
294-
return true;
295-
} else {
296-
return false;
297-
}
292+
return $avatar->exists();
298293
}
299294

300295
/**

lib/public/iavatar.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ interface IAvatar {
2020
*/
2121
function get($size = 64);
2222

23+
/**
24+
* Check if an avatar exists for the user
25+
*
26+
* @return bool
27+
*/
28+
public function exists();
29+
2330
/**
2431
* sets the users avatar
2532
* @param Image $data mixed imagedata or path to set a new avatar

0 commit comments

Comments
 (0)