mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +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,30 +230,44 @@ class SettingsController extends Controller
|
||||||
|
|
||||||
public function timelineSettings(Request $request)
|
public function timelineSettings(Request $request)
|
||||||
{
|
{
|
||||||
$pid = $request->user()->profile_id;
|
$uid = $request->user()->id;
|
||||||
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
$pid = $request->user()->profile_id;
|
||||||
$replies = Redis::zscore('pf:tl:replies', $pid) != false;
|
$top = Redis::zscore('pf:tl:top', $pid) != false;
|
||||||
return view('settings.timeline', compact('top', 'replies'));
|
$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)
|
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);
|
Redis::zrem('pf:tl:top', $pid);
|
||||||
} else {
|
Redis::zrem('pf:tl:replies', $pid);
|
||||||
Redis::zrem('pf:tl:top', $pid);
|
$userSettings = UserSetting::firstOrCreate([
|
||||||
}
|
'user_id' => $uid
|
||||||
|
]);
|
||||||
if($replies) {
|
if($userSettings->other) {
|
||||||
Redis::zadd('pf:tl:replies', $pid, $pid);
|
$other = $userSettings->other;
|
||||||
} else {
|
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
||||||
Redis::zrem('pf:tl:replies', $pid);
|
} else {
|
||||||
}
|
$other['enable_reblogs'] = $request->has('enable_reblogs');
|
||||||
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
}
|
||||||
|
$userSettings->other = $other;
|
||||||
|
$userSettings->save();
|
||||||
|
return redirect(route('settings'))->with('status', 'Timeline settings successfully updated!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mediaSettings(Request $request)
|
public function mediaSettings(Request $request)
|
||||||
|
|
Loading…
Reference in a new issue