diff --git a/appinfo/info.xml b/appinfo/info.xml
index 82f2c7f1a..144c243b2 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -69,19 +69,19 @@ Those groups of people (or "circles") can then be used by any other app for shar
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ OCA\Circles\Activity\SettingAsNonMember
+ OCA\Circles\Activity\SettingAsMember
+ OCA\Circles\Activity\SettingAsModerator
+
+
+ OCA\Circles\Activity\Filter
+
+
+ OCA\Circles\Activity\Provider
+
+
diff --git a/lib/Activity/Filter.php b/lib/Activity/Filter.php
index cc21c24a6..26f8a135e 100644
--- a/lib/Activity/Filter.php
+++ b/lib/Activity/Filter.php
@@ -1,5 +1,31 @@
+ * @copyright 2023
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
namespace OCA\Circles\Activity;
@@ -9,15 +35,10 @@
use OCP\IURLGenerator;
class Filter implements IFilter {
- /** @var IL10N */
- protected $l10n;
-
- /** @var IURLGenerator */
- protected $url;
-
- public function __construct(IL10N $l10n, IURLGenerator $url) {
- $this->l10n = $l10n;
- $this->url = $url;
+ public function __construct(
+ protected IL10N $l10n,
+ protected IURLGenerator $url
+ ) {
}
/**
diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php
index 184815e01..49e882305 100644
--- a/lib/Activity/Provider.php
+++ b/lib/Activity/Provider.php
@@ -1,5 +1,7 @@
- * @copyright 2017
+ * @copyright 2023
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -25,89 +27,59 @@
*
*/
-
namespace OCA\Circles\Activity;
-use Exception;
use InvalidArgumentException;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Exceptions\FakeException;
-use OCA\Circles\Model\DeprecatedCircle;
-use OCA\Circles\Model\FederatedLink;
-use OCA\Circles\Model\DeprecatedMember;
-use OCA\Circles\Service\CirclesService;
-use OCA\Circles\Service\MiscService;
+use OCA\Circles\Model\Circle;
+use OCA\Circles\Model\Member;
+use OCA\Circles\Tools\Exceptions\InvalidItemException;
+use OCA\Circles\Tools\Traits\TDeserialize;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\Activity\IProvider;
+use OCP\IURLGenerator;
-/**
- * Class Provider
- *
- * @package OCA\Circles\Activity
- */
class Provider implements IProvider {
- /** @var ProviderSubjectCircle */
- private $parserCircle;
-
- /** @var ProviderSubjectMember */
- private $parserMember;
-
- /** @var ProviderSubjectGroup */
- private $parserGroup;
-
- /** @var ProviderSubjectLink */
- private $parserLink;
-
- /** @var MiscService */
- protected $miscService;
-
- /** @var IManager */
- protected $activityManager;
-
+ use TDeserialize;
public function __construct(
- IManager $activityManager, MiscService $miscService, ProviderSubjectCircle $parserCircle,
- ProviderSubjectMember $parserMember, ProviderSubjectGroup $parserGroup,
- ProviderSubjectLink $parserLink
+ private IManager $activityManager,
+ private IURLGenerator $urlGenerator,
+ private ProviderSubjectCircle $parserCircle,
+ private ProviderSubjectMember $parserMember,
+ private ProviderSubjectCircleMember $parserCircleMember
) {
- $this->activityManager = $activityManager;
- $this->miscService = $miscService;
-
- $this->parserCircle = $parserCircle;
- $this->parserMember = $parserMember;
- $this->parserGroup = $parserGroup;
- $this->parserLink = $parserLink;
}
-
/**
* {@inheritdoc}
*/
- public function parse($lang, IEvent $event, IEvent $previousEvent = null) {
+ public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent {
try {
$params = $event->getSubjectParameters();
$this->initActivityParser($event, $params);
- $circle = DeprecatedCircle::fromJSON($params['circle']);
+ /** @var Circle $circle */
+ $circle = $this->deserializeJson($params['circle'], Circle::class);
- $this->setIcon($event, $circle);
- $this->parseAsNonMember($event, $circle, $params);
+ $this->setIcon($event);
+ $this->parseAsNonMember($event, $circle);
$this->parseAsMember($event, $circle, $params);
$this->parseAsModerator($event, $circle, $params);
- } catch (FakeException $e) {
+ } catch (FakeException|InvalidItemException $e) {
/** clean exit */
}
return $event;
}
-
/**
* @param IEvent $event
* @param array $params
*/
- private function initActivityParser(IEvent $event, $params) {
+ private function initActivityParser(IEvent $event, array $params): void {
if ($event->getApp() !== Application::APP_ID) {
throw new InvalidArgumentException();
}
@@ -117,30 +89,28 @@ private function initActivityParser(IEvent $event, $params) {
}
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
*/
- private function setIcon(IEvent $event, DeprecatedCircle $circle) {
- $event->setIcon(
- CirclesService::getCircleIcon(
- $circle->getType(),
- (method_exists($this->activityManager, 'getRequirePNG')
- && $this->activityManager->getRequirePNG())
- )
+ private function setIcon(IEvent $event): void {
+ $path = $this->urlGenerator->imagePath(
+ Application::APP_ID,
+ 'circles.' . $this->activityManager->getRequirePNG() ? 'png' : 'svg'
);
+ $event->setIcon($this->urlGenerator->getAbsoluteURL($path));
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param array $params
*
* @throws FakeException
*/
- private function parseAsNonMember(IEvent $event, DeprecatedCircle $circle, $params) {
+ private function parseAsNonMember(
+ IEvent $event,
+ Circle $circle
+ ): void {
if ($event->getType() !== 'circles_as_non_member') {
return;
}
@@ -150,53 +120,61 @@ private function parseAsNonMember(IEvent $event, DeprecatedCircle $circle, $para
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param array $params
*
* @throws FakeException
*/
- private function parseAsMember(IEvent $event, DeprecatedCircle $circle, $params) {
+ private function parseAsMember(
+ IEvent $event,
+ Circle $circle,
+ array $params
+ ): void {
if ($event->getType() !== 'circles_as_member') {
return;
}
-// $this->parserCircle->parseSubjectCircleCreate($event, $circle);
+ $this->parserCircle->parseSubjectCircleCreate($event, $circle);
$this->parserCircle->parseSubjectCircleDelete($event, $circle);
$this->parseMemberAsMember($event, $circle, $params);
+ $this->parseCircleMemberAsMember($event, $circle, $params);
}
-
/**
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param IEvent $event
* @param array $params
*
- * @throws Exception
+ * @throws FakeException
+ * @throws InvalidItemException
*/
- private function parseAsModerator(IEvent $event, DeprecatedCircle $circle, $params) {
+ private function parseAsModerator(IEvent $event, Circle $circle, array $params): void {
if ($event->getType() !== 'circles_as_moderator') {
return;
}
$this->parseMemberAsModerator($event, $circle, $params);
- $this->parseGroupAsModerator($event, $circle, $params);
- $this->parseLinkAsModerator($event, $circle, $params);
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param array $params
*
* @throws FakeException
+ * @throws InvalidItemException
*/
- private function parseMemberAsMember(IEvent $event, DeprecatedCircle $circle, $params) {
+ private function parseMemberAsMember(
+ IEvent $event,
+ Circle $circle,
+ array $params
+ ): void {
if (!key_exists('member', $params)) {
return;
}
- $member = DeprecatedMember::fromJSON($params['member']);
+ /** @var Member $member */
+ $member = $this->deserializeJson($params['member'], Member::class);
$this->parserMember->parseSubjectMemberJoin($event, $circle, $member);
$this->parserMember->parseSubjectMemberAdd($event, $circle, $member);
@@ -204,72 +182,55 @@ private function parseMemberAsMember(IEvent $event, DeprecatedCircle $circle, $p
$this->parserMember->parseSubjectMemberRemove($event, $circle, $member);
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param array $params
*
* @throws FakeException
+ * @throws InvalidItemException
*/
- private function parseGroupAsModerator(IEvent $event, DeprecatedCircle $circle, $params) {
- if (!key_exists('group', $params)) {
+ private function parseCircleMemberAsMember(
+ IEvent $event,
+ Circle $circle,
+ array $params
+ ): void {
+ if (!key_exists('member', $params)) {
return;
}
- $group = DeprecatedMember::fromJSON($params['group']);
+ /** @var Member $member */
+ $member = $this->deserializeJson($params['member'], Member::class);
- $this->parserGroup->parseGroupLink($event, $circle, $group);
- $this->parserGroup->parseGroupUnlink($event, $circle, $group);
- $this->parserGroup->parseGroupLevel($event, $circle, $group);
+ $this->parserCircleMember->parseSubjectCircleMemberJoin($event, $circle, $member);
+ $this->parserCircleMember->parseSubjectCircleMemberAdd($event, $circle, $member);
+ $this->parserCircleMember->parseSubjectCircleMemberLeft($event, $circle, $member);
+ $this->parserCircleMember->parseSubjectCircleMemberRemove($event, $circle, $member);
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param array $params
*
* @throws FakeException
+ * @throws InvalidItemException
*/
- private function parseMemberAsModerator(IEvent $event, DeprecatedCircle $circle, $params) {
+ private function parseMemberAsModerator(
+ IEvent $event,
+ Circle $circle,
+ array $params
+ ): void {
if (!key_exists('member', $params)) {
return;
}
- $member = DeprecatedMember::fromJSON($params['member']);
+ /** @var Member $member */
+ $member = $this->deserializeJson($params['member'], Member::class);
$this->parserMember->parseMemberInvited($event, $circle, $member);
- $this->parserMember->parseMemberLevel($event, $circle, $member);
+ $this->parserMember->parseMemberLevel($event, $circle, $member, $params['level'] ?? 0);
$this->parserMember->parseMemberRequestInvitation($event, $circle, $member);
$this->parserMember->parseMemberOwner($event, $circle, $member);
}
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param array $params
- *
- * @throws FakeException
- */
- private function parseLinkAsModerator(IEvent $event, DeprecatedCircle $circle, $params) {
- if (!key_exists('link', $params)) {
- return;
- }
-
- $remote = FederatedLink::fromJSON($params['link']);
-
- $this->parserLink->parseLinkRequestSent($event, $circle, $remote);
- $this->parserLink->parseLinkRequestReceived($event, $circle, $remote);
- $this->parserLink->parseLinkRequestRejected($event, $circle, $remote);
- $this->parserLink->parseLinkRequestCanceled($event, $circle, $remote);
- $this->parserLink->parseLinkRequestAccepted($event, $circle, $remote);
- $this->parserLink->parseLinkRequestRemoved($event, $circle, $remote);
- $this->parserLink->parseLinkRequestCanceling($event, $circle, $remote);
- $this->parserLink->parseLinkRequestAccepting($event, $circle, $remote);
- $this->parserLink->parseLinkUp($event, $circle, $remote);
- $this->parserLink->parseLinkDown($event, $circle, $remote);
- $this->parserLink->parseLinkRemove($event, $circle, $remote);
- }
}
diff --git a/lib/Activity/ProviderParser.php b/lib/Activity/ProviderParser.php
index bef4b3a43..df461bfb6 100644
--- a/lib/Activity/ProviderParser.php
+++ b/lib/Activity/ProviderParser.php
@@ -1,5 +1,7 @@
- * @copyright 2017
+ * @copyright 2023
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -27,60 +29,39 @@
namespace OCA\Circles\Activity;
-use OCA\Circles\Api\v1\Circles;
-use OCA\Circles\Model\DeprecatedCircle;
-use OCA\Circles\Model\FederatedLink;
-use OCA\Circles\Model\DeprecatedMember;
-use OCA\Circles\Service\MiscService;
+use OCA\Circles\IFederatedUser;
+use OCA\Circles\Model\Circle;
+use OCA\Circles\Model\Member;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;
class ProviderParser {
- /** @var MiscService */
- protected $miscService;
-
- /** @var IL10N */
- protected $l10n;
-
- /** @var IURLGenerator */
- protected $url;
-
- /** @var IManager */
- protected $activityManager;
-
public function __construct(
- IURLGenerator $url, IManager $activityManager, IL10N $l10n, MiscService $miscService
+ protected IURLGenerator $url,
+ protected IManager $activityManager,
+ protected IL10N $l10n
) {
- $this->url = $url;
- $this->activityManager = $activityManager;
- $this->l10n = $l10n;
- $this->miscService = $miscService;
}
-
/**
- * general function to generate Circle event.
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink|null $remote
+ * @param Circle $circle
* @param string $ownEvent
* @param string $othersEvent
*/
- protected function parseCircleEvent(IEvent $event, DeprecatedCircle $circle, $remote, $ownEvent, $othersEvent
- ) {
+ protected function parseCircleEvent(
+ IEvent $event,
+ Circle $circle,
+ string $ownEvent,
+ string $othersEvent
+ ): void {
$data = [
'author' => $this->generateViewerParameter($circle),
'circle' => $this->generateCircleParameter($circle)
];
- $remoteCircle = $this->generateRemoteCircleParameter($remote);
- if ($remoteCircle !== null) {
- $data['remote'] = $remoteCircle;
- }
-
if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) {
$this->setSubject($event, $ownEvent, $data);
@@ -90,29 +71,35 @@ protected function parseCircleEvent(IEvent $event, DeprecatedCircle $circle, $re
$this->setSubject($event, $othersEvent, $data);
}
-
/**
* @param IEvent $event
* @param string $line
* @param array $data
*/
- protected function setSubject(IEvent $event, $line, $data) {
+ protected function setSubject(
+ IEvent $event,
+ string $line,
+ array $data
+ ): void {
$this->setParsedSubject($event, $line, $data);
$this->setRichSubject($event, $line, $data);
}
-
/**
* @param IEvent $event
* @param string $line
* @param array $data
*/
- protected function setRichSubject(IEvent $event, $line, $data) {
+ protected function setRichSubject(
+ IEvent $event,
+ string $line,
+ array $data
+ ): void {
$ak = array_keys($data);
foreach ($ak as $k) {
$subAk = array_keys($data[$k]);
foreach ($subAk as $sK) {
- if (substr($sK, 0, 1) === '_') {
+ if (str_starts_with($sK, '_')) {
unset($data[$k][$sK]);
}
}
@@ -121,13 +108,16 @@ protected function setRichSubject(IEvent $event, $line, $data) {
$event->setRichSubject($line, $data);
}
-
/**
* @param IEvent $event
* @param string $line
* @param array $data
*/
- protected function setParsedSubject(IEvent $event, $line, $data) {
+ protected function setParsedSubject(
+ IEvent $event,
+ string $line,
+ array $data
+ ): void {
$ak = array_keys($data);
$replace = [];
foreach ($ak as $k) {
@@ -138,24 +128,23 @@ protected function setParsedSubject(IEvent $event, $line, $data) {
$replace['{' . $k . '}'] = $data[$k]['_parsed'];
}
- $line = strtr($line, $replace);
-
- $event->setParsedSubject($line);
+ $event->setParsedSubject(strtr($line, $replace));
}
-
/**
- * general function to generate Member event.
- *
- * @param DeprecatedCircle $circle
- * @param $member
* @param IEvent $event
- * @param $ownEvent
- * @param $othersEvent
+ * @param Circle $circle
+ * @param Member $member
+ * @param string $ownEvent
+ * @param string $othersEvent
*/
protected function parseMemberEvent(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member, $ownEvent, $othersEvent
- ) {
+ IEvent $event,
+ Circle $circle,
+ Member $member,
+ string $ownEvent,
+ string $othersEvent
+ ): void {
$data = [
'circle' => $this->generateCircleParameter($circle),
'member' => $this->generateUserParameter($member)
@@ -171,38 +160,20 @@ protected function parseMemberEvent(
$this->setSubject($event, $othersEvent, $data);
}
-
- /**
- * general function to generate Link event.
- *
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- * @param IEvent $event
- * @param string $line
- */
- protected function parseLinkEvent(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote, $line
- ) {
- $data = [
- 'circle' => $this->generateCircleParameter($circle),
- 'remote' => $this->generateRemoteCircleParameter($remote)
- ];
-
- $this->setSubject($event, $line, $data);
- }
-
-
/**
- * general function to generate Circle+Member event.
- *
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
* @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
* @param string $ownEvent
* @param string $othersEvent
*/
protected function parseCircleMemberEvent(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member, $ownEvent, $othersEvent
- ) {
+ IEvent $event,
+ Circle $circle,
+ Member $member,
+ string $ownEvent,
+ string $othersEvent
+ ): void {
$data = [
'author' => $this->generateViewerParameter($circle),
'circle' => $this->generateCircleParameter($circle),
@@ -220,20 +191,24 @@ protected function parseCircleMemberEvent(
$this->setSubject($event, $othersEvent, $data);
}
-
/**
* general function to generate Circle+Member advanced event.
*
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
* @param IEvent $event
- * @param $ownEvent
- * @param $targetEvent
- * @param $othersEvent
+ * @param Circle $circle
+ * @param Member $member
+ * @param string $ownEvent
+ * @param string $targetEvent
+ * @param string $othersEvent
*/
protected function parseCircleMemberAdvancedEvent(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member, $ownEvent, $targetEvent, $othersEvent
- ) {
+ IEvent $event,
+ Circle $circle,
+ Member $member,
+ string $ownEvent,
+ string $targetEvent,
+ string $othersEvent
+ ): void {
$data = [
'author' => $this->generateViewerParameter($circle),
'circle' => $this->generateCircleParameter($circle),
@@ -255,98 +230,70 @@ protected function parseCircleMemberAdvancedEvent(
$this->setSubject($event, $othersEvent, $data);
}
-
/**
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
* @param string $userId
*
* @return bool
*/
- protected function isViewerTheAuthor(DeprecatedCircle $circle, $userId) {
- if ($circle->getViewer() === null) {
+ protected function isViewerTheAuthor(Circle $circle, string $userId): bool {
+ if (!$circle->hasInitiator()) {
return false;
}
- if ($circle->getViewer()
- ->getUserId() === $userId) {
- return true;
- }
+ $initiator = $circle->getInitiator();
- return false;
+ return ($initiator->getUserType() === Member::TYPE_USER
+ && $initiator->getUserId() === $userId);
}
-
/**
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
*
- * @return string|array
+ * @return array
*/
- protected function generateViewerParameter(DeprecatedCircle $circle) {
- if ($circle->getViewer() === null) {
+ protected function generateViewerParameter(Circle $circle): array {
+ if (!$circle->hasInitiator()) {
return [];
}
- return $this->generateUserParameter($circle->getViewer());
+ return $this->generateUserParameter($circle->getInitiator());
}
-
/**
- * @param DeprecatedMember $member
+ * @param Member $member
*
- * @return array|string
+ * @return array
*/
- protected function generateExternalMemberParameter(DeprecatedMember $member) {
+ protected function generateExternalMemberParameter(Member $member): array {
return [
- 'type' => $member->getTypeName(),
+ 'type' => Member::$TYPE[$member->getUserType()] ?? '',
'id' => $member->getUserId(),
- 'name' => $member->getCachedName() . ' (' . $member->getTypeString() . ')',
- '_parsed' => $member->getCachedName()
+ 'name' => $member->getDisplayName() . ' (' . (Member::$TYPE[$member->getUserType()] ?? '') . ')',
+ '_parsed' => $member->getDisplayName()
];
}
-
/**
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
*
* @return array
*/
- protected function generateCircleParameter(DeprecatedCircle $circle) {
+ protected function generateCircleParameter(Circle $circle): array {
return [
'type' => 'circle',
- 'id' => $circle->getId(),
+ 'id' => $circle->getSingleId(),
'name' => $circle->getName(),
'_parsed' => $circle->getName(),
- 'link' => Circles::generateAbsoluteLink($circle->getUniqueId())
+ 'link' => $circle->getUrl()
];
}
-
/**
- * @param FederatedLink $link
- *
- * @return array
- */
- protected function generateRemoteCircleParameter($link) {
- if ($link === null) {
- return null;
- }
-
- return [
- 'type' => 'circle',
- 'id' => $link->getUniqueId(),
- 'name' => $link->getToken() . '@' . $link->getAddress(),
- '_parsed' => $link->getToken() . '@' . $link->getAddress()
- ];
- }
-
-
- /**
- * @param DeprecatedMember $member
- *
* @return array
*/
- protected function generateUserParameter(DeprecatedMember $member) {
- $display = $member->getCachedName();
+ protected function generateUserParameter(IFederatedUser $member): array {
+ $display = $member->getDisplayName();
if ($display === '') {
$display = $member->getUserId();
}
@@ -359,13 +306,10 @@ protected function generateUserParameter(DeprecatedMember $member) {
];
}
-
/**
- * @param DeprecatedMember $group
- *
* @return array
*/
- protected function generateGroupParameter($group) {
+ protected function generateGroupParameter(Member $group): array {
return [
'type' => 'user-group',
'id' => $group->getUserId(),
diff --git a/lib/Activity/ProviderSubjectCircle.php b/lib/Activity/ProviderSubjectCircle.php
index 55cbeee3b..f9837d7e0 100644
--- a/lib/Activity/ProviderSubjectCircle.php
+++ b/lib/Activity/ProviderSubjectCircle.php
@@ -1,4 +1,7 @@
- * @copyright 2017
+ * @copyright 2023
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -24,27 +27,26 @@
*
*/
-
namespace OCA\Circles\Activity;
use OCA\Circles\Exceptions\FakeException;
-use OCA\Circles\Model\DeprecatedCircle;
+use OCA\Circles\Model\Circle;
use OCP\Activity\IEvent;
class ProviderSubjectCircle extends ProviderParser {
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
*
* @throws FakeException
*/
- public function parseSubjectCircleCreate(IEvent $event, DeprecatedCircle $circle) {
+ public function parseSubjectCircleCreate(IEvent $event, Circle $circle): void {
if ($event->getSubject() !== 'circle_create') {
return;
}
$this->parseCircleEvent(
- $event, $circle, null,
+ $event, $circle,
$this->l10n->t('You created the circle {circle}'),
$this->l10n->t('{author} created the circle {circle}')
);
@@ -52,20 +54,19 @@ public function parseSubjectCircleCreate(IEvent $event, DeprecatedCircle $circle
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
+ * @param Circle $circle
*
* @throws FakeException
*/
- public function parseSubjectCircleDelete(IEvent $event, DeprecatedCircle $circle) {
+ public function parseSubjectCircleDelete(IEvent $event, Circle $circle): void {
if ($event->getSubject() !== 'circle_delete') {
return;
}
$this->parseCircleEvent(
- $event, $circle, null,
+ $event, $circle,
$this->l10n->t('You deleted {circle}'),
$this->l10n->t('{author} deleted {circle}')
);
diff --git a/lib/Activity/ProviderSubjectCircleMember.php b/lib/Activity/ProviderSubjectCircleMember.php
new file mode 100644
index 000000000..6df9b7ffa
--- /dev/null
+++ b/lib/Activity/ProviderSubjectCircleMember.php
@@ -0,0 +1,168 @@
+
+ * @copyright 2023
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+namespace OCA\Circles\Activity;
+
+use OCA\Circles\Exceptions\FakeException;
+use OCA\Circles\Model\Circle;
+use OCA\Circles\Model\Member;
+use OCP\Activity\IEvent;
+
+class ProviderSubjectCircleMember extends ProviderParser {
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @param string $ownEvent
+ * @param string $othersEvent
+ * @return void
+ */
+ protected function parseMemberCircleEvent(
+ IEvent $event,
+ Circle $circle,
+ Member $member,
+ string $ownEvent,
+ string $othersEvent
+ ): void {
+ $data = [
+ 'author' => $this->generateViewerParameter($circle),
+ 'circle' => $this->generateCircleParameter($circle),
+ 'member' => $this->generateUserParameter($member),
+ 'external' => $this->generateExternalMemberParameter($member),
+ 'group' => $this->generateGroupParameter($member),
+ ];
+
+ if ($this->isViewerTheAuthor($circle, $this->activityManager->getCurrentUserId())) {
+ $this->setSubject($event, $ownEvent, $data);
+
+ return;
+ }
+
+ $this->setSubject($event, $othersEvent, $data);
+ }
+
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @throws FakeException
+ */
+ public function parseSubjectCircleMemberJoin(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($event->getSubject() !== 'member_circle_joined') {
+ return;
+ }
+
+ $this->parseMemberCircleEvent(
+ $event, $circle, $member,
+ $this->l10n->t('You made {member} join {circle}'),
+ $this->l10n->t('{author} made {member} join {circle}')
+ );
+
+ throw new FakeException();
+ }
+
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @return void
+ * @throws FakeException
+ */
+ public function parseSubjectCircleMemberAdd(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($event->getSubject() !== 'member_circle_added') {
+ return;
+ }
+
+ $this->parseMemberCircleEvent(
+ $event, $circle, $member,
+ $this->l10n->t('You added circle {member} as member to {circle}'),
+ $this->l10n->t('{author} added circle {member} has been added as member to {circle}')
+ );
+
+ throw new FakeException();
+ }
+
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @return void
+ * @throws FakeException
+ */
+ public function parseSubjectCircleMemberLeft(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($event->getSubject() !== 'member_circle_left') {
+ return;
+ }
+
+ $this->parseCircleMemberEvent(
+ $event, $circle, $member,
+ $this->l10n->t('You made {member} leave {circle}'),
+ $this->l10n->t('{author} made {member} leave {circle}')
+ );
+
+ throw new FakeException();
+ }
+
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @return void
+ * @throws FakeException
+ */
+ public function parseSubjectCircleMemberRemove(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($event->getSubject() !== 'member_circle_removed') {
+ return;
+ }
+
+ $this->parseCircleMemberEvent(
+ $event, $circle, $member,
+ $this->l10n->t('You removed {member} leave {circle}'),
+ $this->l10n->t('{author} made {member} leave {circle}')
+ );
+
+ throw new FakeException();
+ }
+}
diff --git a/lib/Activity/ProviderSubjectGroup.php b/lib/Activity/ProviderSubjectGroup.php
deleted file mode 100644
index 08dfa2251..000000000
--- a/lib/Activity/ProviderSubjectGroup.php
+++ /dev/null
@@ -1,101 +0,0 @@
-
- * @copyright 2017
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-
-namespace OCA\Circles\Activity;
-
-use OCA\Circles\Exceptions\FakeException;
-use OCA\Circles\Model\DeprecatedCircle;
-use OCA\Circles\Model\DeprecatedMember;
-use OCP\Activity\IEvent;
-
-class ProviderSubjectGroup extends ProviderParser {
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $group
- *
- * @throws FakeException
- */
- public function parseGroupLink(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $group) {
- if ($event->getSubject() !== 'group_link') {
- return;
- }
-
- $this->parseCircleMemberEvent(
- $event, $circle, $group,
- $this->l10n->t('You linked {group} to {circle}'),
- $this->l10n->t('{group} has been linked to {circle} by {author}')
- );
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $group
- *
- * @throws FakeException
- */
- public function parseGroupUnlink(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $group) {
- if ($event->getSubject() !== 'group_unlink') {
- return;
- }
- $this->parseCircleMemberEvent(
- $event, $circle, $group,
- $this->l10n->t('You unlinked {group} from {circle}'),
- $this->l10n->t('{group} has been unlinked from {circle} by {author}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $group
- *
- * @throws FakeException
- */
- public function parseGroupLevel(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $group) {
- if ($event->getSubject() !== 'group_level') {
- return;
- }
-
- $l = $this->l10n;
-
- $level = [$l->t($group->getLevelString())];
- $this->parseCircleMemberEvent(
- $event, $circle, $group,
- $l->t('You changed the level of the linked group {group} in {circle} to %1$s', $level),
- $l->t('{author} changed the level of the linked group {group} in {circle} to %1$s', $level)
- );
-
- throw new FakeException();
- }
-}
diff --git a/lib/Activity/ProviderSubjectLink.php b/lib/Activity/ProviderSubjectLink.php
deleted file mode 100644
index 075ba87c8..000000000
--- a/lib/Activity/ProviderSubjectLink.php
+++ /dev/null
@@ -1,273 +0,0 @@
-
- * @copyright 2017
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-
-namespace OCA\Circles\Activity;
-
-use OCA\Circles\Exceptions\FakeException;
-use OCA\Circles\Model\DeprecatedCircle;
-use OCA\Circles\Model\FederatedLink;
-use OCP\Activity\IEvent;
-
-class ProviderSubjectLink extends ProviderParser {
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestSent(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_sent') {
- return;
- }
-
- $this->parseCircleEvent(
- $event, $circle, $remote,
- $this->l10n->t('You sent a request to link {circle} with {remote}'),
- $this->l10n->t('{author} sent a request to link {circle} with {remote}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestReceived(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_received') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote, $this->l10n->t('{remote} requested a link with {circle}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestRejected(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_rejected') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote,
- $this->l10n->t('The request to link {circle} with {remote} has been rejected')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestCanceled(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_canceled') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote,
- $this->l10n->t(
- 'The request to link {remote} with {circle} has been canceled remotely'
- )
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestAccepted(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_accepted') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote,
- $this->l10n->t('The request to link {circle} with {remote} has been accepted')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestRemoved(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_removed') {
- return;
- }
-
- $this->parseCircleEvent(
- $event, $circle, $remote,
- $this->l10n->t('You dismissed the request to link {remote} with {circle}'),
- $this->l10n->t('{author} dismissed the request to link {remote} with {circle}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestCanceling(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_canceling') {
- return;
- }
-
- $this->parseCircleEvent(
- $event, $circle, $remote,
- $this->l10n->t('You canceled the request to link {circle} with {remote}'),
- $this->l10n->t('{author} canceled the request to link {circle} with {remote}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRequestAccepting(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_request_accepting') {
- return;
- }
-
- $this->parseCircleEvent(
- $event, $circle, $remote,
- $this->l10n->t('You accepted the request to link {remote} with {circle}'),
- $this->l10n->t('{author} accepted the request to link {remote} with {circle}')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkUp(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_up') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote,
- $this->l10n->t('A link between {circle} and {remote} is now up and running')
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkDown(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_down') {
- return;
- }
-
- $this->parseLinkEvent(
- $event, $circle, $remote,
- $this->l10n->t(
- 'The link between {circle} and {remote} has been shutdown remotely'
- )
- );
-
- throw new FakeException();
- }
-
-
- /**
- * @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param FederatedLink $remote
- *
- * @throws FakeException
- */
- public function parseLinkRemove(IEvent $event, DeprecatedCircle $circle, FederatedLink $remote) {
- if ($event->getSubject() !== 'link_remove') {
- return;
- }
-
- $this->parseCircleEvent(
- $event, $circle, $remote,
- $this->l10n->t('You closed the link between {circle} and {remote}'),
- $this->l10n->t('{author} closed the link between {circle} and {remote}')
- );
-
- throw new FakeException();
- }
-}
diff --git a/lib/Activity/ProviderSubjectMember.php b/lib/Activity/ProviderSubjectMember.php
index e8e7de2b6..7e7b7010f 100644
--- a/lib/Activity/ProviderSubjectMember.php
+++ b/lib/Activity/ProviderSubjectMember.php
@@ -1,4 +1,7 @@
- * @copyright 2017
+ * @copyright 2023
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
@@ -24,31 +27,31 @@
*
*/
-
namespace OCA\Circles\Activity;
use OCA\Circles\Exceptions\FakeException;
-use OCA\Circles\Model\DeprecatedCircle;
-use OCA\Circles\Model\DeprecatedMember;
+use OCA\Circles\Model\Circle;
+use OCA\Circles\Model\Member;
use OCP\Activity\IEvent;
class ProviderSubjectMember extends ProviderParser {
/**
- * Parse on Subject 'member_join'.
- * If circle is closed, we say that user accepted his invitation.
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseSubjectMemberJoin(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseSubjectMemberJoin(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
if ($event->getSubject() !== 'member_join') {
return;
}
- $this->parseSubjectMemberJoinClosedCircle($event, $circle, $member);
+ $this->parseSubjectMemberJoinOnInvite($event, $circle, $member);
$this->parseCircleMemberEvent(
$event, $circle, $member, $this->l10n->t('You joined {circle}'),
$this->l10n->t('{member} joined {circle}')
@@ -57,16 +60,19 @@ public function parseSubjectMemberJoin(IEvent $event, DeprecatedCircle $circle,
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- private function parseSubjectMemberJoinClosedCircle(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
- if ($circle->getType() !== DeprecatedCircle::CIRCLES_CLOSED) {
+ private function parseSubjectMemberJoinOnInvite(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if (!$circle->isConfig(Circle::CFG_INVITE)) {
return;
}
@@ -81,17 +87,18 @@ private function parseSubjectMemberJoinClosedCircle(IEvent $event, DeprecatedCir
/**
- * Parse on Subject 'member_add'.
- * If circle is closed, we say that user's invitation was accepted.
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseSubjectMemberAdd(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
- if ($event->getSubject() !== 'member_add') {
+ public function parseSubjectMemberAdd(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($event->getSubject() !== 'member_added') {
return;
}
@@ -107,17 +114,19 @@ public function parseSubjectMemberAdd(IEvent $event, DeprecatedCircle $circle, D
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- private function parseSubjectMemberAddNotLocalMember(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member
- ) {
- if ($member->getType() === DeprecatedMember::TYPE_USER) {
+ private function parseSubjectMemberAddNotLocalMember(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($member->getUserType() === Member::TYPE_USER) {
return;
}
@@ -133,13 +142,17 @@ private function parseSubjectMemberAddNotLocalMember(IEvent $event, DeprecatedCi
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- private function parseSubjectMemberAddClosedCircle(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
- if ($circle->getType() !== DeprecatedCircle::CIRCLES_CLOSED) {
+ private function parseSubjectMemberAddClosedCircle(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if (!$circle->isConfig(Circle::CFG_REQUEST)) {
return;
}
@@ -155,22 +168,23 @@ private function parseSubjectMemberAddClosedCircle(IEvent $event, DeprecatedCirc
/**
- * Parse on Subject 'member_left'.
- * If circle is closed and member was not a real member, we send him to
- * parseSubjectNonMemberLeftClosedCircle();
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseSubjectMemberLeft(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseSubjectMemberLeft(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
if ($event->getSubject() !== 'member_left') {
return;
}
- $this->parseSubjectNonMemberLeftClosedCircle($event, $circle, $member);
+ $this->parseSubjectNonMemberLeftInvite($event, $circle, $member);
+ $this->parseSubjectNonMemberLeftRequest($event, $circle, $member);
$this->parseCircleMemberEvent(
$event, $circle, $member,
$this->l10n->t('You left {circle}'),
@@ -182,53 +196,71 @@ public function parseSubjectMemberLeft(IEvent $event, DeprecatedCircle $circle,
/**
- * Parse on Subject 'member_left' on a closed circle when user were not yet a member.
- * If status is Invited we say that member rejected his invitation.
- * If status is Requested we say he dismissed his request.
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- private function parseSubjectNonMemberLeftClosedCircle(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member
- ) {
- if ($circle->getType() !== DeprecatedCircle::CIRCLES_CLOSED
- || $member->getLevel() !== DeprecatedMember::LEVEL_NONE) {
+ private function parseSubjectNonMemberLeftInvite(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if (!$circle->isConfig(Circle::CFG_INVITE)
+ || $member->getLevel() > Member::LEVEL_NONE) {
return;
}
- if ($member->getStatus() === DeprecatedMember::STATUS_INVITED) {
- $this->parseCircleMemberEvent(
- $event, $circle, $member,
- $this->l10n->t("You declined the invitation to join {circle}"),
- $this->l10n->t("{member} declined an invitation to join {circle}")
- );
- } else {
- $this->parseCircleMemberEvent(
- $event, $circle, $member,
- $this->l10n->t("You cancelled your request to join {circle}"),
- $this->l10n->t("{member} cancelled his request to join {circle}")
- );
- }
+ $this->parseCircleMemberEvent(
+ $event, $circle, $member,
+ $this->l10n->t("You declined the invitation to join {circle}"),
+ $this->l10n->t("{member} declined an invitation to join {circle}")
+ );
throw new FakeException();
}
/**
- * Parse on Subject 'member_remove'.
- * If circle is closed and member was not a real member, we send him to
- * parseSubjectNonMemberRemoveClosedCircle();
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
*
+ * @throws FakeException
+ */
+ private function parseSubjectNonMemberLeftRequest(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if (!$circle->isConfig(Circle::CFG_REQUEST)
+ || $member->getLevel() > Member::LEVEL_NONE) {
+ return;
+ }
+
+ $this->parseCircleMemberEvent(
+ $event, $circle, $member,
+ $this->l10n->t("You cancelled your request to join {circle}"),
+ $this->l10n->t("{member} cancelled a request to join {circle}")
+ );
+
+ throw new FakeException();
+ }
+
+
+ /**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseSubjectMemberRemove(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseSubjectMemberRemove(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
if ($event->getSubject() !== 'member_remove') {
return;
}
@@ -245,18 +277,19 @@ public function parseSubjectMemberRemove(IEvent $event, DeprecatedCircle $circle
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
private function parseSubjectMemberRemoveNotLocalMember(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member
- ) {
- if ($member->getType() === DeprecatedMember::TYPE_USER) {
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($member->getUserType() === Member::TYPE_USER) {
return;
}
@@ -271,21 +304,19 @@ private function parseSubjectMemberRemoveNotLocalMember(
/**
- * Parse on Subject 'member_remove' on a closed circle when user were not yet a member.
- * If status is Invited we say that author cancelled his invitation.
- * If status is Requested we say that his invitation was rejected.
- *
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
private function parseSubjectMemberRemoveNotYetMember(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member
- ) {
- if ($circle->getType() !== DeprecatedCircle::CIRCLES_CLOSED
- || $member->getLevel() !== DeprecatedMember::LEVEL_NONE) {
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if (!$circle->isConfig(Circle::CFG_INVITE)
+ || $member->getLevel() > Member::LEVEL_NONE) {
return;
}
@@ -300,11 +331,18 @@ private function parseSubjectMemberRemoveNotYetMember(
throw new FakeException();
}
-
+ /**
+ * @param IEvent $event
+ * @param Circle $circle
+ * @param Member $member
+ * @throws FakeException
+ */
private function parseSubjectMemberRemoveNotYetMemberRequesting(
- IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member
- ) {
- if ($member->getStatus() !== DeprecatedMember::STATUS_REQUEST) {
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
+ if ($member->getStatus() !== Member::STATUS_REQUEST) {
return;
}
@@ -318,15 +356,13 @@ private function parseSubjectMemberRemoveNotYetMemberRequesting(
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
- *
+ * @param Circle $circle
+ * @param Member $member
* @throws FakeException
*/
- public function parseMemberInvited(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseMemberInvited(IEvent $event, Circle $circle, Member $member): void {
if ($event->getSubject() !== 'member_invited') {
return;
}
@@ -344,22 +380,27 @@ public function parseMemberInvited(IEvent $event, DeprecatedCircle $circle, Depr
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
- *
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $level
* @throws FakeException
*/
- public function parseMemberLevel(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseMemberLevel(
+ IEvent $event,
+ Circle $circle,
+ Member $member,
+ int $level
+ ): void {
if ($event->getSubject() !== 'member_level') {
return;
}
- $level = [$this->l10n->t($member->getLevelString())];
+ $levelString = $this->l10n->t(Member::$DEF_LEVEL[$level] ?? '');
$this->parseCircleMemberAdvancedEvent(
$event, $circle, $member,
- $this->l10n->t('You changed {member}\'s level in {circle} to %1$s', $level),
- $this->l10n->t('{author} changed your level in {circle} to %1$s', $level),
- $this->l10n->t('{author} changed {member}\'s level in {circle} to %1$s', $level)
+ $this->l10n->t('You changed {member}\'s level in {circle} to %1$s', [$levelString]),
+ $this->l10n->t('{author} changed your level in {circle} to %1$s', [$levelString]),
+ $this->l10n->t('{author} changed {member}\'s level in {circle} to %1$s', [$levelString])
);
throw new FakeException();
@@ -368,12 +409,16 @@ public function parseMemberLevel(IEvent $event, DeprecatedCircle $circle, Deprec
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseMemberRequestInvitation(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseMemberRequestInvitation(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
if ($event->getSubject() !== 'member_request_invitation') {
return;
}
@@ -387,15 +432,18 @@ public function parseMemberRequestInvitation(IEvent $event, DeprecatedCircle $ci
throw new FakeException();
}
-
/**
* @param IEvent $event
- * @param DeprecatedCircle $circle
- * @param DeprecatedMember $member
+ * @param Circle $circle
+ * @param Member $member
*
* @throws FakeException
*/
- public function parseMemberOwner(IEvent $event, DeprecatedCircle $circle, DeprecatedMember $member) {
+ public function parseMemberOwner(
+ IEvent $event,
+ Circle $circle,
+ Member $member
+ ): void {
if ($event->getSubject() !== 'member_owner') {
return;
}
diff --git a/lib/Activity/SettingAsMember.php b/lib/Activity/SettingAsMember.php
index 3714b766b..f9e3e8923 100644
--- a/lib/Activity/SettingAsMember.php
+++ b/lib/Activity/SettingAsMember.php
@@ -6,15 +6,9 @@
use OCP\IL10N;
class SettingAsMember implements ISetting {
- /** @var IL10N */
- protected $l10n;
-
-
- /**
- * @param IL10N $l10n
- */
- public function __construct(IL10N $l10n) {
- $this->l10n = $l10n;
+ public function __construct(
+ protected IL10N $l10n
+ ) {
}
diff --git a/lib/Activity/SettingAsModerator.php b/lib/Activity/SettingAsModerator.php
index 16d7d79af..a098cbbc0 100644
--- a/lib/Activity/SettingAsModerator.php
+++ b/lib/Activity/SettingAsModerator.php
@@ -1,19 +1,41 @@
+ * @copyright 2023
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
namespace OCA\Circles\Activity;
use OCP\Activity\ISetting;
use OCP\IL10N;
class SettingAsModerator implements ISetting {
- /** @var IL10N */
- protected $l10n;
-
- /**
- * @param IL10N $l10n
- */
- public function __construct(IL10N $l10n) {
- $this->l10n = $l10n;
+ public function __construct(
+ protected IL10N $l10n
+ ) {
}
/**
diff --git a/lib/Activity/SettingAsNonMember.php b/lib/Activity/SettingAsNonMember.php
index 3ededa315..f7e6953e2 100644
--- a/lib/Activity/SettingAsNonMember.php
+++ b/lib/Activity/SettingAsNonMember.php
@@ -1,25 +1,41 @@
+ * @copyright 2023
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
*
- * @package OCA\Circles\Activity
*/
-class SettingAsNonMember implements ISetting {
- /** @var IL10N */
- protected $l10n;
+namespace OCA\Circles\Activity;
- /**
- * @param IL10N $l10n
- */
- public function __construct(IL10N $l10n) {
- $this->l10n = $l10n;
+use OCP\Activity\ISetting;
+use OCP\IL10N;
+
+class SettingAsNonMember implements ISetting {
+ public function __construct(
+ protected IL10N $l10n
+ ) {
}
diff --git a/lib/Events/CircleGenericEvent.php b/lib/Events/CircleGenericEvent.php
index c84efe71c..814fb9cb3 100644
--- a/lib/Events/CircleGenericEvent.php
+++ b/lib/Events/CircleGenericEvent.php
@@ -35,39 +35,22 @@
use OCA\Circles\Model\Federated\FederatedEvent;
use OCP\EventDispatcher\Event;
-/**
- * Class CircleMemberAddedEvent
- *
- * @package OCA\Circles\Events
- */
class CircleGenericEvent extends Event {
public const INVITED = 1;
public const JOINED = 2;
- /** @deprecated */
- public const MULTIPLE = 3;
+ public const ADDED = 3;
public const REMOVED = 4;
public const LEFT = 5;
public const LEVEL = 6;
public const NAME = 7;
public const REQUESTED = 8;
+ private Circle $circle;
- /** @var FederatedEvent */
- private $federatedEvent;
-
- /** @var Circle */
- private $circle;
-
-
- /**
- * CircleMemberAddedEvent constructor.
- *
- * @param FederatedEvent $federatedEvent
- */
- public function __construct(FederatedEvent $federatedEvent) {
+ public function __construct(
+ private FederatedEvent $federatedEvent
+ ) {
parent::__construct();
-
- $this->federatedEvent = $federatedEvent;
$this->circle = $federatedEvent->getCircle();
}
diff --git a/lib/FederatedItems/SingleMemberAdd.php b/lib/FederatedItems/SingleMemberAdd.php
index 98b441f16..f433d4945 100644
--- a/lib/FederatedItems/SingleMemberAdd.php
+++ b/lib/FederatedItems/SingleMemberAdd.php
@@ -31,9 +31,6 @@
namespace OCA\Circles\FederatedItems;
-use OCA\Circles\Tools\Traits\TDeserialize;
-use OCA\Circles\Tools\Traits\TNCLogger;
-use OCA\Circles\Tools\Traits\TStringTools;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Exceptions\CircleNotFoundException;
use OCA\Circles\Exceptions\FederatedItemBadRequestException;
@@ -73,6 +70,9 @@
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Service\RemoteStreamService;
use OCA\Circles\StatusCode;
+use OCA\Circles\Tools\Traits\TDeserialize;
+use OCA\Circles\Tools\Traits\TNCLogger;
+use OCA\Circles\Tools\Traits\TStringTools;
use OCP\IUserManager;
/**
@@ -87,73 +87,20 @@ class SingleMemberAdd implements
IFederatedItemMemberRequired,
IFederatedItemMemberCheckNotRequired {
use TDeserialize;
-
-
use TStringTools;
use TNCLogger;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var MemberRequest */
- protected $memberRequest;
-
- /** @var FederatedUserService */
- protected $federatedUserService;
-
- /** @var RemoteStreamService */
- protected $remoteStreamService;
-
- /** @var CircleService */
- protected $circleService;
-
- /** @var MemberService */
- protected $memberService;
-
- /** @var MembershipService */
- protected $membershipService;
-
- /** @var EventService */
- protected $eventService;
-
- /** @var ConfigService */
- protected $configService;
-
-
- /**
- * SingleMemberAdd constructor.
- *
- * @param IUserManager $userManager
- * @param MemberRequest $memberRequest
- * @param FederatedUserService $federatedUserService
- * @param RemoteStreamService $remoteStreamService
- * @param CircleService $circleService
- * @param MemberService $memberService
- * @param MembershipService $membershipService
- * @param EventService $eventService
- * @param ConfigService $configService
- */
public function __construct(
- IUserManager $userManager,
- MemberRequest $memberRequest,
- FederatedUserService $federatedUserService,
- RemoteStreamService $remoteStreamService,
- CircleService $circleService,
- MemberService $memberService,
- MembershipService $membershipService,
- EventService $eventService,
- ConfigService $configService
+ protected IUserManager $userManager,
+ protected MemberRequest $memberRequest,
+ protected FederatedUserService $federatedUserService,
+ protected RemoteStreamService $remoteStreamService,
+ protected CircleService $circleService,
+ protected MemberService $memberService,
+ protected MembershipService $membershipService,
+ protected EventService $eventService,
+ protected ConfigService $configService
) {
- $this->userManager = $userManager;
- $this->memberRequest = $memberRequest;
- $this->federatedUserService = $federatedUserService;
- $this->remoteStreamService = $remoteStreamService;
- $this->circleService = $circleService;
- $this->memberService = $memberService;
- $this->membershipService = $membershipService;
- $this->eventService = $eventService;
- $this->configService = $configService;
}
@@ -207,27 +154,6 @@ public function manage(FederatedEvent $event): void {
}
$this->membershipService->updatePopulation($event->getCircle());
-
-// //
-// // TODO: verifiez comment se passe le cached name sur un member_add
-// //
-// $cachedName = $member->getCachedName();
-// $password = $event->getData()
-// ->g('password');
-//
-// $shares = $this->generateUnknownSharesLinks($circle, $member, $password);
-// $result = [
-// 'unknownShares' => $shares,
-// 'cachedName' => $cachedName
-// ];
-//
-// if ($member->getType() === DeprecatedMember::TYPE_CONTACT
-// && $this->configService->isLocalInstance($member->getInstance())) {
-// $result['contact'] = $this->miscService->getInfosFromContact($member);
-// }
-//
-// $event->setResult(new SimpleDataStore($result));
-// $this->eventsService->onMemberNew($circle, $member);
}
@@ -237,54 +163,12 @@ public function manage(FederatedEvent $event): void {
*/
public function result(FederatedEvent $event, array $results): void {
$member = $event->getMember();
+ \OC::$server->getLogger()->log(3, '>> ' . $member->getStatus());
if ($member->getStatus() === Member::STATUS_INVITED) {
$this->eventService->memberInvited($event, $results);
} else {
$this->eventService->memberAdded($event, $results);
}
-
-// $password = $cachedName = '';
-// $circle = $member = null;
-// $links = [];
-// $recipients = [];
-// foreach ($events as $event) {
-// $data = $event->getData();
-// if ($data->gBool('passwordByMail') !== false) {
-// $password = $data->g('password');
-// }
-// $circle = $event->getDeprecatedCircle();
-// $member = $event->getMember();
-// $result = $event->getResult();
-// if ($result->g('cachedName') !== '') {
-// $cachedName = $result->g('cachedName');
-// }
-//
-// $links = array_merge($links, $result->gArray('unknownShares'));
-// $contact = $result->gArray('contact');
-// if (!empty($contact)) {
-// $recipients = $contact['emails'];
-// }
-// }
-//
-// if (empty($links) || $circle === null || $member === null) {
-// return;
-// }
-//
-// if ($cachedName !== '') {
-// $member->setCachedName($cachedName);
-// $this->membersService->updateMember($member);
-// }
-//
-// if ($member->getType() === DeprecatedMember::TYPE_MAIL
-// || $member->getType() === DeprecatedMember::TYPE_CONTACT) {
-// if ($member->getType() === DeprecatedMember::TYPE_MAIL) {
-// $recipients = [$member->getUserId()];
-// }
-//
-// foreach ($recipients as $recipient) {
-// $this->memberIsMailbox($circle, $recipient, $links, $password);
-// }
-// }
}
diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php
index 57933f038..3477133a4 100644
--- a/lib/Model/Circle.php
+++ b/lib/Model/Circle.php
@@ -86,11 +86,9 @@ class Circle extends ManagedModel implements IEntity, IDeserializable, IQueryRow
use TArrayTools;
use TDeserialize;
-
public const FLAGS_SHORT = 1;
public const FLAGS_LONG = 2;
-
// specific value
public const CFG_CIRCLE = 0; // only for code readability. Circle is locked by default.
public const CFG_SINGLE = 1; // Circle with only one single member.
diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php
new file mode 100644
index 000000000..347d96a10
--- /dev/null
+++ b/lib/Service/ActivityService.php
@@ -0,0 +1,375 @@
+
+ * @copyright 2023
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+namespace OCA\Circles\Service;
+
+use OCA\Circles\AppInfo\Application;
+use OCA\Circles\Db\MemberRequest;
+use OCA\Circles\Events\CircleGenericEvent;
+use OCA\Circles\IFederatedUser;
+use OCA\Circles\Model\Circle;
+use OCA\Circles\Model\Federated\FederatedEvent;
+use OCA\Circles\Model\Member;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager as IActivityManager;
+use OCP\IUser;
+use OCP\IUserManager;
+use UnhandledMatchError;
+
+class ActivityService {
+ public function __construct(
+ private IActivityManager $activityManager,
+ private IUserManager $userManager,
+ private MemberRequest $memberRequest,
+ private ConfigService $configService
+ ) {
+ }
+
+ /**
+ * @param Circle $circle
+ */
+ public function onCircleCreation(Circle $circle): void {
+ if ($circle->isConfig(Circle::CFG_PERSONAL)
+ || !$this->configService->getAppValueBool(ConfigService::ACTIVITY_ON_NEW_CIRCLE)) {
+ return;
+ }
+
+ $event = $this->generateEvent('circles_as_non_member');
+ $event->setSubject('circle_create', ['circle' => json_encode($circle)]);
+
+ $this->userManager->callForSeenUsers(
+ function ($user) use ($event) {
+ /** @var IUser $user */
+ $this->publishEvent($event, [$user]);
+ }
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ */
+ public function onCircleDestruction(Circle $circle): void {
+ if ($circle->isConfig(Circle::CFG_PERSONAL)) {
+ return;
+ }
+
+ $event = $this->generateEvent('circles_as_member');
+ $event->setSubject('circle_delete', ['circle' => json_encode($circle)]);
+ $this->publishEvent(
+ $event,
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MEMBER)
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $eventType
+ */
+ public function onMemberNew(
+ Circle $circle,
+ Member $member,
+ int $eventType
+ ): void {
+ if ($circle->isConfig(Circle::CFG_PERSONAL)) {
+ return;
+ }
+
+ if ($member->getLevel() === Member::LEVEL_NONE) {
+ $this->onMemberAlmost($circle, $member, $eventType);
+ return;
+ }
+
+ switch ($member->getUserType()) {
+ case Member::TYPE_USER:
+ case Member::TYPE_MAIL:
+ case Member::TYPE_CONTACT:
+ $this->onMemberNewAccount($circle, $member, $eventType);
+ break;
+
+ case Member::TYPE_CIRCLE:
+ $this->onMemberNewCircle(
+ $circle,
+ $member,
+ $eventType
+ );
+ break;
+ }
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $eventType
+ */
+ private function onMemberNewAccount(
+ Circle $circle,
+ Member $member,
+ int $eventType
+ ): void {
+ $event = $this->generateEvent('circles_as_member');
+
+ try {
+ $event->setSubject(
+ match ($eventType) {
+ CircleGenericEvent::ADDED => 'member_added',
+ CircleGenericEvent::JOINED => 'member_join'
+ },
+ [
+ 'circle' => json_encode($circle),
+ 'member' => json_encode($member)
+ ]
+ );
+ } catch (UnhandledMatchError $e) {
+ return;
+ }
+
+ $this->publishEvent(
+ $event, array_merge(
+ [$member],
+ $this->memberRequest->getInheritedMembers(
+ $circle->getSingleId(),
+ false,
+ Member::LEVEL_MODERATOR
+ )
+ )
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $eventType
+ */
+ private function onMemberNewCircle(
+ Circle $circle,
+ Member $member,
+ int $eventType = CircleGenericEvent::JOINED
+ ): void {
+ $event = $this->generateEvent('circles_as_member');
+
+ try {
+ $event->setSubject(
+ match ($eventType) {
+ CircleGenericEvent::ADDED => 'member_circle_added',
+ CircleGenericEvent::JOINED => 'member_circle_joined'
+ },
+ [
+ 'circle' => json_encode($circle),
+ 'member' => json_encode($member)
+ ]
+ );
+ } catch (UnhandledMatchError $e) {
+ return;
+ }
+
+ $this->publishEvent(
+ $event, array_merge(
+ $this->memberRequest->getInheritedMembers($member->getSingleId(), false, Member::LEVEL_MEMBER),
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MODERATOR)
+ )
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $eventType
+ */
+ private function onMemberAlmost(
+ Circle $circle,
+ Member $member,
+ int $eventType
+ ): void {
+ if ($member->getUserType() !== Member::TYPE_USER) {
+ return; // only if almost-member is a local account
+ }
+
+ $event = $this->generateEvent('circles_as_moderator');
+
+ try {
+ $event->setSubject(
+ match ($eventType) {
+ CircleGenericEvent::INVITED => 'member_invited',
+ CircleGenericEvent::REQUESTED => 'member_request_invitation'
+ },
+ [
+ 'circle' => json_encode($circle),
+ 'member' => json_encode($member)
+ ]
+ );
+ } catch (UnhandledMatchError $e) {
+ return;
+ }
+
+ $this->publishEvent(
+ $event,
+ array_merge(
+ [$member],
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MODERATOR)
+ )
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $eventType
+ */
+ public function onMemberRemove(Circle $circle, Member $member, int $eventType): void {
+ if ($circle->isConfig(Circle::CFG_PERSONAL)) {
+ return;
+ }
+
+ $event = $this->generateEvent('circles_as_member');
+ try {
+ $event->setSubject(
+ match ($eventType) {
+ CircleGenericEvent::LEFT => 'member_left',
+ CircleGenericEvent::REMOVED => 'member_remove'
+ },
+ [
+ 'circle' => json_encode($circle),
+ 'member' => json_encode($member)
+ ]
+ );
+ } catch (UnhandledMatchError $e) {
+ return;
+ }
+
+ $this->publishEvent(
+ $event, array_merge(
+ [$member],
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MODERATOR)
+ )
+ );
+ }
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ * @param int $level
+ */
+ public function onMemberLevel(
+ Circle $circle,
+ Member $member,
+ int $level
+ ): void {
+ if ($member->getLevel() === Member::LEVEL_OWNER) {
+ $this->onMemberOwner($circle, $member);
+
+ return;
+ }
+
+ $event = $this->generateEvent('circles_as_moderator');
+ $event->setSubject(
+ 'member_level',
+ ['circle' => json_encode($circle), 'member' => json_encode($member), 'level' => $level]
+ );
+
+ $this->publishEvent(
+ $event, array_merge(
+ [$member],
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MODERATOR))
+ );
+ }
+
+
+ /**
+ * @param Circle $circle
+ * @param Member $member
+ */
+ public function onMemberOwner(Circle $circle, Member $member): void {
+ $event = $this->generateEvent('circles_as_moderator');
+ $event->setSubject(
+ 'member_owner',
+ ['circle' => json_encode($circle), 'member' => json_encode($member)]
+ );
+
+ $this->publishEvent(
+ $event,
+ $this->memberRequest->getInheritedMembers($circle->getSingleId(), false, Member::LEVEL_MEMBER)
+ );
+ }
+
+
+ public function onShareNew(Circle $getCircle, FederatedEvent $federatedEvent): void {
+ }
+
+
+ /**
+ * generateEvent()
+ * Create an Activity Event with the basic settings for the app.
+ *
+ * @param string $type
+ *
+ * @return IEvent
+ */
+ private function generateEvent(string $type): IEvent {
+ $event = $this->activityManager->generateEvent();
+ $event->setApp(Application::APP_ID)
+ ->setType($type);
+
+ return $event;
+ }
+
+
+ /**
+ * Publish the event to the users.
+ * - if user is IUser, we get userId,
+ * - if user is Member, we ignore non-local account and returns local userId,
+ * - others models are ignored
+ * - avoid duplicate activity in case of inheritance as an account can be inherited memberships throw different path
+ *
+ * @param IEvent $event
+ * @param array $users
+ */
+ private function publishEvent(IEvent $event, array $users): void {
+ $knownSingleIds = [];
+ foreach ($users as $user) {
+ if ($user instanceof IUser) {
+ $userId = $user->getUID();
+ } elseif ($user instanceof IFederatedUser) {
+ $singleId = $user->getSingleId();
+ if ($user->getUserType() !== Member::TYPE_USER ||
+ in_array($singleId, $knownSingleIds)) {
+ continue; // we ignore non-local account and already known single ids
+ }
+
+ $knownSingleIds[] = $singleId;
+ $userId = $user->getUserId();
+ } else {
+ continue;
+ }
+
+ $event->setAffectedUser($userId);
+ $this->activityManager->publish($event);
+ }
+ }
+}
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index 47e2d2906..b798be4f1 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -182,7 +182,7 @@ class ConfigService {
self::SELF_SIGNED_CERT => '0',
self::MEMBERS_LIMIT => '-1',
- self::ACTIVITY_ON_NEW_CIRCLE => '1',
+ self::ACTIVITY_ON_NEW_CIRCLE => '0',
self::ALLOWED_TYPES => Member::ALLOWING_ALL_TYPES,
self::CIRCLE_TYPES_FORCE => '0',
self::CIRCLE_TYPES_BLOCK => '0',
diff --git a/lib/Service/EventService.php b/lib/Service/EventService.php
index 004a32283..fb3e65fa1 100644
--- a/lib/Service/EventService.php
+++ b/lib/Service/EventService.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
/**
* Circles - Bring cloud-users closer together.
*
@@ -34,9 +33,6 @@
namespace OCA\Circles\Service;
-use OCA\Circles\Tools\Model\SimpleDataStore;
-use OCA\Circles\Tools\Traits\TNCLogger;
-use OCA\Circles\AppInfo\Application;
use OCA\Circles\Events\AddingCircleMemberEvent;
use OCA\Circles\Events\CircleCreatedEvent;
use OCA\Circles\Events\CircleDestroyedEvent;
@@ -62,30 +58,14 @@
use OCA\Circles\Model\Membership;
use OCA\Circles\Model\Mount;
use OCA\Circles\Model\ShareWrapper;
+use OCA\Circles\Tools\Model\SimpleDataStore;
use OCP\EventDispatcher\IEventDispatcher;
-/**
- * Class EventService
- *
- * @package OCA\Circles\Service
- */
class EventService {
- use TNCLogger;
-
-
- /** @var IEventDispatcher */
- private $eventDispatcher;
-
-
- /**
- * EventService constructor.
- *
- * @param IEventDispatcher $eventDispatcher
- */
- public function __construct(IEventDispatcher $eventDispatcher) {
- $this->eventDispatcher = $eventDispatcher;
-
- $this->setup('app', Application::APP_ID);
+ public function __construct(
+ private IEventDispatcher $eventDispatcher,
+ private ActivityService $activityService
+ ) {
}
@@ -104,6 +84,7 @@ public function circleCreating(FederatedEvent $federatedEvent): void {
public function circleCreated(FederatedEvent $federatedEvent, array $results): void {
$event = new CircleCreatedEvent($federatedEvent, $results);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onCircleCreation($event->getCircle());
}
@@ -124,13 +105,13 @@ public function circleEdited(FederatedEvent $federatedEvent, array $results): vo
$this->eventDispatcher->dispatchTyped($event);
}
-
/**
* @param FederatedEvent $federatedEvent
*/
public function circleDestroying(FederatedEvent $federatedEvent): void {
$event = new DestroyingCircleEvent($federatedEvent);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onCircleDestruction($event->getCircle());
}
/**
@@ -156,8 +137,9 @@ public function memberPreparing(FederatedEvent $federatedEvent): void {
*/
public function memberAdding(FederatedEvent $federatedEvent): void {
$event = new AddingCircleMemberEvent($federatedEvent);
- $event->setType(CircleGenericEvent::INVITED);
+ $event->setType(CircleGenericEvent::ADDED);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberNew($event->getCircle(), $event->getMember(), CircleGenericEvent::ADDED);
}
/**
@@ -166,7 +148,7 @@ public function memberAdding(FederatedEvent $federatedEvent): void {
*/
public function memberAdded(FederatedEvent $federatedEvent, array $results): void {
$event = new CircleMemberAddedEvent($federatedEvent, $results);
- $event->setType(CircleGenericEvent::INVITED);
+ $event->setType(CircleGenericEvent::ADDED);
$this->eventDispatcher->dispatchTyped($event);
}
@@ -178,6 +160,7 @@ public function memberInviting(FederatedEvent $federatedEvent): void {
$event = new RequestingCircleMemberEvent($federatedEvent);
$event->setType(CircleGenericEvent::INVITED);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberNew($event->getCircle(), $event->getMember(), CircleGenericEvent::INVITED);
}
/**
@@ -198,6 +181,7 @@ public function memberRequesting(FederatedEvent $federatedEvent): void {
$event = new RequestingCircleMemberEvent($federatedEvent);
$event->setType(CircleGenericEvent::REQUESTED);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberNew($event->getCircle(), $event->getMember(), CircleGenericEvent::REQUESTED);
}
/**
@@ -218,6 +202,7 @@ public function memberJoining(FederatedEvent $federatedEvent): void {
$event = new AddingCircleMemberEvent($federatedEvent);
$event->setType(CircleGenericEvent::JOINED);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberNew($event->getCircle(), $event->getMember(), CircleGenericEvent::JOINED);
}
/**
@@ -239,6 +224,7 @@ public function memberLevelEditing(FederatedEvent $federatedEvent): void {
$event->setLevel($federatedEvent->getData()->gInt('level'));
$event->setType(CircleGenericEvent::LEVEL);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberLevel($event->getCircle(), $event->getMember(), $event->getLevel());
}
/**
@@ -292,6 +278,7 @@ public function memberRemoved(FederatedEvent $federatedEvent, array $results): v
$event = new CircleMemberRemovedEvent($federatedEvent, $results);
$event->setType(CircleGenericEvent::REMOVED);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberRemove($event->getCircle(), $event->getMember(), CircleGenericEvent::REMOVED);
}
@@ -312,6 +299,7 @@ public function memberLeft(FederatedEvent $federatedEvent, array $results): void
$event = new CircleMemberRemovedEvent($federatedEvent, $results);
$event->setType(CircleGenericEvent::LEFT);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onMemberRemove($event->getCircle(), $event->getMember(), CircleGenericEvent::LEFT);
}
@@ -343,6 +331,7 @@ public function fileShareCreating(FederatedEvent $federatedEvent, ?Mount $mount
public function fileShareCreated(FederatedEvent $federatedEvent, array $result): void {
$event = new FileShareCreatedEvent($federatedEvent, $result);
$this->eventDispatcher->dispatchTyped($event);
+ $this->activityService->onShareNew($event->getCircle(), $event->getFederatedEvent());
}
@@ -354,7 +343,6 @@ public function membershipsCreated(array $new): void {
$this->eventDispatcher->dispatchTyped($event);
}
-
/**
* @param Membership[] $deprecated
*/
@@ -363,26 +351,12 @@ public function membershipsRemoved(array $deprecated): void {
$this->eventDispatcher->dispatchTyped($event);
}
-
/**
* @param ShareWrapper $wrappedShare
*/
public function localShareCreated(ShareWrapper $wrappedShare): void {
}
- /**
- * @param ShareWrapper $wrappedShare
- * @param Mount $mount
- */
- public function federatedShareCreated(ShareWrapper $wrappedShare, Mount $mount): void {
-// Circles::shareToCircle(
-// $circle->getUniqueId(), 'files', '',
-// ['id' => $share->getId(), 'share' => $this->shareObjectToArray($share)],
-// '\OCA\Circles\Circles\FileSharingBroadcaster'
-// );
- }
-
-
/**
* @param ShareWrapper $wrappedShare
*/
@@ -394,14 +368,4 @@ public function localShareDeleted(ShareWrapper $wrappedShare): void {
*/
public function federatedShareDeleted(ShareWrapper $wrappedShare): void {
}
-
-
-
-// /**
-// * @param FederatedEvent $federatedEvent
-// */
-// public function onSharedItemsSyncRequested(FederatedEvent $federatedEvent) {
-// $event = new SharedItemsSyncRequestedEvent($federatedEvent);
-// $this->eventDispatcher->dispatchTyped($event);
-// }
}
diff --git a/lib/Tools/Traits/TDeserialize.php b/lib/Tools/Traits/TDeserialize.php
index 799e96d4b..d52c126d0 100644
--- a/lib/Tools/Traits/TDeserialize.php
+++ b/lib/Tools/Traits/TDeserialize.php
@@ -63,10 +63,6 @@ public function serializeArray(array $data): array {
* @throws InvalidItemException
*/
public function deserialize(array $data, string $class): IDeserializable {
- if ($class instanceof IDeserializable) {
- throw new InvalidItemException(get_class($class) . ' does not implement IDeserializable');
- }
-
/** @var IDeserializable $item */
$item = new $class;
$item->import($data);