diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 2ad4611e9..42a70a611 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -80,6 +80,7 @@ use App\Util\Media\License; use App\Jobs\MediaPipeline\MediaSyncLicensePipeline; use App\Services\DiscoverService; use App\Services\CustomEmojiService; +use App\Services\MarkerService; class ApiV1Controller extends Controller { @@ -2742,4 +2743,45 @@ class ApiV1Controller extends Controller return $this->json([]); } + + /** + * GET /api/v1/markers + * + * + * @return array + */ + public function getMarkers(Request $request) + { + abort_if(!$request->user(), 403); + $type = $request->input('timeline'); + if(!$type || !in_array($type, ['home', 'notifications'])) { + return $this->json([]); + } + $pid = $request->user()->profile_id; + return $this->json(MarkerService::get($pid, $type)); + } + + /** + * POST /api/v1/markers + * + * + * @return array + */ + public function setMarkers(Request $request) + { + abort_if(!$request->user(), 403); + $pid = $request->user()->profile_id; + $home = $request->input('home.last_read_id'); + $notifications = $request->input('notifications.last_read_id'); + + if($home) { + return $this->json(MarkerService::set($pid, 'home', $home)); + } + + if($notifications) { + return $this->json(MarkerService::set($pid, 'notifications', $notifications)); + } + + return $this->json([]); + } } diff --git a/app/Services/MarkerService.php b/app/Services/MarkerService.php new file mode 100644 index 000000000..619af9748 --- /dev/null +++ b/app/Services/MarkerService.php @@ -0,0 +1,28 @@ + (string) $entityId, + 'version' => $existing ? ($existing['version'] + 1) : 1, + 'updated_at' => now()->format('c') + ]; + Cache::put($key, $val, 2592000); + return $val; + } +} diff --git a/routes/api.php b/routes/api.php index 8626a7189..93d41caf4 100644 --- a/routes/api.php +++ b/routes/api.php @@ -87,6 +87,8 @@ Route::group(['prefix' => 'api'], function() use($middleware) { Route::get('preferences', 'Api\ApiV1Controller@getPreferences')->middleware($middleware); Route::get('trends', 'Api\ApiV1Controller@getTrends')->middleware($middleware); Route::get('announcements', 'Api\ApiV1Controller@getAnnouncements')->middleware($middleware); + Route::get('markers', 'Api\ApiV1Controller@getMarkers')->middleware($middleware); + Route::post('markers', 'Api\ApiV1Controller@setMarkers')->middleware($middleware); }); Route::group(['prefix' => 'v2'], function() use($middleware) {