urlGenerator = $urlGenerator; $this->notificationManager = $notificationManager; $this->memberRequest = $memberRequest; $this->timezoneService = $timezoneService; $this->setup('app', Application::APP_ID); } /** * @param Member $member */ public function notificationInvited(Member $member): void { if ($member->getUserType() !== Member::TYPE_USER || !$member->isLocal()) { return; } $this->deleteNotification('member', $member->getId()); $notification = $this->createMemberNotification( $member->getUserId(), $member->getId(), 'invitation' ); $declineAction = $notification->createAction(); $declineUrl = $this->urlGenerator->linkToOCSRouteAbsolute('circles.Local.circleLeave', ['circleId' => $member->getCircleId()]); $declineAction->setLabel('refuse') ->setLink($declineUrl, 'PUT'); $notification->addAction($declineAction); $acceptAction = $notification->createAction(); $acceptUrl = $this->urlGenerator->linkToOCSRouteAbsolute('circles.Local.circleJoin', ['circleId' => $member->getCircleId()]); $acceptAction->setLabel('accept') ->setLink($acceptUrl, 'PUT'); $notification->addAction($acceptAction); $this->notificationManager->notify($notification); } /** * @param Member $member * * @throws RequestBuilderException */ public function notificationRequested(Member $member): void { // if ($member->getUserType() !== Member::TYPE_USER || !$member->isLocal()) { // return; // } $this->deleteNotification('member', $member->getId()); $moderators = $this->memberRequest->getInheritedMembers( $member->getCircleId(), false, Member::LEVEL_MODERATOR ); foreach ($moderators as $moderator) { if ($moderator->getUserType() !== Member::TYPE_USER || !$moderator->isLocal()) { continue; } $notification = $this->createMemberNotification( $moderator->getUserId(), $member->getId(), 'joinRequest' ); $declineAction = $notification->createAction(); $declineUrl = $this->urlGenerator->linkToOCSRouteAbsolute( 'circles.Local.memberRemove', [ 'circleId' => $member->getCircleId(), 'memberId' => $member->getId() ] ); $declineAction->setLabel('refuse') ->setLink($declineUrl, 'DELETE'); $notification->addAction($declineAction); $acceptAction = $notification->createAction(); $acceptUrl = $this->urlGenerator->linkToOCSRouteAbsolute( 'circles.Local.memberConfirm', [ 'circleId' => $member->getCircleId(), 'memberId' => $member->getId() ] ); $acceptAction->setLabel('accept') ->setLink($acceptUrl, 'PUT'); $notification->addAction($acceptAction); $this->notificationManager->notify($notification); } } /** * @param string $object * @param string $objectId */ public function deleteNotification(string $object, string $objectId) { // if ($objectId === '') { // return; // } // // $notification = $this->notificationManager->createNotification(); // $notification->setApp('circles') // ->setObject($object, $objectId); // // $this->notificationManager->markProcessed($notification); } /** * @param string $userId * @param string $memberId * @param string $subject * * @return INotification */ private function createMemberNotification( string $userId, string $memberId, string $subject, ): INotification { $notification = $this->notificationManager->createNotification(); $notification->setApp('circles') ->setDateTime($this->timezoneService->getDateTime()) ->setUser($userId) ->setObject('member', $memberId) ->setSubject($subject); return $notification; } public function markInvitationAsProcessed(Member $member): void { if ($member->getUserType() !== Member::TYPE_USER || !$member->isLocal()) { return; } $notification = $this->notificationManager->createNotification(); $notification->setApp('circles') ->setUser($member->getUserId()) ->setObject('member', $member->getId()) ->setSubject('invitation'); $this->notificationManager->markProcessed($notification); } }