summaryrefslogtreecommitdiffstats
path: root/lib/Controller/SocialApiController.php
diff options
context:
space:
mode:
authorcall-me-matt <nextcloud@matthiasheinisch.de>2020-03-30 23:32:37 +0200
committercall-me-matt <nextcloud@matthiasheinisch.de>2020-08-05 00:23:06 +0200
commit973c28825b42c10a153785982c782368b9b79702 (patch)
tree63981d8805d2212b219d25d97761e25d27909206 /lib/Controller/SocialApiController.php
parentb78f4d65cc1438477e6c307f9d5d732e84833a98 (diff)
allowing for background updates of social avatars
Signed-off-by: call-me-matt <nextcloud@matthiasheinisch.de>
Diffstat (limited to 'lib/Controller/SocialApiController.php')
-rw-r--r--lib/Controller/SocialApiController.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/Controller/SocialApiController.php b/lib/Controller/SocialApiController.php
index 4898d915..b09eafdb 100644
--- a/lib/Controller/SocialApiController.php
+++ b/lib/Controller/SocialApiController.php
@@ -30,21 +30,29 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;
+use OCP\IUserSession;
class SocialApiController extends ApiController {
+ protected $appName;
/** @var IConfig */
private $config;
+ /** @var IUserSession */
+ private $userSession;
+
/** @var SocialApiService */
private $socialApiService;
public function __construct(IRequest $request,
IConfig $config,
+ IUserSession $userSession,
SocialApiService $socialApiService) {
parent::__construct(Application::APP_ID, $request);
$this->config = $config;
+ $this->appName = Application::APP_ID;
+ $this->userSession = $userSession;
$this->socialApiService = $socialApiService;
}
@@ -69,6 +77,46 @@ class SocialApiController extends ApiController {
/**
* @NoAdminRequired
*
+ * update appconfig (user setting)
+ *
+ * @param {String} key the identifier to change
+ * @param {String} allow the value to set
+ *
+ * @returns {JSONResponse} an empty JSONResponse with respective http status code
+ */
+ public function setUserConfig($key, $allow) {
+ $user = $this->userSession->getUser();
+ if (is_null($user)) {
+ return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
+ }
+ $userId = $user->getUid();
+ $this->config->setUserValue($userId, $this->appName, $key, $allow);
+ return new JSONResponse([], Http::STATUS_OK);
+ }
+
+
+ /**
+ * @NoAdminRequired
+ *
+ * retrieve appconfig (user setting)
+ *
+ * @param {String} key the identifier to retrieve
+ *
+ * @returns {string} the desired value or null if not existing
+ */
+ public function getUserConfig($key) {
+ $user = $this->userSession->getUser();
+ if (is_null($user)) {
+ return null;
+ }
+ $userId = $user->getUid();
+ return $this->config->getUserValue($userId, $this->appName, $key, 'null');
+ }
+
+
+ /**
+ * @NoAdminRequired
+ *
* returns an array of supported social networks
*
* @returns {array} array of the supported social networks