mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-26 06:53:17 +00:00
Update SettingsController
This commit is contained in:
parent
1c13b518be
commit
0eca48f1a4
2 changed files with 70 additions and 20 deletions
|
@ -17,6 +17,7 @@ use App\Report;
|
|||
use App\Profile;
|
||||
use App\StatusArchived;
|
||||
use App\User;
|
||||
use App\UserSetting;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\ProfileStatusService;
|
||||
|
@ -845,4 +846,39 @@ class ApiV1Dot1Controller extends Controller
|
|||
|
||||
return StatusService::get($status->id, false);
|
||||
}
|
||||
|
||||
public function getWebSettings(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
$uid = $request->user()->id;
|
||||
$settings = UserSetting::firstOrCreate([
|
||||
'user_id' => $uid
|
||||
]);
|
||||
if(!$settings->other) {
|
||||
return [];
|
||||
}
|
||||
return $settings->other;
|
||||
}
|
||||
|
||||
public function setWebSettings(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
$this->validate($request, [
|
||||
'field' => 'required|in:enable_reblogs,hide_reblog_banner',
|
||||
'value' => 'required'
|
||||
]);
|
||||
$field = $request->input('field');
|
||||
$value = $request->input('value');
|
||||
$settings = UserSetting::whereUserId($request->user()->id)->first();
|
||||
if(!$settings) {
|
||||
$other = [];
|
||||
} else {
|
||||
$other = $settings->other;
|
||||
}
|
||||
$other[$field] = $value;
|
||||
$settings->other = $other;
|
||||
$settings->save();
|
||||
|
||||
return [200];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,30 +230,44 @@ class SettingsController extends Controller
|
|||
|
||||
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'));
|
||||
$uid = $request->user()->id;
|
||||
$pid = $request->user()->profile_id;
|
||||
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
||||
$replies = Redis::zscore('pf:tl:replies', $pid) != false;
|
||||
$userSettings = UserSetting::firstOrCreate([
|
||||
'user_id' => $uid
|
||||
]);
|
||||
if(!$userSettings || !$userSettings->other) {
|
||||
$userSettings = [
|
||||
'enable_reblogs' => false,
|
||||
];
|
||||
} else {
|
||||
$userSettings = $userSettings->other;
|
||||
}
|
||||
return view('settings.timeline', compact('top', 'replies', 'userSettings'));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if($replies) {
|
||||
Redis::zadd('pf:tl:replies', $pid, $pid);
|
||||
} else {
|
||||
Redis::zrem('pf:tl:replies', $pid);
|
||||
}
|
||||
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
||||
$pid = $request->user()->profile_id;
|
||||
$uid = $request->user()->id;
|
||||
$this->validate($request, [
|
||||
'enable_reblogs' => 'sometimes'
|
||||
]);
|
||||
Redis::zrem('pf:tl:top', $pid);
|
||||
Redis::zrem('pf:tl:replies', $pid);
|
||||
$userSettings = UserSetting::firstOrCreate([
|
||||
'user_id' => $uid
|
||||
]);
|
||||
if($userSettings->other) {
|
||||
$other = $userSettings->other;
|
||||
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
||||
} else {
|
||||
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
||||
}
|
||||
$userSettings->other = $other;
|
||||
$userSettings->save();
|
||||
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
||||
}
|
||||
|
||||
public function mediaSettings(Request $request)
|
||||
|
|
Loading…
Reference in a new issue