mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update ApiV1Controller, add include_reblogs attribute to home timeline
This commit is contained in:
parent
c244d8b5c8
commit
37fd03428a
3 changed files with 17 additions and 7 deletions
|
@ -2132,7 +2132,8 @@ class ApiV1Controller extends Controller
|
|||
'page' => 'sometimes|integer|max:40',
|
||||
'min_id' => 'sometimes|integer|min:0|max:' . PHP_INT_MAX,
|
||||
'max_id' => 'sometimes|integer|min:0|max:' . PHP_INT_MAX,
|
||||
'limit' => 'sometimes|integer|min:1|max:100'
|
||||
'limit' => 'sometimes|integer|min:1|max:100',
|
||||
'include_reblogs' => 'sometimes',
|
||||
]);
|
||||
|
||||
$napi = $request->has(self::PF_API_ENTITY_KEY);
|
||||
|
@ -2141,6 +2142,13 @@ class ApiV1Controller extends Controller
|
|||
$max = $request->input('max_id');
|
||||
$limit = $request->input('limit') ?? 20;
|
||||
$pid = $request->user()->profile_id;
|
||||
$includeReblogs = $request->filled('include_reblogs');
|
||||
$nullFields = $includeReblogs ?
|
||||
['in_reply_to_id'] :
|
||||
['in_reply_to_id', 'reblog_of_id'];
|
||||
$inTypes = $includeReblogs ?
|
||||
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'share'] :
|
||||
['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
|
||||
|
||||
$following = Cache::remember('profile:following:'.$pid, 1209600, function() use($pid) {
|
||||
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||
|
@ -2159,9 +2167,9 @@ class ApiV1Controller extends Controller
|
|||
'reblog_of_id'
|
||||
)
|
||||
->where('id', $dir, $id)
|
||||
->whereNull(['in_reply_to_id', 'reblog_of_id'])
|
||||
->whereNull($nullFields)
|
||||
->whereIntegerInRaw('profile_id', $following)
|
||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||
->whereIn('type', $inTypes)
|
||||
->whereIn('visibility',['public', 'unlisted', 'private'])
|
||||
->orderByDesc('id')
|
||||
->take(($limit * 2))
|
||||
|
@ -2202,9 +2210,9 @@ class ApiV1Controller extends Controller
|
|||
'in_reply_to_id',
|
||||
'reblog_of_id',
|
||||
)
|
||||
->whereNull(['in_reply_to_id', 'reblog_of_id'])
|
||||
->whereNull($nullFields)
|
||||
->whereIntegerInRaw('profile_id', $following)
|
||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||
->whereIn('type', $inTypes)
|
||||
->whereIn('visibility',['public', 'unlisted', 'private'])
|
||||
->orderByDesc('id')
|
||||
->take(($limit * 2))
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Services\HashidService;
|
|||
use App\Services\LikeService;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusLabelService;
|
||||
use App\Services\StatusMentionService;
|
||||
|
@ -32,7 +33,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
|
|||
'url' => $status->url(),
|
||||
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||
'reblog' => null,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Services\HashidService;
|
|||
use App\Services\LikeService;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusLabelService;
|
||||
use App\Services\StatusMentionService;
|
||||
|
@ -35,7 +36,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
|
|||
'url' => $status->url(),
|
||||
'in_reply_to_id' => (string) $status->in_reply_to_id,
|
||||
'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id,
|
||||
'reblog' => null,
|
||||
'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id) : null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'content_text' => $status->caption,
|
||||
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||
|
|
Loading…
Reference in a new issue