Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2023-08-11 08:52:01 +02:00
Родитель 7b1d2929c8
Коммит 4a779761a8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
28 изменённых файлов: 47 добавлений и 93 удалений

Просмотреть файл

@ -26,30 +26,6 @@
namespace OCA\Polls\AppInfo;
use OCA\Polls\Dashboard\PollWidget;
use OCA\Polls\Event\CommentAddEvent;
use OCA\Polls\Event\CommentDeleteEvent;
use OCA\Polls\Event\OptionConfirmedEvent;
use OCA\Polls\Event\OptionCreatedEvent;
use OCA\Polls\Event\OptionDeletedEvent;
use OCA\Polls\Event\OptionUnconfirmedEvent;
use OCA\Polls\Event\OptionUpdatedEvent;
use OCA\Polls\Event\PollArchivedEvent;
use OCA\Polls\Event\PollCreatedEvent;
use OCA\Polls\Event\PollDeletedEvent;
use OCA\Polls\Event\PollExpiredEvent;
use OCA\Polls\Event\PollOptionReorderedEvent;
use OCA\Polls\Event\PollOwnerChangeEvent;
use OCA\Polls\Event\PollRestoredEvent;
use OCA\Polls\Event\PollTakeoverEvent;
use OCA\Polls\Event\PollUpdatedEvent;
use OCA\Polls\Event\ShareChangedDisplayNameEvent;
use OCA\Polls\Event\ShareChangedEmailEvent;
use OCA\Polls\Event\ShareChangedRegistrationConstraintEvent;
use OCA\Polls\Event\ShareCreateEvent;
use OCA\Polls\Event\ShareDeletedEvent;
use OCA\Polls\Event\ShareRegistrationEvent;
use OCA\Polls\Event\ShareTypeChangedEvent;
use OCA\Polls\Event\VoteSetEvent;
use OCA\Polls\Listener\CommentListener;
use OCA\Polls\Listener\GroupDeletedListener;
use OCA\Polls\Listener\OptionListener;
@ -85,30 +61,11 @@ class Application extends App implements IBootstrap {
$context->registerMiddleWare(RequestAttributesMiddleware::class);
$context->registerNotifierService(Notifier::class);
$context->registerEventListener(CommentAddEvent::class, CommentListener::class);
$context->registerEventListener(CommentDeleteEvent::class, CommentListener::class);
$context->registerEventListener(OptionConfirmedEvent::class, OptionListener::class);
$context->registerEventListener(OptionCreatedEvent::class, OptionListener::class);
$context->registerEventListener(OptionDeletedEvent::class, OptionListener::class);
$context->registerEventListener(OptionUnconfirmedEvent::class, OptionListener::class);
$context->registerEventListener(PollOptionReorderedEvent::class, OptionListener::class);
$context->registerEventListener(OptionUpdatedEvent::class, OptionListener::class);
$context->registerEventListener(PollArchivedEvent::class, PollListener::class);
$context->registerEventListener(PollCreatedEvent::class, PollListener::class);
$context->registerEventListener(PollDeletedEvent::class, PollListener::class);
$context->registerEventListener(PollExpiredEvent::class, PollListener::class);
$context->registerEventListener(PollRestoredEvent::class, PollListener::class);
$context->registerEventListener(PollOwnerChangeEvent::class, PollListener::class);
$context->registerEventListener(PollTakeoverEvent::class, PollListener::class);
$context->registerEventListener(PollUpdatedEvent::class, PollListener::class);
$context->registerEventListener(ShareChangedEmailEvent::class, ShareListener::class);
$context->registerEventListener(ShareChangedDisplayNameEvent::class, ShareListener::class);
$context->registerEventListener(ShareChangedRegistrationConstraintEvent::class, ShareListener::class);
$context->registerEventListener(ShareCreateEvent::class, ShareListener::class);
$context->registerEventListener(ShareDeletedEvent::class, ShareListener::class);
$context->registerEventListener(ShareRegistrationEvent::class, ShareListener::class);
$context->registerEventListener(ShareTypeChangedEvent::class, ShareListener::class);
$context->registerEventListener(VoteSetEvent::class, VoteListener::class);
$context->registerEventListener(CommentEvent::class, CommentListener::class);
$context->registerEventListener(OptionEvent::class, OptionListener::class);
$context->registerEventListener(PollEvent::class, PollListener::class);
$context->registerEventListener(ShareEvent::class, ShareListener::class);
$context->registerEventListener(VoteEvent::class, VoteListener::class);
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
$context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
$context->registerSearchProvider(SearchProvider::class);

Просмотреть файл

@ -23,6 +23,7 @@
namespace OCA\Polls\Controller;
use \OCA\Polls\Db\Comment;
use OCA\Polls\Model\Acl;
use OCA\Polls\Service\CommentService;
use OCP\AppFramework\Http\JSONResponse;
@ -74,7 +75,7 @@ class CommentApiController extends BaseApiController {
]);
}
private function deleteComment($commentId) {
private function deleteComment(int $commentId): Comment {
$comment = $this->commentService->get($commentId);
return $this->commentService->delete($comment, $this->acl->setPollId($comment->getPollId()));
}

Просмотреть файл

@ -35,11 +35,11 @@ use OCP\EventDispatcher\Event;
use OCP\IUserSession;
abstract class BaseEvent extends Event {
protected string $activityObject = '';
protected string $activitySubject = '';
protected ?string $activityObject = null;
protected ?string $eventId = null;
protected array $activitySubjectParams = [];
protected Poll $poll;
protected bool $log = true;
protected Poll $poll;
protected IUserSession $userSession;
protected UserService $userService;
@ -88,8 +88,8 @@ abstract class BaseEvent extends Event {
}
public function getLogId(): string {
if ($this->log && $this->activitySubject) {
return $this->activitySubject;
if ($this->log && $this->eventId) {
return $this->eventId;
}
return '';
}
@ -98,11 +98,7 @@ abstract class BaseEvent extends Event {
return [];
}
public function getActivityId(): string {
return $this->activitySubject;
}
public function getActivityObject(): string {
public function getActivityObject(): ?string {
return $this->activityObject;
}
@ -113,8 +109,8 @@ abstract class BaseEvent extends Event {
return $this->eventObject->getId();
}
public function getActivitySubject(): string {
return $this->activitySubject;
public function getActivitySubject(): ?string {
return $this->eventId;
}
public function getActivitySubjectParams(): array {

Просмотреть файл

@ -30,6 +30,6 @@ class CommentAddEvent extends CommentEvent {
protected Comment $comment
) {
parent::__construct($comment);
$this->activitySubject = self::ADD;
$this->eventId = self::ADD;
}
}

Просмотреть файл

@ -31,6 +31,6 @@ class CommentDeleteEvent extends CommentEvent {
) {
parent::__construct($comment);
$this->log = false;
$this->activitySubject = self::DELETE;
$this->eventId = self::DELETE;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class OptionConfirmedEvent extends OptionEvent {
protected Option $option
) {
parent::__construct($option);
$this->activitySubject = self::CONFIRM;
$this->eventId = self::CONFIRM;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class OptionCreatedEvent extends OptionEvent {
protected Option $option,
) {
parent::__construct($option);
$this->activitySubject = self::ADD;
$this->eventId = self::ADD;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class OptionDeletedEvent extends OptionEvent {
protected Option $option
) {
parent::__construct($option);
$this->activitySubject = self::DELETE;
$this->eventId = self::DELETE;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class OptionUnconfirmedEvent extends OptionEvent {
protected Option $option
) {
parent::__construct($option);
$this->activitySubject = self::UNCONFIRM;
$this->eventId = self::UNCONFIRM;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class OptionUpdatedEvent extends OptionEvent {
protected Option $option
) {
parent::__construct($option);
$this->activitySubject = self::UPDATE;
$this->eventId = self::UPDATE;
}
}

Просмотреть файл

@ -31,7 +31,7 @@ class PollArchivedEvent extends PollEvent {
protected Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::DELETE;
$this->eventId = self::DELETE;
}
public function getNotification(): array {

Просмотреть файл

@ -30,6 +30,6 @@ class PollCreatedEvent extends PollEvent {
protected Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::ADD;
$this->eventId = self::ADD;
}
}

Просмотреть файл

@ -32,7 +32,7 @@ class PollDeletedEvent extends PollEvent {
protected Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::DELETE;
$this->eventId = self::DELETE;
}

Просмотреть файл

@ -30,6 +30,6 @@ class PollExpiredEvent extends PollEvent {
Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::EXPIRE;
$this->eventId = self::EXPIRE;
}
}

Просмотреть файл

@ -31,6 +31,6 @@ class PollOptionReorderedEvent extends PollEvent {
) {
parent::__construct($poll);
$this->log = false;
$this->activitySubject = self::OPTION_REORDER;
$this->eventId = self::OPTION_REORDER;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class PollOwnerChangeEvent extends PollEvent {
Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::OWNER_CHANGE;
$this->eventId = self::OWNER_CHANGE;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class PollRestoredEvent extends PollEvent {
Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::RESTORE;
$this->eventId = self::RESTORE;
}
}

Просмотреть файл

@ -30,6 +30,6 @@ class PollUpdatedEvent extends PollEvent {
Poll $poll
) {
parent::__construct($poll);
$this->activitySubject = self::UPDATE;
$this->eventId = self::UPDATE;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareChangedDisplayNameEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::CHANGE_DISPLAY_NAME;
$this->eventId = self::CHANGE_DISPLAY_NAME;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareChangedEmailEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::CHANGE_EMAIL;
$this->eventId = self::CHANGE_EMAIL;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareChangedRegistrationConstraintEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::CHANGE_REG_CONSTR;
$this->eventId = self::CHANGE_REG_CONSTR;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareCreateEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::ADD;
$this->eventId = self::ADD;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareDeletedEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::DELETE;
$this->eventId = self::DELETE;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareRegistrationEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::REGISTRATION;
$this->eventId = self::REGISTRATION;
}
}

Просмотреть файл

@ -28,6 +28,6 @@ use OCA\Polls\Db\Share;
class ShareTypeChangedEvent extends ShareEvent {
public function __construct(Share $share) {
parent::__construct($share);
$this->activitySubject = self::CHANGE_TYPE;
$this->eventId = self::CHANGE_TYPE;
}
}

Просмотреть файл

@ -32,6 +32,6 @@ class VoteSetEvent extends VoteEvent {
) {
parent::__construct($vote);
$this->log = $log;
$this->activitySubject = self::SET;
$this->eventId = self::SET;
}
}

Просмотреть файл

@ -112,15 +112,15 @@ abstract class BaseListener implements IEventListener {
protected function updateLastInteraction(): void {
// Update last interaction, exept event is one of the of excluded events
if (
!($this->event instanceof PollTakeoverEvent)
&& !($this->event instanceof PollOwnerChangeEvent)
&& !($this->event instanceof PollExpiredEvent)
&& !($this->event instanceof PollDeletedEvent)
&& !($this->event instanceof PollArchivedEvent)
if ($this->event instanceof PollTakeoverEvent
|| $this->event instanceof PollOwnerChangeEvent
|| $this->event instanceof PollExpiredEvent
|| $this->event instanceof PollDeletedEvent
|| $this->event instanceof PollArchivedEvent
) {
$this->pollService->setLastInteraction($this->getPollId());
return;
}
$this->pollService->setLastInteraction($this->getPollId());
}
/**
* Default logging for email notifications.
@ -170,7 +170,7 @@ abstract class BaseListener implements IEventListener {
if (!($this->event instanceof BaseEvent)) {
return;
}
if ($this->event->getActivityId()) {
if ($this->event->getActivitySubject() && $this->event->getActivityObject()) {
$activityEvent = $this->activityService->createActivityEvent($this->event);
$this->activityService->publishActivityEvent($activityEvent, $this->event->getActor());
if ($this->event->getActor() !== $this->event->getPollOwner()) {

Просмотреть файл

@ -57,7 +57,7 @@ class ActivityService {
public function createActivityEvent(BaseEvent $event): ActivityEvent {
$activityEvent = $this->activityManager->generateEvent();
$activityEvent->setApp('polls')
->setType($event->getActivityId())
->setType($event->getActivitySubject())
->setAuthor($event->getActor())
->setObject($event->getActivityObject(), $event->getActivityObjectId())
->setSubject($event->getActivitySubject(), $event->getActivitySubjectParams())