mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Update PublicApiController
This commit is contained in:
parent
fe64e18712
commit
2923453e13
1 changed files with 95 additions and 101 deletions
|
@ -27,6 +27,7 @@ use App\Transformer\Api\{
|
||||||
};
|
};
|
||||||
use App\Services\{
|
use App\Services\{
|
||||||
AccountService,
|
AccountService,
|
||||||
|
FollowerService,
|
||||||
LikeService,
|
LikeService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
ProfileService,
|
ProfileService,
|
||||||
|
@ -151,13 +152,8 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
if(Auth::check()) {
|
if(Auth::check()) {
|
||||||
$p = Auth::user()->profile;
|
$p = Auth::user()->profile;
|
||||||
$filtered = UserFilter::whereUserId($p->id)
|
$scope = $p->id == $status->profile_id || FollowerService::follows($p->id, $profile->id) ? ['public', 'private', 'unlisted'] : ['public','unlisted'];
|
||||||
->whereFilterableType('App\Profile')
|
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
|
||||||
->pluck('filterable_id')->toArray();
|
|
||||||
$scope = $p->id == $status->profile_id ? ['public', 'private', 'unlisted'] : ['public','unlisted'];
|
|
||||||
} else {
|
} else {
|
||||||
$filtered = [];
|
|
||||||
$scope = ['public', 'unlisted'];
|
$scope = ['public', 'unlisted'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +162,6 @@ class PublicApiController extends Controller
|
||||||
$replies = $status->comments()
|
$replies = $status->comments()
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->whereNotIn('profile_id', $filtered)
|
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->where('id', '>=', $request->min_id)
|
->where('id', '>=', $request->min_id)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
|
@ -176,17 +171,15 @@ class PublicApiController extends Controller
|
||||||
$replies = $status->comments()
|
$replies = $status->comments()
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->whereNotIn('profile_id', $filtered)
|
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->where('id', '<=', $request->max_id)
|
->where('id', '<=', $request->max_id)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$replies = $status->comments()
|
$replies = Status::whereInReplyToId($status->id)
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('scope', $scope)
|
->whereIn('scope', $scope)
|
||||||
->whereNotIn('profile_id', $filtered)
|
|
||||||
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
->select('id', 'caption', 'local', 'visibility', 'scope', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
@ -290,100 +283,100 @@ class PublicApiController extends Controller
|
||||||
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
||||||
|
|
||||||
if(config('exp.cached_public_timeline') == false) {
|
if(config('exp.cached_public_timeline') == false) {
|
||||||
if($min || $max) {
|
if($min || $max) {
|
||||||
$dir = $min ? '>' : '<';
|
$dir = $min ? '>' : '<';
|
||||||
$id = $min ?? $max;
|
$id = $min ?? $max;
|
||||||
$timeline = Status::select(
|
$timeline = Status::select(
|
||||||
'id',
|
'id',
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'type',
|
'type',
|
||||||
'scope',
|
'scope',
|
||||||
'local'
|
'local'
|
||||||
)
|
)
|
||||||
->where('id', $dir, $id)
|
->where('id', $dir, $id)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use ($user) {
|
->map(function($s) use ($user) {
|
||||||
$status = StatusService::getFull($s->id, $user->profile_id);
|
$status = StatusService::getFull($s->id, $user->profile_id);
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
return in_array($s['account']['id'], $filtered) == false;
|
return in_array($s['account']['id'], $filtered) == false;
|
||||||
});
|
});
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
} else {
|
} else {
|
||||||
$timeline = Status::select(
|
$timeline = Status::select(
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'caption',
|
'caption',
|
||||||
'rendered',
|
'rendered',
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'type',
|
'type',
|
||||||
'in_reply_to_id',
|
'in_reply_to_id',
|
||||||
'reblog_of_id',
|
'reblog_of_id',
|
||||||
'is_nsfw',
|
'is_nsfw',
|
||||||
'scope',
|
'scope',
|
||||||
'local',
|
'local',
|
||||||
'reply_count',
|
'reply_count',
|
||||||
'comments_disabled',
|
'comments_disabled',
|
||||||
'created_at',
|
'created_at',
|
||||||
'place_id',
|
'place_id',
|
||||||
'likes_count',
|
'likes_count',
|
||||||
'reblogs_count',
|
'reblogs_count',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)
|
)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use ($user) {
|
->map(function($s) use ($user) {
|
||||||
$status = StatusService::getFull($s->id, $user->profile_id);
|
$status = StatusService::getFull($s->id, $user->profile_id);
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
return in_array($s['account']['id'], $filtered) == false;
|
return in_array($s['account']['id'], $filtered) == false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
|
Cache::remember('api:v1:timelines:public:cache_check', 10368000, function() {
|
||||||
if(PublicTimelineService::count() == 0) {
|
if(PublicTimelineService::count() == 0) {
|
||||||
PublicTimelineService::warmCache(true, 400);
|
PublicTimelineService::warmCache(true, 400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($max) {
|
if ($max) {
|
||||||
$feed = PublicTimelineService::getRankedMaxId($max, $limit);
|
$feed = PublicTimelineService::getRankedMaxId($max, $limit);
|
||||||
} else if ($min) {
|
} else if ($min) {
|
||||||
$feed = PublicTimelineService::getRankedMinId($min, $limit);
|
$feed = PublicTimelineService::getRankedMinId($min, $limit);
|
||||||
} else {
|
} else {
|
||||||
$feed = PublicTimelineService::get(0, $limit);
|
$feed = PublicTimelineService::get(0, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = collect($feed)
|
$res = collect($feed)
|
||||||
->map(function($k) use($user) {
|
->map(function($k) use($user) {
|
||||||
$status = StatusService::get($k);
|
$status = StatusService::get($k);
|
||||||
if($user) {
|
if($user) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
})
|
})
|
||||||
->filter(function($s) use($filtered) {
|
->filter(function($s) use($filtered) {
|
||||||
return in_array($s['account']['id'], $filtered) == false;
|
return in_array($s['account']['id'], $filtered) == false;
|
||||||
})
|
})
|
||||||
->values()
|
->values()
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
@ -438,6 +431,7 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
||||||
$types = ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
|
$types = ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'];
|
||||||
|
// $types = ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album', 'text'];
|
||||||
|
|
||||||
$textOnlyReplies = false;
|
$textOnlyReplies = false;
|
||||||
|
|
||||||
|
@ -625,7 +619,7 @@ class PublicApiController extends Controller
|
||||||
return $v != $pid;
|
return $v != $pid;
|
||||||
})
|
})
|
||||||
->map(function($id) use($pid) {
|
->map(function($id) use($pid) {
|
||||||
return RelationshipService::get($pid, $id);
|
return RelationshipService::get($pid, $id);
|
||||||
});
|
});
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
|
Loading…
Add table
Reference in a new issue