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

github.com/nextcloud/circles.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@nextcloud.com>2017-08-01 18:40:31 +0300
committerMaxence Lange <maxence@nextcloud.com>2017-08-01 18:40:31 +0300
commit2b96d68551a3f9a37b852a93bf35399b9c7504b2 (patch)
tree4da021c8723c92805f1642650af75fe77e6c6ee7 /lib
parentd901b9cdb21125b7027b36cf7d66652d92106983 (diff)
rewrite on getDisplayName() and Personal Circle
Signed-off-by: Maxence Lange <maxence@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Api/Sharees.php11
-rw-r--r--lib/Api/v1/Circles.php36
-rw-r--r--lib/IBroadcaster.php5
-rw-r--r--lib/Model/BaseMember.php5
-rw-r--r--lib/Model/Circle.php33
-rw-r--r--lib/Model/SharingFrame.php30
-rw-r--r--lib/Service/BroadcastService.php39
-rw-r--r--lib/Service/FederatedService.php1
-rw-r--r--lib/Service/MiscService.php30
-rw-r--r--lib/Service/SharesService.php1
10 files changed, 148 insertions, 43 deletions
diff --git a/lib/Api/Sharees.php b/lib/Api/Sharees.php
index 26933ca0..c1437dfc 100644
--- a/lib/Api/Sharees.php
+++ b/lib/Api/Sharees.php
@@ -29,6 +29,7 @@ namespace OCA\Circles\Api;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
+use OCA\Circles\Service\MiscService;
use OCP\Share;
@@ -83,12 +84,10 @@ class Sharees {
'shareType' => Share::SHARE_TYPE_CIRCLE,
'shareWith' => $entry->getUniqueId(),
'circleInfo' => $entry->getInfo(),
- 'circleOwner' => \OC::$server->getUserManager()
- ->get(
- $entry->getOwner()
- ->getUserId()
- )
- ->getDisplayName()
+ 'circleOwner' => MiscService::staticGetUserManager(
+ $entry->getOwner()
+ ->getUserId()
+ )
],
];
diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php
index 427e02fd..7185611d 100644
--- a/lib/Api/v1/Circles.php
+++ b/lib/Api/v1/Circles.php
@@ -33,6 +33,7 @@ use OCA\Circles\Model\Circle;
use OCA\Circles\Model\FederatedLink;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;
+use OCA\Circles\Service\MiscService;
class Circles {
@@ -387,4 +388,39 @@ class Circles {
. '-' . $link->getToken();
}
+
+ /**
+ * @param SharingFrame $frame
+ *
+ * @return array
+ */
+ public static function generateUserParameter(SharingFrame $frame) {
+
+ if ($frame->getCloudId() !== null) {
+ $name = $frame->getAuthor() . '@' . $frame->getCloudId();
+ } else {
+ $name = MiscService::staticGetDisplayName($frame->getAuthor());
+ }
+
+ return [
+ 'type' => 'user',
+ 'id' => $frame->getAuthor(),
+ 'name' => $name
+ ];
+ }
+
+
+ /**
+ * @param SharingFrame $frame
+ *
+ * @return array
+ */
+ public static function generateCircleParameter(SharingFrame $frame) {
+ return [
+ 'type' => 'circle',
+ 'id' => $frame->getCircleId(),
+ 'name' => $frame->getCircleName(),
+ 'link' => self::generateLink($frame->getCircleId())
+ ];
+ }
} \ No newline at end of file
diff --git a/lib/IBroadcaster.php b/lib/IBroadcaster.php
index dc61e621..df7f5868 100644
--- a/lib/IBroadcaster.php
+++ b/lib/IBroadcaster.php
@@ -4,6 +4,7 @@
namespace OCA\Circles;
+use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;
interface IBroadcaster {
@@ -15,7 +16,7 @@ interface IBroadcaster {
/**
- * broadcast a creation of $share to $circleId.
+ * broadcast a creation of a Share to a circle.
*
* @param SharingFrame $frame
*
@@ -25,7 +26,7 @@ interface IBroadcaster {
/**
- * broadcast a creation of $share to $userId.
+ * broadcast a creation of a Share to a $userId.
*
* @param SharingFrame $frame
* @param string $userId
diff --git a/lib/Model/BaseMember.php b/lib/Model/BaseMember.php
index bec1e431..c1235347 100644
--- a/lib/Model/BaseMember.php
+++ b/lib/Model/BaseMember.php
@@ -27,6 +27,7 @@
namespace OCA\Circles\Model;
use OC\L10N\L10N;
+use OCA\Circles\Service\MiscService;
class BaseMember implements \JsonSerializable {
@@ -146,9 +147,7 @@ class BaseMember implements \JsonSerializable {
if ($userId !== null && $userId !== '') {
$this->setDisplayName(
- \OC::$server->getUserManager()
- ->get($userId)
- ->getDisplayName()
+ MiscService::staticGetDisplayName($userId)
);
}
diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php
index a456e323..d249d716 100644
--- a/lib/Model/Circle.php
+++ b/lib/Model/Circle.php
@@ -68,22 +68,22 @@ class Circle extends BaseCircle implements \JsonSerializable {
public function jsonSerialize() {
$json = array(
- 'id' => $this->getId(),
- 'name' => $this->getName(),
- 'owner' => $this->getOwner(),
- 'user' => $this->getViewer(),
- 'group' => $this->getGroupViewer(),
- 'viewer' => $this->getHigherViewer(),
- 'description' => $this->getDescription(),
- 'settings' => $this->getSettings(),
- 'type' => $this->getType(),
- 'creation' => $this->getCreation(),
- 'typeString' => $this->getTypeString(),
- 'typeLongString' => $this->getTypeLongString(),
- 'unique_id' => $this->getUniqueId($this->fullJson),
- 'members' => $this->getMembers(),
- 'groups' => $this->getGroups(),
- 'links' => $this->getLinks()
+ 'id' => $this->getId(),
+ 'name' => $this->getName(),
+ 'owner' => $this->getOwner(),
+ 'user' => $this->getViewer(),
+ 'group' => $this->getGroupViewer(),
+ 'viewer' => $this->getHigherViewer(),
+ 'description' => $this->getDescription(),
+ 'settings' => $this->getSettings(),
+ 'type' => $this->getType(),
+ 'creation' => $this->getCreation(),
+ 'type_string' => $this->getTypeString(),
+ 'type_long_string' => $this->getTypeLongString(),
+ 'unique_id' => $this->getUniqueId($this->fullJson),
+ 'members' => $this->getMembers(),
+ 'groups' => $this->getGroups(),
+ 'links' => $this->getLinks()
);
if ($this->lightJson) {
@@ -168,7 +168,6 @@ class Circle extends BaseCircle implements \JsonSerializable {
}
-
/**
* @throws CircleTypeNotValidException
*/
diff --git a/lib/Model/SharingFrame.php b/lib/Model/SharingFrame.php
index 83105de6..398d520d 100644
--- a/lib/Model/SharingFrame.php
+++ b/lib/Model/SharingFrame.php
@@ -42,6 +42,9 @@ class SharingFrame implements \JsonSerializable {
/** @var string */
private $circleName;
+ /** @var int */
+ private $circleType;
+
/** @var string */
private $author;
@@ -111,6 +114,21 @@ class SharingFrame implements \JsonSerializable {
/**
+ * @param int $circleType
+ */
+ public function setCircleType($circleType) {
+ $this->circleType = $circleType;
+ }
+
+ /**
+ * @return int
+ */
+ public function getCircleType() {
+ return $this->circleType;
+ }
+
+
+ /**
* @param string $author
*/
public function setAuthor($author) {
@@ -273,11 +291,12 @@ class SharingFrame implements \JsonSerializable {
}
}
-
+
public function jsonSerialize() {
return array(
'circle_id' => $this->getCircleId(),
'circle_name' => $this->getCircleName(),
+ 'circle_type' => $this->getCircleType(),
'unique_id' => $this->getUniqueId(),
'source' => $this->getSource(),
'type' => $this->getType(),
@@ -292,7 +311,7 @@ class SharingFrame implements \JsonSerializable {
public static function fromJSON($json) {
$arr = json_decode($json, true);
- if (!key_exists('source', $arr)) {
+ if (!is_array($arr) || !key_exists('source', $arr)) {
return null;
}
@@ -301,6 +320,10 @@ class SharingFrame implements \JsonSerializable {
if (key_exists('circle_name', $arr)) {
$share->setCircleName($arr['circle_name']);
}
+ if (key_exists('circle_type', $arr)) {
+ $share->setCircleType($arr['circle_type']);
+ }
+
if (key_exists('headers', $arr)) {
$share->setHeaders($arr['headers']);
@@ -318,4 +341,5 @@ class SharingFrame implements \JsonSerializable {
return $share;
}
-} \ No newline at end of file
+}
+
diff --git a/lib/Service/BroadcastService.php b/lib/Service/BroadcastService.php
index 59fba597..d93ae358 100644
--- a/lib/Service/BroadcastService.php
+++ b/lib/Service/BroadcastService.php
@@ -27,10 +27,12 @@
namespace OCA\Circles\Service;
+use Exception;
use OCA\Circles\Db\CirclesRequest;
use OCA\Circles\Db\MembersRequest;
use OCA\Circles\Exceptions\BroadcasterIsNotCompatibleException;
use OCA\Circles\IBroadcaster;
+use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;
@@ -81,10 +83,14 @@ class BroadcastService {
* broadcast the SharingFrame item using a IBroadcaster.
* The broadcast is usually set by the app that created the SharingFrame item.
*
+ * If the circle is not a Personal Circle, we first call createShareToCircle()
+ * Then for each members of the circle, we call createShareToUser()
+ * If the circle is a Personal Circle, we don't send data about the SharingFrame but null.
+ *
* @param string $broadcast
* @param SharingFrame $frame
*
- * @throws BroadcasterIsNotCompatibleException
+ * @throws Exception
*/
public function broadcastFrame($broadcast, SharingFrame $frame) {
@@ -92,16 +98,27 @@ class BroadcastService {
return;
}
- $broadcaster = \OC::$server->query((string)$broadcast);
- if (!($broadcaster instanceof IBroadcaster)) {
- throw new BroadcasterIsNotCompatibleException();
- }
-
- $broadcaster->init();
- $broadcaster->createShareToCircle($frame);
- $users = $this->membersRequest->forceGetMembers($frame->getCircleId(), Member::LEVEL_MEMBER, true);
- foreach ($users AS $user) {
- $broadcaster->createShareToUser($frame, $user->getUserId());
+ try {
+ $broadcaster = \OC::$server->query((string)$broadcast);
+ if (!($broadcaster instanceof IBroadcaster)) {
+ throw new BroadcasterIsNotCompatibleException();
+ }
+
+ $circle = $this->circlesRequest->forceGetCircle($frame->getCircleId());
+
+ $broadcaster->init();
+ if ($circle->getType() !== Circle::CIRCLES_PERSONAL) {
+ $broadcaster->createShareToCircle($frame);
+ }
+
+ $users = $this->membersRequest->forceGetMembers(
+ $circle->getUniqueId(), Member::LEVEL_MEMBER, true
+ );
+ foreach ($users AS $user) {
+ $broadcaster->createShareToUser($frame, $user->getUserId());
+ }
+ } catch (Exception $e) {
+ throw $e;
}
}
diff --git a/lib/Service/FederatedService.php b/lib/Service/FederatedService.php
index 4015c2e8..98b6a877 100644
--- a/lib/Service/FederatedService.php
+++ b/lib/Service/FederatedService.php
@@ -718,6 +718,7 @@ class FederatedService {
$frame->setCircleId($link->getCircleId());
$frame->setCircleName($circle->getName());
+ $frame->setCircleType($circle->getType());
$this->circlesRequest->saveFrame($frame);
$this->broadcastService->broadcastFrame($frame->getHeader('broadcast'), $frame);
diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php
index 90371019..e504815b 100644
--- a/lib/Service/MiscService.php
+++ b/lib/Service/MiscService.php
@@ -68,6 +68,33 @@ class MiscService {
* @return string
* @throws NoUserException
*/
+ public static function staticGetDisplayName($userId, $noException = false) {
+ $user = \OC::$server->getUserManager()
+ ->get($userId);
+ if ($user === null) {
+ if ($noException) {
+ return $userId;
+ } else {
+ throw new NoUserException();
+ }
+ }
+
+ return $user->getDisplayName();
+ }
+
+
+ /**
+ * return Display Name if user exists and display name exists.
+ * returns Exception if user does not exist.
+ *
+ * However, with noException set to true, will return userId even if user does not exist
+ *
+ * @param $userId
+ * @param bool $noException
+ *
+ * @return string
+ * @throws NoUserException
+ */
public function getDisplayName($userId, $noException = false) {
$user = $this->userManager->get($userId);
if ($user === null) {
@@ -80,4 +107,5 @@ class MiscService {
return $user->getDisplayName();
}
-} \ No newline at end of file
+}
+
diff --git a/lib/Service/SharesService.php b/lib/Service/SharesService.php
index 507bb0a6..8f5a8145 100644
--- a/lib/Service/SharesService.php
+++ b/lib/Service/SharesService.php
@@ -145,6 +145,7 @@ class SharesService {
$frame->setHeader('broadcast', (string)$broadcast);
$frame->generateUniqueId();
$frame->setCircleName($circle->getName());
+ $frame->setCircleType($circle->getType());
} catch (Exception $e) {
throw new $e;