Update ApiV1Controller, fix notification entities

pull/3329/head
Daniel Supernault 2022-03-23 00:28:39 -06:00
rodzic 244869b7c2
commit afe903c36e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 0DEF1C662C9033F7
2 zmienionych plików z 75 dodań i 18 usunięć

Wyświetl plik

@ -1589,14 +1589,14 @@ class ApiV1Controller extends Controller
$minId = null;
if($max) {
$res = NotificationService::getMax($pid, $max, $limit);
$res = NotificationService::getMaxMastodon($pid, $max, $limit);
$ids = NotificationService::getRankedMaxId($pid, $max, $limit);
if(!empty($ids)) {
$maxId = max($ids);
$minId = min($ids);
}
} else {
$res = NotificationService::getMin($pid, $min ?? $since, $limit);
$res = NotificationService::getMinMastodon($pid, $min ?? $since, $limit);
$ids = NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
if(!empty($ids)) {
$maxId = max($ids);
@ -2216,9 +2216,7 @@ class ApiV1Controller extends Controller
Cache::forget('profile:embed:' . $status->profile_id);
Cache::forget($limitKey);
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res = StatusService::getMastodon($status->id, false);
return $this->json($res);
}
@ -2318,16 +2316,16 @@ class ApiV1Controller extends Controller
->first();
if(!$reblog) {
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
return response()->json($res);
$res = StatusService::getMastodon($status->id);
$res['reblogged'] = false;
return $this->json($res);
}
UndoSharePipeline::dispatch($reblog);
ReblogService::del($user->profile_id, $status->id);
$res = StatusService::getMastodon($status->id);
$res['reblogged'] = true;
$res['reblogged'] = false;
return $this->json($res);
}
@ -2454,8 +2452,7 @@ class ApiV1Controller extends Controller
'status_id' => $status->id,
'profile_id' => $request->user()->profile_id
]);
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res = StatusService::getMastodon($status->id);
return $this->json($res);
}
@ -2475,17 +2472,11 @@ class ApiV1Controller extends Controller
->whereScope('public')
->findOrFail($id);
Bookmark::firstOrCreate([
'status_id' => $status->id,
'profile_id' => $request->user()->profile_id
]);
$bookmark = Bookmark::whereStatusId($status->id)
->whereProfileId($request->user()->profile_id)
->firstOrFail();
$bookmark->delete();
$resource = new Fractal\Resource\Item($status, new StatusTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res = StatusService::getMastodon($status->id);
return $this->json($res);
}

Wyświetl plik

@ -16,6 +16,15 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
class NotificationService {
const CACHE_KEY = 'pf:services:notifications:ids:';
const MASTODON_TYPES = [
'follow',
'follow_request',
'mention',
'reblog',
'favourite',
'poll',
'status'
];
public static function get($id, $start = 0, $stop = 400)
{
@ -85,6 +94,63 @@ class NotificationService {
return $res->toArray();
}
public static function getMaxMastodon($id = false, $start = 0, $limit = 10)
{
$ids = self::getRankedMaxId($id, $start, $limit);
if(empty($ids)) {
return [];
}
$res = collect([]);
foreach($ids as $id) {
$n = self::getNotification($id);
if($n != null && in_array($n['type'], self::MASTODON_TYPES)) {
$n['account'] = AccountService::getMastodon($n['account']['id']);
if(isset($n['relationship'])) {
unset($n['relationship']);
}
if(isset($n['status'])) {
$n['status'] = StatusService::getMastodon($n['status']['id'], false);
}
$res->push($n);
}
}
return $res->toArray();
}
public static function getMinMastodon($id = false, $start = 0, $limit = 10)
{
$ids = self::getRankedMinId($id, $start, $limit);
if(empty($ids)) {
return [];
}
$res = collect([]);
foreach($ids as $id) {
$n = self::getNotification($id);
if($n != null && in_array($n['type'], self::MASTODON_TYPES)) {
$n['account'] = AccountService::getMastodon($n['account']['id']);
if(isset($n['relationship'])) {
unset($n['relationship']);
}
if(isset($n['status'])) {
$n['status'] = StatusService::getMastodon($n['status']['id'], false);
}
$res->push($n);
}
}
return $res->toArray();
}
public static function getRankedMaxId($id = false, $start = null, $limit = 10)
{
if(!$start || !$id) {