diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 09cd8b1ae..fada324fe 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -6,6 +6,7 @@ use App\Follower; use App\Hashtag; use App\Profile; use App\Status; +use App\UserFilter; use Auth; use Illuminate\Http\Request; @@ -23,6 +24,13 @@ class DiscoverController extends Controller $following = Follower::whereProfileId($pid) ->pluck('following_id'); + $filtered = UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id'); + + $following = $following->push($filtered); + $people = Profile::inRandomOrder() ->where('id', '!=', $pid) ->whereNotIn('id', $following) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 6449bcb3a..670bf3b2c 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -7,6 +7,7 @@ use App\EmailVerification; use App\Media; use App\Profile; use App\User; +use App\UserFilter; use App\Util\Lexer\PrettyNumber; use Auth; use DB; @@ -254,4 +255,64 @@ class SettingsController extends Controller { return view('settings.developers'); } + + public function mutedUsers() + { + $pid = Auth::user()->profile->id; + $ids = (new UserFilter())->mutedUserIds($pid); + $users = Profile::whereIn('id', $ids)->simplePaginate(15); + return view('settings.privacy.muted', compact('users')); + } + + public function mutedUsersUpdate(Request $request) + { + $this->validate($request, [ + 'profile_id' => 'required|integer|min:1' + ]); + $fid = $request->input('profile_id'); + $pid = Auth::user()->profile->id; + DB::transaction(function () use ($fid, $pid) { + $filter = UserFilter::whereUserId($pid) + ->whereFilterableId($fid) + ->whereFilterableType('App\Profile') + ->whereFilterType('mute') + ->firstOrFail(); + $filter->delete(); + }); + return redirect()->back(); + } + + public function blockedUsers() + { + $pid = Auth::user()->profile->id; + $ids = (new UserFilter())->blockedUserIds($pid); + $users = Profile::whereIn('id', $ids)->simplePaginate(15); + return view('settings.privacy.blocked', compact('users')); + } + + + public function blockedUsersUpdate(Request $request) + { + $this->validate($request, [ + 'profile_id' => 'required|integer|min:1' + ]); + $fid = $request->input('profile_id'); + $pid = Auth::user()->profile->id; + DB::transaction(function () use ($fid, $pid) { + $filter = UserFilter::whereUserId($pid) + ->whereFilterableId($fid) + ->whereFilterableType('App\Profile') + ->whereFilterType('block') + ->firstOrFail(); + $filter->delete(); + }); + return redirect()->back(); + } + + public function blockedInstances() + { + $settings = Auth::user()->settings; + return view('settings.privacy.blocked-instances'); + } } + diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index ec4b00d72..de6e0c874 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -7,6 +7,7 @@ use App\Follower; use App\Profile; use App\Status; use App\User; +use App\UserFilter; use App\Util\Lexer\PrettyNumber; use Auth; use Cache; @@ -30,10 +31,16 @@ class SiteController extends Controller public function homeTimeline() { + $pid = Auth::user()->profile->id; // TODO: Use redis for timelines $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id'); $following->push(Auth::user()->profile->id); + $filtered = UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id'); $timeline = Status::whereIn('profile_id', $following) + ->whereNotIn('profile_id', $filtered) ->whereHas('media') ->orderBy('id', 'desc') ->withCount(['comments', 'likes', 'shares']) diff --git a/app/UserFilter.php b/app/UserFilter.php index ab5fe321a..50cd5887e 100644 --- a/app/UserFilter.php +++ b/app/UserFilter.php @@ -12,4 +12,21 @@ class UserFilter extends Model 'filterable_type', 'filter_type', ]; + + public function mutedUserIds($profile_id) + { + return $this->whereUserId($profile_id) + ->whereFilterableType('App\Profile') + ->whereFilterType('mute') + ->pluck('filterable_id'); + } + + + public function blockedUserIds($profile_id) + { + return $this->whereUserId($profile_id) + ->whereFilterableType('App\Profile') + ->whereFilterType('block') + ->pluck('filterable_id'); + } } diff --git a/config/pixelfed.php b/config/pixelfed.php index 196571661..83fc883db 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -23,7 +23,7 @@ return [ | This value is the version of your PixelFed instance. | */ - 'version' => '0.1.7', + 'version' => '0.1.8', /* |-------------------------------------------------------------------------- diff --git a/resources/views/settings/partial/sidebar.blade.php b/resources/views/settings/partial/sidebar.blade.php index 18588b59a..04fa93991 100644 --- a/resources/views/settings/partial/sidebar.blade.php +++ b/resources/views/settings/partial/sidebar.blade.php @@ -16,7 +16,7 @@ Notifications --}} - {{--