kopia lustrzana https://github.com/pixelfed/pixelfed
				
				
				
			Update Timeline, make text-only posts opt-in by default
							rodzic
							
								
									08f492bd3d
								
							
						
					
					
						commit
						0153ed6d64
					
				|  | @ -16,6 +16,7 @@ use App\{ | |||
|     UserFilter | ||||
| }; | ||||
| use Auth, Cache; | ||||
| use Illuminate\Support\Facades\Redis; | ||||
| use Carbon\Carbon; | ||||
| use League\Fractal; | ||||
| use App\Transformer\Api\{ | ||||
|  | @ -401,6 +402,11 @@ class PublicApiController extends Controller | |||
|         } | ||||
| 
 | ||||
|         $filtered = $user ? UserFilterService::filters($user->profile_id) : []; | ||||
|         $textOnlyPosts = Redis::zscore('pf:tl:top', $pid) !== false; | ||||
|         $textOnlyReplies = Redis::zscore('pf:tl:replies', $pid) !== false; | ||||
|         $types = $textOnlyPosts ? | ||||
|         	['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'] : | ||||
|         	['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']; | ||||
| 
 | ||||
|         if($min || $max) { | ||||
|             $dir = $min ? '>' : '<'; | ||||
|  | @ -425,12 +431,14 @@ class PublicApiController extends Controller | |||
|                         'created_at', | ||||
|                         'updated_at' | ||||
|                       ) | ||||
|             		  ->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) | ||||
|             		  ->whereIn('type', $types) | ||||
|                       ->when(!$textOnlyReplies, function($q, $textOnlyReplies) { | ||||
|                       	return $q->whereNull('in_reply_to_id'); | ||||
|                   	  }) | ||||
|                       ->with('profile', 'hashtags', 'mentions') | ||||
|                       ->where('id', $dir, $id) | ||||
|                       ->whereIn('profile_id', $following) | ||||
|                       ->whereNotIn('profile_id', $filtered) | ||||
|                       ->whereNull('in_reply_to_id') | ||||
|                       ->whereIn('visibility',['public', 'unlisted', 'private']) | ||||
|                       ->orderBy('created_at', 'desc') | ||||
|                       ->limit($limit) | ||||
|  | @ -456,11 +464,13 @@ class PublicApiController extends Controller | |||
|                         'created_at', | ||||
|                         'updated_at' | ||||
|                       ) | ||||
|             		  ->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) | ||||
|             		  ->whereIn('type', $types) | ||||
|             		  ->when(!$textOnlyReplies, function($q, $textOnlyReplies) { | ||||
|                       	return $q->whereNull('in_reply_to_id'); | ||||
|                   	  }) | ||||
|                       ->with('profile', 'hashtags', 'mentions') | ||||
|                       ->whereIn('profile_id', $following) | ||||
|                       ->whereNotIn('profile_id', $filtered) | ||||
|                       ->whereNull('in_reply_to_id') | ||||
|                       ->whereIn('visibility',['public', 'unlisted', 'private']) | ||||
|                       ->orderBy('created_at', 'desc') | ||||
|                       ->simplePaginate($limit); | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ use App\ProfileSponsor; | |||
| use App\Report; | ||||
| use App\UserFilter; | ||||
| use Auth, Cookie, DB, Cache, Purify; | ||||
| use Illuminate\Support\Facades\Redis; | ||||
| use Carbon\Carbon; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Str; | ||||
|  | @ -223,5 +224,33 @@ class SettingsController extends Controller | |||
| 		return redirect(route('settings'))->with('status', 'Sponsor settings successfully updated!');; | ||||
| 	} | ||||
| 
 | ||||
| 	public function timelineSettings(Request $request) | ||||
| 	{ | ||||
| 		$pid = $request->user()->profile_id; | ||||
| 		$top = Redis::zscore('pf:tl:top', $pid) != false; | ||||
| 		$replies = Redis::zscore('pf:tl:replies', $pid) != false; | ||||
| 		return view('settings.timeline', compact('top', 'replies')); | ||||
| 	} | ||||
| 
 | ||||
