forked from mirror/pixelfed
Update DiscoverController
This commit is contained in:
parent
25a71a9f5f
commit
4fe46723ee
1 changed files with 29 additions and 1 deletions
|
@ -3,10 +3,12 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\{
|
use App\{
|
||||||
|
DiscoverCategory,
|
||||||
Follower,
|
Follower,
|
||||||
Hashtag,
|
Hashtag,
|
||||||
Profile,
|
Profile,
|
||||||
Status,
|
Status,
|
||||||
|
StatusHashtag,
|
||||||
UserFilter
|
UserFilter
|
||||||
};
|
};
|
||||||
use Auth, DB, Cache;
|
use Auth, DB, Cache;
|
||||||
|
@ -51,4 +53,30 @@ class DiscoverController extends Controller
|
||||||
|
|
||||||
return view('discover.tags.show', compact('tag', 'posts'));
|
return view('discover.tags.show', compact('tag', 'posts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function showCategory(Request $request, $slug)
|
||||||
|
{
|
||||||
|
$tag = DiscoverCategory::whereActive(true)
|
||||||
|
->whereSlug($slug)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
// todo refactor this mess
|
||||||
|
$tagids = $tag->hashtags->pluck('id')->toArray();
|
||||||
|
$sids = StatusHashtag::whereIn('hashtag_id', $tagids)->orderByDesc('status_id')->take(500)->pluck('status_id')->toArray();
|
||||||
|
$posts = Status::whereIn('id', $sids)->whereNull('uri')->whereType('photo')->whereNull('in_reply_to_id')->whereNull('reblog_of_id')->orderByDesc('created_at')->paginate(21);
|
||||||
|
$tag->posts_count = $tag->posts()->count();
|
||||||
|
return view('discover.tags.category', compact('tag', 'posts'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showPersonal(Request $request)
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
// todo refactor this mess
|
||||||
|
$tags = Hashtag::whereHas('posts')->orderByRaw('rand()')->take(5)->get();
|
||||||
|
$following = $profile->following->pluck('id');
|
||||||
|
$following = $following->push($profile->id)->toArray();
|
||||||
|
$posts = Status::withCount(['likes','comments'])->whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->orderByDesc('created_at')->paginate(21);
|
||||||
|
$posts->post_count = Status::whereNotIn('profile_id', $following)->whereHas('media')->whereType('photo')->count();
|
||||||
|
return view('discover.personal', compact('posts', 'tags'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue