Skip to content

Commit

Permalink
Merge pull request #17001 from nextcloud/fix/noid/addressbookchanges-…
Browse files Browse the repository at this point in the history
…avatar

reduce adressbook change events and handling
  • Loading branch information
blizzz authored Oct 1, 2019
2 parents d68f30e + d33e0be commit 47ab961
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/private/Avatar/UserAvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand All @@ -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', '');
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/Avatar/UserAvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 47ab961

Please sign in to comment.