mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-03-03 10:16:05 +00:00
Update PublicApiController, use AccountService in accountStatuses method
This commit is contained in:
parent
80d9b9399a
commit
bef959f451
1 changed files with 71 additions and 78 deletions
|
@ -51,11 +51,11 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
protected function getUserData($user)
|
protected function getUserData($user)
|
||||||
{
|
{
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
return AccountService::get($user->profile_id);
|
return AccountService::get($user->profile_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getLikes($status)
|
protected function getLikes($status)
|
||||||
|
@ -94,12 +94,12 @@ class PublicApiController extends Controller
|
||||||
$status = Status::whereProfileId($profile->id)->findOrFail($postid);
|
$status = Status::whereProfileId($profile->id)->findOrFail($postid);
|
||||||
$this->scopeCheck($profile, $status);
|
$this->scopeCheck($profile, $status);
|
||||||
if(!$request->user()) {
|
if(!$request->user()) {
|
||||||
$res = ['status' => StatusService::get($status->id)];
|
$res = ['status' => StatusService::get($status->id)];
|
||||||
} else {
|
} else {
|
||||||
$item = new Fractal\Resource\Item($status, new StatusStatelessTransformer());
|
$item = new Fractal\Resource\Item($status, new StatusStatelessTransformer());
|
||||||
$res = [
|
$res = [
|
||||||
'status' => $this->fractal->createData($item)->toArray(),
|
'status' => $this->fractal->createData($item)->toArray(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
@ -200,14 +200,14 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
public function statusLikes(Request $request, $username, $id)
|
public function statusLikes(Request $request, $username, $id)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 404);
|
abort_if(!$request->user(), 404);
|
||||||
$status = Status::findOrFail($id);
|
$status = Status::findOrFail($id);
|
||||||
$this->scopeCheck($status->profile, $status);
|
$this->scopeCheck($status->profile, $status);
|
||||||
$page = $request->input('page');
|
$page = $request->input('page');
|
||||||
if($page && $page >= 3 && $request->user()->profile_id != $status->profile_id) {
|
if($page && $page >= 3 && $request->user()->profile_id != $status->profile_id) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => []
|
'data' => []
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$likes = $this->getLikes($status);
|
$likes = $this->getLikes($status);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
@ -217,15 +217,15 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
public function statusShares(Request $request, $username, $id)
|
public function statusShares(Request $request, $username, $id)
|
||||||
{
|
{
|
||||||
abort_if(!$request->user(), 404);
|
abort_if(!$request->user(), 404);
|
||||||
$profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
|
$profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
|
||||||
$status = Status::whereProfileId($profile->id)->findOrFail($id);
|
$status = Status::whereProfileId($profile->id)->findOrFail($id);
|
||||||
$this->scopeCheck($profile, $status);
|
$this->scopeCheck($profile, $status);
|
||||||
$page = $request->input('page');
|
$page = $request->input('page');
|
||||||
if($page && $page >= 3 && $request->user()->profile_id != $status->profile_id) {
|
if($page && $page >= 3 && $request->user()->profile_id != $status->profile_id) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => []
|
'data' => []
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$shares = $this->getShares($status);
|
$shares = $this->getShares($status);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
@ -300,7 +300,7 @@ class PublicApiController extends Controller
|
||||||
'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'])
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
|
@ -335,7 +335,7 @@ class PublicApiController extends Controller
|
||||||
'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'])
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
|
@ -343,8 +343,8 @@ class PublicApiController extends Controller
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->simplePaginate($limit);
|
->simplePaginate($limit);
|
||||||
|
|
||||||
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
||||||
$res = $this->fractal->createData($fractal)->toArray();
|
$res = $this->fractal->createData($fractal)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
@ -389,12 +389,12 @@ class PublicApiController extends Controller
|
||||||
});
|
});
|
||||||
|
|
||||||
if($recentFeed == true) {
|
if($recentFeed == true) {
|
||||||
$key = 'profile:home-timeline-cursor:'.$user->id;
|
$key = 'profile:home-timeline-cursor:'.$user->id;
|
||||||
$ttl = now()->addMinutes(30);
|
$ttl = now()->addMinutes(30);
|
||||||
$min = Cache::remember($key, $ttl, function() use($pid) {
|
$min = Cache::remember($key, $ttl, function() use($pid) {
|
||||||
$res = StatusView::whereProfileId($pid)->orderByDesc('status_id')->first();
|
$res = StatusView::whereProfileId($pid)->orderByDesc('status_id')->first();
|
||||||
return $res ? $res->status_id : null;
|
return $res ? $res->status_id : null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
|
||||||
|
@ -403,16 +403,16 @@ class PublicApiController extends Controller
|
||||||
$textOnlyReplies = false;
|
$textOnlyReplies = false;
|
||||||
|
|
||||||
if(config('exp.top')) {
|
if(config('exp.top')) {
|
||||||
$textOnlyPosts = (bool) Redis::zscore('pf:tl:top', $pid);
|
$textOnlyPosts = (bool) Redis::zscore('pf:tl:top', $pid);
|
||||||
$textOnlyReplies = (bool) Redis::zscore('pf:tl:replies', $pid);
|
$textOnlyReplies = (bool) Redis::zscore('pf:tl:replies', $pid);
|
||||||
|
|
||||||
if($textOnlyPosts) {
|
if($textOnlyPosts) {
|
||||||
array_push($types, 'text');
|
array_push($types, 'text');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config('exp.polls') == true) {
|
if(config('exp.polls') == true) {
|
||||||
array_push($types, 'poll');
|
array_push($types, 'poll');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($min || $max) {
|
if($min || $max) {
|
||||||
|
@ -438,10 +438,10 @@ class PublicApiController extends Controller
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)
|
)
|
||||||
->whereIn('type', $types)
|
->whereIn('type', $types)
|
||||||
->when($textOnlyReplies != true, function($q, $textOnlyReplies) {
|
->when($textOnlyReplies != true, function($q, $textOnlyReplies) {
|
||||||
return $q->whereNull('in_reply_to_id');
|
return $q->whereNull('in_reply_to_id');
|
||||||
})
|
})
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->where('id', $dir, $id)
|
->where('id', $dir, $id)
|
||||||
->whereIn('profile_id', $following)
|
->whereIn('profile_id', $following)
|
||||||
|
@ -471,10 +471,10 @@ class PublicApiController extends Controller
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)
|
)
|
||||||
->whereIn('type', $types)
|
->whereIn('type', $types)
|
||||||
->when(!$textOnlyReplies, function($q, $textOnlyReplies) {
|
->when(!$textOnlyReplies, function($q, $textOnlyReplies) {
|
||||||
return $q->whereNull('in_reply_to_id');
|
return $q->whereNull('in_reply_to_id');
|
||||||
})
|
})
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereIn('profile_id', $following)
|
->whereIn('profile_id', $following)
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
|
@ -527,7 +527,7 @@ class PublicApiController extends Controller
|
||||||
'scope',
|
'scope',
|
||||||
'created_at',
|
'created_at',
|
||||||
)
|
)
|
||||||
->where('id', $dir, $id)
|
->where('id', $dir, $id)
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereNotNull('uri')
|
->whereNotNull('uri')
|
||||||
|
@ -543,19 +543,19 @@ class PublicApiController extends Controller
|
||||||
});
|
});
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
} else {
|
} else {
|
||||||
$timeline = Status::select(
|
$timeline = Status::select(
|
||||||
'id',
|
'id',
|
||||||
'uri',
|
'uri',
|
||||||
'type',
|
'type',
|
||||||
'scope',
|
'scope',
|
||||||
'created_at',
|
'created_at',
|
||||||
)
|
)
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereNotNull('uri')
|
->whereNotNull('uri')
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
->where('id', '>', $amin)
|
->where('id', '>', $amin)
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use ($user) {
|
->map(function($s) use ($user) {
|
||||||
|
@ -563,7 +563,7 @@ class PublicApiController extends Controller
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
return $status;
|
return $status;
|
||||||
});
|
});
|
||||||
$res = $timeline->toArray();
|
$res = $timeline->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
|
@ -605,10 +605,10 @@ class PublicApiController extends Controller
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
if(!$profile->domain && !$profile->user->settings->show_profile_followers) {
|
if(!$profile->domain && !$profile->user->settings->show_profile_followers) {
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
if(!$owner && $request->page > 5) {
|
if(!$owner && $request->page > 5) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = Follower::select('id', 'profile_id', 'following_id')
|
$res = Follower::select('id', 'profile_id', 'following_id')
|
||||||
|
@ -639,11 +639,11 @@ class PublicApiController extends Controller
|
||||||
abort_if($owner == false && $profile->is_private == true && !$profile->followedBy(Auth::user()->profile), 404);
|
abort_if($owner == false && $profile->is_private == true && !$profile->followedBy(Auth::user()->profile), 404);
|
||||||
|
|
||||||
if(!$profile->domain) {
|
if(!$profile->domain) {
|
||||||
abort_if($profile->user->settings->show_profile_following == false && $owner == false, 404);
|
abort_if($profile->user->settings->show_profile_following == false && $owner == false, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$owner && $request->page > 5) {
|
if(!$owner && $request->page > 5) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if($search) {
|
if($search) {
|
||||||
|
@ -676,14 +676,15 @@ class PublicApiController extends Controller
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$profile = Profile::whereNull('status')->findOrFail($id);
|
$profile = AccountService::get($id);
|
||||||
|
abort_if(!$profile, 404);
|
||||||
|
|
||||||
$limit = $request->limit ?? 9;
|
$limit = $request->limit ?? 9;
|
||||||
$max_id = $request->max_id;
|
$max_id = $request->max_id;
|
||||||
$min_id = $request->min_id;
|
$min_id = $request->min_id;
|
||||||
$scope = ['photo', 'photo:album', 'video', 'video:album'];
|
$scope = ['photo', 'photo:album', 'video', 'video:album'];
|
||||||
|
|
||||||
if($profile->is_private) {
|
if($profile['locked']) {
|
||||||
if(!$user) {
|
if(!$user) {
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
|
@ -700,7 +701,7 @@ class PublicApiController extends Controller
|
||||||
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||||
return $following->push($pid)->toArray();
|
return $following->push($pid)->toArray();
|
||||||
});
|
});
|
||||||
$visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
$visibility = true == in_array($profile['id'], $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
||||||
} else {
|
} else {
|
||||||
$visibility = ['public', 'unlisted'];
|
$visibility = ['public', 'unlisted'];
|
||||||
}
|
}
|
||||||
|
@ -708,15 +709,7 @@ class PublicApiController extends Controller
|
||||||
|
|
||||||
$dir = $min_id ? '>' : '<';
|
$dir = $min_id ? '>' : '<';
|
||||||
$id = $min_id ?? $max_id;
|
$id = $min_id ?? $max_id;
|
||||||
$res = Status::select(
|
$res = Status::whereProfileId($profile['id'])
|
||||||
'id',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
|
||||||
'scope',
|
|
||||||
'local',
|
|
||||||
'created_at'
|
|
||||||
)
|
|
||||||
->whereProfileId($profile->id)
|
|
||||||
->whereNull('in_reply_to_id')
|
->whereNull('in_reply_to_id')
|
||||||
->whereNull('reblog_of_id')
|
->whereNull('reblog_of_id')
|
||||||
->whereIn('type', $scope)
|
->whereIn('type', $scope)
|
||||||
|
@ -726,18 +719,18 @@ class PublicApiController extends Controller
|
||||||
->orderByDesc('id')
|
->orderByDesc('id')
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($user) {
|
->map(function($s) use($user) {
|
||||||
try {
|
try {
|
||||||
$status = StatusService::get($s->id, false);
|
$status = StatusService::get($s->id, false);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$status = false;
|
$status = false;
|
||||||
}
|
}
|
||||||
if($user && $status) {
|
if($user && $status) {
|
||||||
$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) {
|
->filter(function($s) {
|
||||||
return $s;
|
return $s;
|
||||||
})
|
})
|
||||||
->values();
|
->values();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue