mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +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\Profile;
|
||||||
use App\StatusArchived;
|
use App\StatusArchived;
|
||||||
use App\User;
|
use App\User;
|
||||||
|
use App\UserSetting;
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\StatusService;
|
use App\Services\StatusService;
|
||||||
use App\Services\ProfileStatusService;
|
use App\Services\ProfileStatusService;
|
||||||
|
@ -845,4 +846,39 @@ class ApiV1Dot1Controller extends Controller
|
||||||
|
|
||||||
return StatusService::get($status->id, false);
|
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,29 +230,43 @@ class SettingsController extends Controller
|
||||||
|
|
||||||
public function timelineSettings(Request $request)
|
public function timelineSettings(Request $request)
|
||||||
{
|
{
|
||||||
|
$uid = $request->user()->id;
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
||||||
$replies = Redis::zscore('pf:tl:replies', $pid) != false;
|
$replies = Redis::zscore('pf:tl:replies', $pid) != false;
|
||||||
return view('settings.timeline', compact('top', 'replies'));
|
$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)
|
public function updateTimelineSettings(Request $request)
|
||||||
{
|
{
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$top = $request->has('top') && $request->input('top') === 'on';
|
$uid = $request->user()->id;
|
||||||
$replies = $request->has('replies') && $request->input('replies') === 'on';
|
$this->validate($request, [
|
||||||
|
'enable_reblogs' => 'sometimes'
|
||||||
if($top) {
|
]);
|
||||||
Redis::zadd('pf:tl:top', $pid, $pid);
|
|
||||||
} else {
|
|
||||||
Redis::zrem('pf:tl:top', $pid);
|
Redis::zrem('pf:tl:top', $pid);
|
||||||
}
|
|
||||||
|
|
||||||
if($replies) {
|
|
||||||
Redis::zadd('pf:tl:replies', $pid, $pid);
|
|
||||||
} else {
|
|
||||||
Redis::zrem('pf:tl:replies', $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!');
|
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue