From 3ce5d4e5450607b42da73f5c45a6fcd516fd9462 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 4 Sep 2019 13:36:08 +0200 Subject: [PATCH 1/2] reduce adressbook change events and handling ... from four to one on avatar updates Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/User_Proxy.php | 2 +- lib/private/Avatar/UserAvatar.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php index ccc82760b024f..a3f9e67764e1f 100644 --- a/apps/user_ldap/lib/User_Proxy.php +++ b/apps/user_ldap/lib/User_Proxy.php @@ -253,7 +253,7 @@ public function setDisplayName($uid, $displayName) { * @return boolean either the user can or cannot */ public function canChangeAvatar($uid) { - return $this->handleRequest($uid, 'canChangeAvatar', array($uid)); + return $this->handleRequest($uid, 'canChangeAvatar', [$uid], true); } /** diff --git a/lib/private/Avatar/UserAvatar.php b/lib/private/Avatar/UserAvatar.php index 2db65634e8c3a..f96ec93d5d098 100644 --- a/lib/private/Avatar/UserAvatar.php +++ b/lib/private/Avatar/UserAvatar.php @@ -97,7 +97,7 @@ public function set($data) { $this->validateAvatar($img); - $this->remove(); + $this->remove(true); $type = $this->getAvatarImageType($img); $file = $this->folder->newFile('avatar.' . $type); $file->putContent($data); @@ -193,7 +193,7 @@ private function validateAvatar(IImage $avatar) { * @throws \OCP\Files\NotPermittedException * @throws \OCP\PreConditionNotMetException */ - public function remove() { + public function remove(bool $silent = false) { $avatars = $this->folder->getDirectoryListing(); $this->config->setUserValue($this->user->getUID(), 'avatar', 'version', @@ -203,7 +203,9 @@ public function remove() { $avatar->delete(); } $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true'); - $this->user->triggerChange('avatar', ''); + if(!$silent) { + $this->user->triggerChange('avatar', ''); + } } /** From d33e0be2f1e2b276fc99b7f22cd5496cfc6c18a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 4 Sep 2019 13:36:36 +0200 Subject: [PATCH 2/2] adjust test expectations Signed-off-by: Arthur Schiwon --- tests/lib/Avatar/UserAvatarTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/lib/Avatar/UserAvatarTest.php b/tests/lib/Avatar/UserAvatarTest.php index 061866bedb0f2..2ce9266cf4d9a 100644 --- a/tests/lib/Avatar/UserAvatarTest.php +++ b/tests/lib/Avatar/UserAvatarTest.php @@ -223,8 +223,7 @@ public function testSetAvatar() { $this->config->expects($this->once()) ->method('getUserValue'); - // One on remove and once on setting the new avatar - $this->user->expects($this->exactly(2))->method('triggerChange'); + $this->user->expects($this->exactly(1))->method('triggerChange'); $this->avatar->set($image->data()); }