add wanted events support #27

This commit is contained in:
ghost 2023-10-24 00:12:13 +03:00
parent 5f4a14ebe2
commit 24c58d4301
20 changed files with 249 additions and 1 deletions

View file

@ -764,6 +764,44 @@ class ActivityController extends AbstractController
break;
// Torrent Wanted
case $activity::EVENT_TORRENT_WANTED_ADD:
// Init torrent
if (!$torrent = $torrentService->getTorrent($activity->getTorrentId()))
{
throw $this->createNotFoundException();
}
return $this->render(
'default/activity/event/torrent/wanted/add' . $extension,
[
'id' => $activity->getId(),
'added' => $activity->getAdded(),
'torrent' =>
[
'id' => $torrent->getId(),
'sensitive' => $torrent->isSensitive(),
'approved' => $torrent->isApproved(),
'name' => $torrentService->readTorrentFileByTorrentId(
$torrent->getId()
)->getName()
],
'session' =>
[
'user' =>
[
'id' => $user->getId(),
'sensitive' => $user->isSensitive(),
'moderator' => $user->isModerator(),
'owner' => $user->getId() === $torrent->getUserId(),
]
]
]
);
break;
/// Torrent Locales
case $activity::EVENT_TORRENT_LOCALES_ADD:

View file

@ -2191,6 +2191,17 @@ class TorrentController extends AbstractController
}
}
// Register activity event only on previous status changed
if ($leechers && !$seeders &&
$leechers != (int) $torrent->getLeechers() && $seeders != (int) $torrent->getSeeders())
{
$activityService->addEventTorrentWantedAdd(
$torrent->getUserId(), // just required field, let's relate with author, because we don't know which exactly user requires for seeders from crontab @TODO
time(),
$torrent->getId()
);
}
// Update DB
$torrentService->updateTorrentScrape(
$torrent->getId(),

View file

@ -57,6 +57,8 @@ class Activity
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 2600;
public const EVENT_TORRENT_WANTED_ADD = 2700;
// ...
#[ORM\Column]

View file

@ -61,6 +61,8 @@ class ActivityService
Activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD,
Activity::EVENT_TORRENT_DOWNLOAD_MAGNET_ADD,
Activity::EVENT_TORRENT_WANTED_ADD,
];
}
@ -365,6 +367,18 @@ class ActivityService
] = $code;
break;
case Activity::EVENT_TORRENT_WANTED_ADD:
$events
[
$this->translatorInterface->trans('Torrents')
]
[
$this->translatorInterface->trans('Wanted')
] = $code;
break;
}
}
@ -847,6 +861,37 @@ class ActivityService
return $activity;
}
public function addEventTorrentWantedAdd(
int $userId,
int $added,
int $torrentId
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_WANTED_ADD
);
$activity->setUserId(
$userId
);
$activity->setAdded(
$added
);
$activity->setTorrentId(
$torrentId
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
/// Torrent Download
public function addEventTorrentDownloadFileAdd(
int $userId,