Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2020-12-16 05:21:39 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2020-12-16 05:42:00 +0300
commit330fac872282eec66ff114cb315b23df9f51908b (patch)
treeab83a7c649835674fa0c22c9f5f082626abd2890
parent135d14b2b58d9ef0fe6834d2a7b698b4b9c7df60 (diff)
Add method to get the version of an avatar
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--lib/private/Avatar/GuestAvatarProvider.php10
-rw-r--r--lib/private/Avatar/UserAvatarProvider.php15
-rw-r--r--lib/public/IAvatarProvider.php16
3 files changed, 41 insertions, 0 deletions
diff --git a/lib/private/Avatar/GuestAvatarProvider.php b/lib/private/Avatar/GuestAvatarProvider.php
index c395b8af760..0768fece298 100644
--- a/lib/private/Avatar/GuestAvatarProvider.php
+++ b/lib/private/Avatar/GuestAvatarProvider.php
@@ -72,6 +72,16 @@ class GuestAvatarProvider implements IAvatarProvider {
}
/**
+ * Returns the latest value of the avatar version
+ *
+ * @param IAvatar $avatar ignored
+ * @return int 0, as versions are not supported by guest avatars
+ */
+ public function getVersion(IAvatar $avatar): int {
+ return 0;
+ }
+
+ /**
* Returns the cache duration for guest avatars in seconds
*
* @param IAvatar $avatar ignored, same duration for all guest avatars
diff --git a/lib/private/Avatar/UserAvatarProvider.php b/lib/private/Avatar/UserAvatarProvider.php
index 401358cf56a..ecdeccb032e 100644
--- a/lib/private/Avatar/UserAvatarProvider.php
+++ b/lib/private/Avatar/UserAvatarProvider.php
@@ -131,6 +131,21 @@ class UserAvatarProvider implements IAvatarProvider {
}
/**
+ * Returns the latest value of the avatar version
+ *
+ * @param IAvatar $avatar the avatar to check
+ * @return int the latest value of the avatar version
+ * @throws \InvalidArgumentException if the given avatar is not a UserAvatar
+ */
+ public function getVersion(IAvatar $avatar): int {
+ if (!($avatar instanceof UserAvatar)) {
+ throw new \InvalidArgumentException();
+ }
+
+ return (int) $this->config->getUserValue($avatar->getUser()->getUID(), 'avatar', 'version', 0);
+ }
+
+ /**
* Returns the cache duration for user avatars in seconds
*
* @param IAvatar $avatar ignored, same duration for all user avatars
diff --git a/lib/public/IAvatarProvider.php b/lib/public/IAvatarProvider.php
index bbd1cb2b6a0..a20c0c2b06b 100644
--- a/lib/public/IAvatarProvider.php
+++ b/lib/public/IAvatarProvider.php
@@ -81,6 +81,22 @@ interface IAvatarProvider {
public function canBeModifiedByCurrentUser(IAvatar $avatar): bool;
/**
+ * Returns the latest value of the avatar version
+ *
+ * Implementers of IAvatarProvider may not throw \InvalidArgumentException
+ * if the behaviour does not depend on specific avatar instances (for
+ * example, if versions are not supported and the same version is always
+ * returned).
+ *
+ * @param IAvatar $avatar the avatar to check
+ * @return int the latest value of the avatar version
+ * @throws \InvalidArgumentException if the given avatar is not supported by
+ * this provider
+ * @since 21.0.0
+ */
+ public function getVersion(IAvatar $avatar): int;
+
+ /**
* Returns the cache duration in seconds
*
* Implementers of IAvatarProvider may not throw \InvalidArgumentException