add poster event support #18

This commit is contained in:
ghost 2023-10-30 05:14:46 +02:00
parent bd5191e894
commit 706ea40eec
12 changed files with 681 additions and 14 deletions

View file

@ -1329,6 +1329,219 @@ class ActivityController extends AbstractController
break;
/// Torrent Poster
case $activity::EVENT_TORRENT_POSTER_ADD:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/poster/add' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
'poster' => [
'id' => $activity->getData()['torrentPosterId'],
'exist' => $torrentService->getTorrentPoster(
$activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links
)
]
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
case $activity::EVENT_TORRENT_POSTER_DELETE:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/poster/delete' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
'poster' => [
'id' => $activity->getData()['torrentPosterId'],
'exist' => $torrentService->getTorrentPoster(
$activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links
)
]
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
case $activity::EVENT_TORRENT_POSTER_APPROVE_ADD:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/poster/approve/add' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
'poster' => [
'id' => $activity->getData()['torrentPosterId'],
'exist' => $torrentService->getTorrentPoster(
$activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links
)
]
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
case $activity::EVENT_TORRENT_POSTER_APPROVE_DELETE:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/poster/approve/delete' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'status' => $torrent->isStatus(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName(),
'poster' => [
'id' => $activity->getData()['torrentPosterId'],
'exist' => $torrentService->getTorrentPoster(
$activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links
)
]
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
/// Torrent star
case $activity::EVENT_TORRENT_STAR_ADD:

View file

@ -1979,14 +1979,12 @@ class TorrentController extends AbstractController
);
// Add activity event
/* @TODO
$activityService->addEventTorrentPosterAdd(
$user->getId(),
$torrent->getId(),
time(),
$torrentPoster->getId()
);
*/
// Redirect to info page created
return $this->redirectToRoute(
@ -2068,26 +2066,22 @@ class TorrentController extends AbstractController
// Add activity event
if (!$torrentPoster->isApproved())
{
/* @TODO
$activityService->addEventTorrentPosterApproveAdd(
$user->getId(),
$torrent->getId(),
time(),
$torrentPoster->getId()
);
*/
}
else
{
/* @TODO
$activityService->addEventTorrentPosterApproveDelete(
$user->getId(),
$torrent->getId(),
time(),
$torrentPoster->getId()
);
*/
}
// Update approved
@ -2157,14 +2151,12 @@ class TorrentController extends AbstractController
}
// Add activity event
/* @TODO
$activityService->addEventTorrentPosterDelete(
$user->getId(),
$torrent->getId(),
time(),
$torrentPoster->getId()
);
*/
// Update approved
$torrentService->deleteTorrentPoster(
@ -2182,12 +2174,6 @@ class TorrentController extends AbstractController
);
}
// Torrent star
#[Route(
'/{_locale}/torrent/{torrentId}/star/toggle',

View file

@ -62,6 +62,11 @@ class Activity
public const EVENT_TORRENT_STATUS_ADD = 1800;
public const EVENT_TORRENT_STATUS_DELETE = 1801;
public const EVENT_TORRENT_POSTER_ADD = 2800;
public const EVENT_TORRENT_POSTER_DELETE = 2801;
public const EVENT_TORRENT_POSTER_APPROVE_ADD = 2810;
public const EVENT_TORRENT_POSTER_APPROVE_DELETE = 2811;
// ...
#[ORM\Column]

View file

@ -56,6 +56,11 @@ class ActivityService
Activity::EVENT_TORRENT_SENSITIVE_APPROVE_ADD,
Activity::EVENT_TORRENT_SENSITIVE_APPROVE_DELETE,
Activity::EVENT_TORRENT_POSTER_ADD,
Activity::EVENT_TORRENT_POSTER_DELETE,
Activity::EVENT_TORRENT_POSTER_APPROVE_ADD,
Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE,
Activity::EVENT_TORRENT_STAR_ADD,
Activity::EVENT_TORRENT_STAR_DELETE,
@ -321,6 +326,55 @@ class ActivityService
break;
/// Torrent poster
case Activity::EVENT_TORRENT_POSTER_ADD:
$events
[
$this->translatorInterface->trans('Torrent poster')
]
[
$this->translatorInterface->trans('Added')
] = $code;
break;
case Activity::EVENT_TORRENT_POSTER_DELETE:
$events
[
$this->translatorInterface->trans('Torrent poster')
]
[
$this->translatorInterface->trans('Deleted')
] = $code;
break;
case Activity::EVENT_TORRENT_POSTER_APPROVE_ADD:
$events
[
$this->translatorInterface->trans('Torrent poster')
]
[
$this->translatorInterface->trans('Approved')
] = $code;
break;
case Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE:
$events
[
$this->translatorInterface->trans('Torrent poster')
]
[
$this->translatorInterface->trans('Disapproved')
] = $code;
break;
/// Torrent stars
case Activity::EVENT_TORRENT_STAR_ADD:
@ -1397,4 +1451,153 @@ class ActivityService
return $activity;
}
/// Torrent poster
public function addEventTorrentPosterAdd(
int $userId,
int $torrentId,
int $added,
int $torrentPosterId,
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_POSTER_ADD
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$activity->setData(
[
'torrentPosterId' => $torrentPosterId
]
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentPosterDelete(
int $userId,
int $torrentId,
int $added,
int $torrentPosterId,
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_POSTER_DELETE
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$activity->setData(
[
'torrentPosterId' => $torrentPosterId
]
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentPosterApproveAdd(
int $userId,
int $torrentId,
int $added,
int $torrentPosterId,
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_POSTER_APPROVE_ADD
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$activity->setData(
[
'torrentPosterId' => $torrentPosterId
]
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentPosterApproveDelete(
int $userId,
int $torrentId,
int $added,
int $torrentPosterId,
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$activity->setData(
[
'torrentPosterId' => $torrentPosterId
]
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
}