From 402edc47deb045836e3d270f2ecb91f0d6b78274 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 15 Sep 2023 04:10:37 +0300 Subject: [PATCH] add vies push support --- src/public/magnet.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/public/magnet.php b/src/public/magnet.php index 665f7fc..4e631c9 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -55,10 +55,34 @@ else $accessRead = ($user->address == $db->getUser($magnet->userId)->address || in_array($user->address, MODERATOR_IP_LIST) || ($magnet->public && $magnet->approved)); $accessEdit = ($user->address == $db->getUser($magnet->userId)->address || in_array($user->address, MODERATOR_IP_LIST)); - // Update magnet viwed + // Update magnet viewed if ($accessRead) { - $db->addMagnetView($magnet->magnetId, $userId, time()); + if ($magnetViewId = $db->addMagnetView($magnet->magnetId, $userId, time())) + { + // Push event to other nodes + if (API_EXPORT_ENABLED && + API_EXPORT_PUSH_ENABLED && + API_EXPORT_USERS_ENABLED && + API_EXPORT_MAGNETS_ENABLED && + API_EXPORT_MAGNET_VIEWS_ENABLED) + { + if (!$memoryApiExportPush = $memory->get('api.export.push')) + { + $memoryApiExportPush = []; + } + + $memoryApiExportPush[] = (object) + [ + 'time' => time(), + 'userId' => $user->userId, + 'magnetId' => $magnet->magnetId, + 'magnetViewId' => $magnetViewId + ]; + + $memory->set('api.export.push', $memoryApiExportPush, 3600); + } + } } // Keywords