Skip to content

Commit 47ab961

Browse files
authored
Merge pull request #17001 from nextcloud/fix/noid/addressbookchanges-avatar
reduce adressbook change events and handling
2 parents d68f30e + d33e0be commit 47ab961

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

apps/user_ldap/lib/User_Proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function setDisplayName($uid, $displayName) {
253253
* @return boolean either the user can or cannot
254254
*/
255255
public function canChangeAvatar($uid) {
256-
return $this->handleRequest($uid, 'canChangeAvatar', array($uid));
256+
return $this->handleRequest($uid, 'canChangeAvatar', [$uid], true);
257257
}
258258

259259
/**

lib/private/Avatar/UserAvatar.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function set($data) {
9797

9898
$this->validateAvatar($img);
9999

100-
$this->remove();
100+
$this->remove(true);
101101
$type = $this->getAvatarImageType($img);
102102
$file = $this->folder->newFile('avatar.' . $type);
103103
$file->putContent($data);
@@ -193,7 +193,7 @@ private function validateAvatar(IImage $avatar) {
193193
* @throws \OCP\Files\NotPermittedException
194194
* @throws \OCP\PreConditionNotMetException
195195
*/
196-
public function remove() {
196+
public function remove(bool $silent = false) {
197197
$avatars = $this->folder->getDirectoryListing();
198198

199199
$this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
@@ -203,7 +203,9 @@ public function remove() {
203203
$avatar->delete();
204204
}
205205
$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
206-
$this->user->triggerChange('avatar', '');
206+
if(!$silent) {
207+
$this->user->triggerChange('avatar', '');
208+
}
207209
}
208210

209211
/**

tests/lib/Avatar/UserAvatarTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ public function testSetAvatar() {
223223
$this->config->expects($this->once())
224224
->method('getUserValue');
225225

226-
// One on remove and once on setting the new avatar
227-
$this->user->expects($this->exactly(2))->method('triggerChange');
226+
$this->user->expects($this->exactly(1))->method('triggerChange');
228227

229228
$this->avatar->set($image->data());
230229
}

0 commit comments

Comments
 (0)