Merge pull request #2855 from pixelfed/staging

Staging
This commit is contained in:
daniel 2021-07-15 20:53:02 -06:00 committed by GitHub
commit f33422e758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 146 additions and 125 deletions

View file

@ -59,6 +59,7 @@
- Updated reply blade view, fix missing avatar and media images. ([5fb33772](https://github.com/pixelfed/pixelfed/commit/5fb33772)) - Updated reply blade view, fix missing avatar and media images. ([5fb33772](https://github.com/pixelfed/pixelfed/commit/5fb33772))
- Updated components, add fallback default avatar. ([726553f5](https://github.com/pixelfed/pixelfed/commit/726553f5)) - Updated components, add fallback default avatar. ([726553f5](https://github.com/pixelfed/pixelfed/commit/726553f5))
- Updated job queue, separate deletes into their own queue. ([7f421392](https://github.com/pixelfed/pixelfed/commit/7f421392)) - Updated job queue, separate deletes into their own queue. ([7f421392](https://github.com/pixelfed/pixelfed/commit/7f421392))
- Updated DiscoverController, use UserFilterService on trendingApi. ([135474ae](https://github.com/pixelfed/pixelfed/commit/135474ae))
- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0) ## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)

View file

@ -3,14 +3,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\{ use App\{
DiscoverCategory, DiscoverCategory,
Follower, Follower,
Hashtag, Hashtag,
HashtagFollow, HashtagFollow,
Profile, Profile,
Status, Status,
StatusHashtag, StatusHashtag,
UserFilter UserFilter
}; };
use Auth, DB, Cache; use Auth, DB, Cache;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -24,145 +24,165 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use App\Services\StatusHashtagService; use App\Services\StatusHashtagService;
use App\Services\SnowflakeService; use App\Services\SnowflakeService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Services\UserFilterService;
class DiscoverController extends Controller class DiscoverController extends Controller
{ {
protected $fractal; protected $fractal;
public function __construct() public function __construct()
{ {
$this->fractal = new Fractal\Manager(); $this->fractal = new Fractal\Manager();
$this->fractal->setSerializer(new ArraySerializer()); $this->fractal->setSerializer(new ArraySerializer());
} }
public function home(Request $request) public function home(Request $request)
{ {
abort_if(!Auth::check() && config('instance.discover.public') == false, 403); abort_if(!Auth::check() && config('instance.discover.public') == false, 403);
return view('discover.home'); return view('discover.home');
} }
public function showTags(Request $request, $hashtag) public function showTags(Request $request, $hashtag)
{ {
abort_if(!config('instance.discover.tags.is_public') && !Auth::check(), 403); abort_if(!config('instance.discover.tags.is_public') && !Auth::check(), 403);
$tag = Hashtag::whereName($hashtag) $tag = Hashtag::whereName($hashtag)
->orWhere('slug', $hashtag) ->orWhere('slug', $hashtag)
->firstOrFail(); ->firstOrFail();
$tagCount = StatusHashtagService::count($tag->id); $tagCount = StatusHashtagService::count($tag->id);
return view('discover.tags.show', compact('tag', 'tagCount')); return view('discover.tags.show', compact('tag', 'tagCount'));
} }
public function showCategory(Request $request, $slug) public function showCategory(Request $request, $slug)
{ {
abort(404); abort(404);
} }
public function showLoops(Request $request) public function showLoops(Request $request)
{ {
abort(404); abort(404);
} }
public function loopsApi(Request $request) public function loopsApi(Request $request)
{ {
abort(404); abort(404);
} }
public function loopWatch(Request $request) public function loopWatch(Request $request)
{ {
return response()->json(200); return response()->json(200);
} }
public function getHashtags(Request $request) public function getHashtags(Request $request)
{ {
$auth = Auth::check(); $auth = Auth::check();
abort_if(!config('instance.discover.tags.is_public') && !$auth, 403); abort_if(!config('instance.discover.tags.is_public') && !$auth, 403);
$this->validate($request, [ $this->validate($request, [
'hashtag' => 'required|string|min:1|max:124', 'hashtag' => 'required|string|min:1|max:124',
'page' => 'nullable|integer|min:1|max:' . ($auth ? 29 : 10) 'page' => 'nullable|integer|min:1|max:' . ($auth ? 29 : 10)
]); ]);
$page = $request->input('page') ?? '1'; $page = $request->input('page') ?? '1';
$end = $page > 1 ? $page * 9 : 0; $end = $page > 1 ? $page * 9 : 0;
$tag = $request->input('hashtag'); $tag = $request->input('hashtag');
$hashtag = Hashtag::whereName($tag)->firstOrFail(); $hashtag = Hashtag::whereName($tag)->firstOrFail();
if($page == 1) { if($page == 1) {
$res['follows'] = HashtagFollow::whereUserId(Auth::id()) $res['follows'] = HashtagFollow::whereUserId(Auth::id())
->whereHashtagId($hashtag->id) ->whereHashtagId($hashtag->id)
->exists(); ->exists();
} }
$res['hashtag'] = [ $res['hashtag'] = [
'name' => $hashtag->name, 'name' => $hashtag->name,
'url' => $hashtag->url() 'url' => $hashtag->url()
]; ];
$res['tags'] = StatusHashtagService::get($hashtag->id, $page, $end); $res['tags'] = StatusHashtagService::get($hashtag->id, $page, $end);
return $res; return $res;
} }
public function profilesDirectory(Request $request) public function profilesDirectory(Request $request)
{ {
return redirect('/') return redirect('/')
->with('statusRedirect', 'The Profile Directory is unavailable at this time.'); ->with('statusRedirect', 'The Profile Directory is unavailable at this time.');
} }
public function profilesDirectoryApi(Request $request) public function profilesDirectoryApi(Request $request)
{ {
return ['error' => 'Temporarily unavailable.']; return ['error' => 'Temporarily unavailable.'];
} }
public function trendingApi(Request $request) public function trendingApi(Request $request)
{ {
abort_if(config('instance.discover.public') == false && !Auth::check(), 403); abort_if(config('instance.discover.public') == false && !Auth::check(), 403);
$this->validate($request, [ $this->validate($request, [
'range' => 'nullable|string|in:daily,monthly' 'range' => 'nullable|string|in:daily,monthly'
]); ]);
$range = $request->input('range') == 'monthly' ? 31 : 1; $range = $request->input('range') == 'monthly' ? 31 : 1;
$key = ':api:discover:trending:v2.8:range:' . $range; $key = ':api:discover:trending:v2.8:range:' . $range;
$ttl = now()->addMinutes(15); $ttl = now()->addMinutes(15);
$ids = Cache::remember($key, $ttl, function() use($range) { $ids = Cache::remember($key, $ttl, function() use($range) {
$days = $range == 1 ? 2 : 31; $days = $range == 1 ? 2 : 31;
$min_id = SnowflakeService::byDate(now()->subDays($days)); $min_id = SnowflakeService::byDate(now()->subDays($days));
return Status::select( return Status::select(
'id', 'id',
'scope', 'scope',
'type', 'type',
'is_nsfw', 'is_nsfw',
'likes_count', 'likes_count',
'created_at' 'created_at'
) )
->where('id', '>', $min_id) ->where('id', '>', $min_id)
->whereNull('uri') ->whereNull('uri')
->whereScope('public') ->whereScope('public')
->whereIn('type', [ ->whereIn('type', [
'photo', 'photo',
'photo:album', 'photo:album',
'video' 'video'
]) ])
->whereIsNsfw(false) ->whereIsNsfw(false)
->orderBy('likes_count','desc') ->orderBy('likes_count','desc')
->take(15) ->take(15)
->pluck('id'); ->pluck('id');
}); });
$res = $ids->map(function($s) { $filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
return StatusService::get($s);
});
return response()->json($res); $res = $ids->map(function($s) {
} return StatusService::get($s);
})->filter(function($s) use($filtered) {
return $s && !in_array($s['account']['id'], $filtered);
})->values();
public function trendingHashtags(Request $request) return response()->json($res);
{ }
return [];
}
public function trendingPlaces(Request $request) public function trendingHashtags(Request $request)
{ {
return []; $res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
} ->groupBy('hashtag_id')
->orderBy('total','desc')
->where('created_at', '>', now()->subDays(90))
->take(9)
->get()
->map(function($h) {
$hashtag = $h->hashtag;
return [
'id' => $hashtag->id,
'total' => $h->total,
'name' => '#'.$hashtag->name,
'url' => $hashtag->url('?src=dsh1')
];
});
return $res;
}
public function trendingPlaces(Request $request)
{
return [];
}
} }

View file

@ -54,7 +54,7 @@ class UserFilterService {
public static function filters(int $profile_id) : array public static function filters(int $profile_id) : array
{ {
return array_merge(self::mutes($profile_id), self::blocks($profile_id)); return array_unique(array_merge(self::mutes($profile_id), self::blocks($profile_id)));
} }
public static function mute(int $profile_id, int $muted_id) public static function mute(int $profile_id, int $muted_id)
@ -98,4 +98,4 @@ class UserFilterService {
} }
return $exists; return $exists;
} }
} }