| 	public function updateTimelineSettings(Request $request) | ||||
| 	{ | ||||
| 		$pid = $request->user()->profile_id; | ||||
| 		$top = $request->has('top') && $request->input('top') === 'on'; | ||||
| 		$replies = $request->has('replies') && $request->input('replies') === 'on'; | ||||
| 
 | ||||
| 		if($top) { | ||||
| 			Redis::zadd('pf:tl:top', $pid, $pid); | ||||
| 		} else { | ||||
| 			Redis::zrem('pf:tl:top', $pid, $pid); | ||||
| 		} | ||||
| 
 | ||||
| 		if($replies) { | ||||
| 			Redis::zadd('pf:tl:replies', $pid, $pid); | ||||
| 		} else { | ||||
| 			Redis::zrem('pf:tl:replies', $pid, $pid); | ||||
| 		} | ||||
| 		return redirect(route('settings.timeline')); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,6 +29,9 @@ | |||
| 			<li class="nav-item pl-3 {{request()->is('settings/security*')?'active':''}}"> | ||||
| 				<a class="nav-link font-weight-light text-muted" href="{{route('settings.security')}}">Security</a> | ||||
| 			</li> | ||||
| 			<li class="nav-item pl-3 {{request()->is('settings/timeline*')?'active':''}}"> | ||||
| 				<a class="nav-link font-weight-light text-muted" href="{{route('settings.timeline')}}">Timelines</a> | ||||
| 			</li> | ||||
| 			<li class="nav-item"> | ||||
| 				<hr> | ||||
| 			</li> | ||||
|  |  | |||
|  | @ -0,0 +1,30 @@ | |||
| @extends('settings.template') | ||||
| 
 | ||||
| @section('section') | ||||
| 
 | ||||
| 	<div class="title"> | ||||
| 		<h3 class="font-weight-bold">Timeline Settings</h3> | ||||
| 	</div> | ||||
| 	<hr> | ||||
| 	<form method="post"> | ||||
| 		@csrf | ||||
| 		<div class="form-check pb-3"> | ||||
| 			<input class="form-check-input" type="checkbox" name="top" {{$top ? 'checked':''}}> | ||||
| 			<label class="form-check-label font-weight-bold" for="">Show text-only posts</label> | ||||
| 			<p class="text-muted small help-text">Show text-only posts from accounts you follow. (Home timeline only)</p> | ||||
| 		</div> | ||||
| 		<div class="form-check pb-3"> | ||||
| 			<input class="form-check-input" type="checkbox" name="replies" {{$replies ? 'checked':''}}> | ||||
| 			<label class="form-check-label font-weight-bold" for="">Show replies</label> | ||||
| 			<p class="text-muted small help-text">Show replies from accounts you follow. (Home timeline only)</p> | ||||
| 		</div> | ||||
| 
 | ||||
| 		<div class="form-group row mt-5 pt-5"> | ||||
| 			<div class="col-12 text-right"> | ||||
| 				<hr> | ||||
| 				<button type="submit" class="btn btn-primary font-weight-bold py-0 px-5">Submit</button> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	</form> | ||||
| 
 | ||||
| @endsection | ||||
|  | @ -426,6 +426,9 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact | |||
| 			Route::get('/', 'ImportController@mastodon')->name('settings.import.mastodon'); | ||||
| 		  }); | ||||
| 		}); | ||||
| 
 | ||||
| 		Route::get('timeline', 'SettingsController@timelineSettings')->name('settings.timeline'); | ||||
| 		Route::post('timeline', 'SettingsController@updateTimelineSettings'); | ||||
| 	}); | ||||
| 
 | ||||
| 	Route::group(['prefix' => 'site'], function () { | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Daniel Supernault
						Daniel Supernault