mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Update Discover
This commit is contained in:
parent
7494d97bbd
commit
1ca76b3a3c
5 changed files with 102 additions and 23 deletions
|
@ -121,6 +121,7 @@ class InternalApiController extends Controller
|
||||||
return response()->json($notifications, 200, [], JSON_PRETTY_PRINT);
|
return response()->json($notifications, 200, [], JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deprecated
|
||||||
public function discover(Request $request)
|
public function discover(Request $request)
|
||||||
{
|
{
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
|
@ -176,6 +177,83 @@ class InternalApiController extends Controller
|
||||||
];
|
];
|
||||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function discoverPeople(Request $request)
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
$pid = $profile->id;
|
||||||
|
$following = Cache::remember('feature:discover:following:'.$pid, 60, function() use ($pid) {
|
||||||
|
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
||||||
|
});
|
||||||
|
$filters = Cache::remember("user:filter:list:$pid", 60, function() use($pid) {
|
||||||
|
return UserFilter::whereUserId($pid)
|
||||||
|
->whereFilterableType('App\Profile')
|
||||||
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
|
->pluck('filterable_id')->toArray();
|
||||||
|
});
|
||||||
|
$following = array_merge($following, $filters);
|
||||||
|
|
||||||
|
$people = Profile::select('id', 'name', 'username')
|
||||||
|
->with('avatar')
|
||||||
|
->orderByRaw('rand()')
|
||||||
|
->whereHas('statuses')
|
||||||
|
->whereNull('domain')
|
||||||
|
->whereNotIn('id', $following)
|
||||||
|
->whereIsPrivate(false)
|
||||||
|
->take(3)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$res = [
|
||||||
|
'people' => $people->map(function($profile) {
|
||||||
|
return [
|
||||||
|
'id' => $profile->id,
|
||||||
|
'avatar' => $profile->avatarUrl(),
|
||||||
|
'name' => $profile->name,
|
||||||
|
'username' => $profile->username,
|
||||||
|
'url' => $profile->url(),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function discoverPosts(Request $request)
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
$pid = $profile->id;
|
||||||
|
$following = Cache::remember('feature:discover:following:'.$pid, 60, function() use ($pid) {
|
||||||
|
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
|
||||||
|
});
|
||||||
|
$filters = Cache::remember("user:filter:list:$pid", 60, function() use($pid) {
|
||||||
|
return UserFilter::whereUserId($pid)
|
||||||
|
->whereFilterableType('App\Profile')
|
||||||
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
|
->pluck('filterable_id')->toArray();
|
||||||
|
});
|
||||||
|
$following = array_merge($following, $filters);
|
||||||
|
|
||||||
|
$posts = Status::select('id', 'caption', 'profile_id')
|
||||||
|
->whereNull('in_reply_to_id')
|
||||||
|
->whereNull('reblog_of_id')
|
||||||
|
->whereIsNsfw(false)
|
||||||
|
->whereVisibility('public')
|
||||||
|
->whereNotIn('profile_id', $following)
|
||||||
|
->with('media')
|
||||||
|
->orderBy('created_at', 'desc')
|
||||||
|
->take(21)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$res = [
|
||||||
|
'posts' => $posts->map(function($post) {
|
||||||
|
return [
|
||||||
|
'url' => $post->url(),
|
||||||
|
'thumb' => $post->thumb(),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
return response()->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
public function directMessage(Request $request, $profileId, $threadId)
|
public function directMessage(Request $request, $profileId, $threadId)
|
||||||
{
|
{
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
|
|
BIN
public/js/components.js
vendored
BIN
public/js/components.js
vendored
Binary file not shown.
Binary file not shown.
|
@ -55,11 +55,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.slowTimeout();
|
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
followUser(id, event) {
|
followUser(id, event) {
|
||||||
axios.post('/i/follow', {
|
axios.post('/i/follow', {
|
||||||
item: id
|
item: id
|
||||||
|
@ -75,30 +75,29 @@ export default {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get('/api/v2/discover')
|
axios.get('/api/v2/discover/people')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
this.people = data.people;
|
this.people = data.people;
|
||||||
this.posts = data.posts;
|
|
||||||
|
|
||||||
if(this.people.length > 1) {
|
if(this.people.length > 1) {
|
||||||
$('.section-people .loader').hide();
|
$('.section-people .loader').hide();
|
||||||
$('.section-people .row.d-none').removeClass('d-none');
|
$('.section-people .row.d-none').removeClass('d-none');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
axios.get('/api/v2/discover/posts')
|
||||||
|
.then((res) => {
|
||||||
|
let data = res.data;
|
||||||
|
this.posts = data.posts;
|
||||||
|
|
||||||
if(this.posts.length > 1) {
|
if(this.posts.length > 1) {
|
||||||
$('.section-explore .loader').hide();
|
$('.section-explore .loader').hide();
|
||||||
$('.section-explore .row.d-none').removeClass('d-none');
|
$('.section-explore .row.d-none').removeClass('d-none');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
|
||||||
slowTimeout() {
|
|
||||||
setTimeout(function() {
|
|
||||||
let el = $('<p>').addClass('font-weight-bold').text('This is taking longer than expected to load. Please try reloading the page if this does not load after 30 seconds.');
|
|
||||||
$('.section-people .loader').append(el);
|
|
||||||
$('.section-explore .loader').append(el);
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::get('notifications', 'InternalApiController@notifications');
|
Route::get('notifications', 'InternalApiController@notifications');
|
||||||
Route::post('notifications', 'InternalApiController@notificationMarkAllRead');
|
Route::post('notifications', 'InternalApiController@notificationMarkAllRead');
|
||||||
Route::get('discover', 'InternalApiController@discover');
|
Route::get('discover', 'InternalApiController@discover');
|
||||||
|
Route::get('discover/people', 'InternalApiController@discoverPeople');
|
||||||
|
Route::get('discover/posts', 'InternalApiController@discoverPosts');
|
||||||
Route::get('profile/{username}/status/{postid}', 'PublicApiController@status');
|
Route::get('profile/{username}/status/{postid}', 'PublicApiController@status');
|
||||||
Route::get('comments/{username}/status/{postId}', 'PublicApiController@statusComments');
|
Route::get('comments/{username}/status/{postId}', 'PublicApiController@statusComments');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue