Remove generated avatar on displayname change
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
6371b76598
commit
a4ca92f29a
3 changed files with 38 additions and 1 deletions
|
@ -393,4 +393,18 @@ class Avatar implements IAvatar {
|
|||
return array(round($r * 255), round($g * 255), round($b * 255));
|
||||
}
|
||||
|
||||
public function userChanged($feature, $oldValue, $newValue) {
|
||||
// We only change the avatar on display name changes
|
||||
if ($feature !== 'displayName') {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the avatar is not generated (so an uploaded image) we skip this
|
||||
if (!$this->folder->fileExists('generated')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -394,9 +394,10 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$userSession->listen('\OC\User', 'logout', function () {
|
||||
\OC_Hook::emit('OC_User', 'logout', array());
|
||||
});
|
||||
$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
|
||||
$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
|
||||
/** @var $user \OC\User\User */
|
||||
\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
|
||||
$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
|
||||
});
|
||||
return $userSession;
|
||||
});
|
||||
|
@ -1175,6 +1176,22 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$logger->info('Could not cleanup avatar of ' . $user->getUID());
|
||||
}
|
||||
});
|
||||
|
||||
$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
|
||||
$manager = $this->getAvatarManager();
|
||||
/** @var IUser $user */
|
||||
$user = $e->getSubject();
|
||||
$feature = $e->getArgument('feature');
|
||||
$oldValue = $e->getArgument('oldValue');
|
||||
$value = $e->getArgument('value');
|
||||
|
||||
try {
|
||||
$avatar = $manager->getAvatar($user->getUID());
|
||||
$avatar->userChanged($feature, $oldValue, $value);
|
||||
} catch (NotFoundException $e) {
|
||||
// no avatar to remove
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,4 +77,10 @@ interface IAvatar {
|
|||
* @since 9.0.0
|
||||
*/
|
||||
public function getFile($size);
|
||||
|
||||
/**
|
||||
* Handle a changed user
|
||||
* @since 13.0.0
|
||||
*/
|
||||
public function userChanged($feature, $oldValue, $newValue);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue