Update SettingsController

This commit is contained in:
Daniel Supernault 2023-07-30 03:55:51 -06:00
parent 1c13b518be
commit 0eca48f1a4
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 70 additions and 20 deletions

View file

@ -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];
}
}

View file

@ -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)