namespace OCA\Files_Sharing\AppInfo;
use OC\Share\Share;
+use OC\User\DisplayNameCache;
use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Files_Sharing\External\Manager;
use OCP\L10N\IFactory;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\IManager;
+use OCP\User\Events\UserChangedEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
$context->registerCapability(Capabilities::class);
$context->registerNotifierService(Notifier::class);
+ $context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class);
}
public function boot(IBootContext $context): void {
private ICacheEntry $sourceRootInfo;
private bool $rootUnchanged = true;
private ?string $ownerDisplayName = null;
- private int $numericId;
+ private $numericId;
private DisplayNameCache $displayNameCache;
/**
namespace OC\User;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IUserManager;
+use OCP\User\Events\UserChangedEvent;
/**
* Class that cache the relation UserId -> Display name
* their preferences. It's generally not an issue if this data is slightly
* outdated.
*/
-class DisplayNameCache {
+class DisplayNameCache implements IEventListener {
private ICache $internalCache;
private IUserManager $userManager;
public function clear(): void {
$this->internalCache->clear();
}
+
+ public function handle(Event $event): void {
+ if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') {
+ $userId = $event->getUser()->getUID();
+ $newDisplayName = $event->getValue();
+ $this->internalCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
+ }
+ }
}