|
@@ -5,6 +5,7 @@ namespace App\Services;
|
|
use Cache;
|
|
use Cache;
|
|
use App\Profile;
|
|
use App\Profile;
|
|
use App\Status;
|
|
use App\Status;
|
|
|
|
+use App\UserSetting;
|
|
use App\Transformer\Api\AccountTransformer;
|
|
use App\Transformer\Api\AccountTransformer;
|
|
use League\Fractal;
|
|
use League\Fractal;
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
@@ -17,14 +18,7 @@ class AccountService
|
|
|
|
|
|
public static function get($id, $softFail = false)
|
|
public static function get($id, $softFail = false)
|
|
{
|
|
{
|
|
- if($id > PHP_INT_MAX || $id < 1) {
|
|
|
|
- return [];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $key = self::CACHE_KEY . $id;
|
|
|
|
- $ttl = now()->addHours(12);
|
|
|
|
-
|
|
|
|
- return Cache::remember($key, $ttl, function() use($id, $softFail) {
|
|
|
|
|
|
+ return Cache::remember(self::CACHE_KEY . $id, 43200, function() use($id, $softFail) {
|
|
$fractal = new Fractal\Manager();
|
|
$fractal = new Fractal\Manager();
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
$profile = Profile::find($id);
|
|
$profile = Profile::find($id);
|
|
@@ -44,6 +38,63 @@ class AccountService
|
|
return Cache::forget(self::CACHE_KEY . $id);
|
|
return Cache::forget(self::CACHE_KEY . $id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static function settings($id)
|
|
|
|
+ {
|
|
|
|
+ $settings = UserSetting::whereUserId($id)->first();
|
|
|
|
+ if(!$settings) {
|
|
|
|
+ return self::defaultSettings();
|
|
|
|
+ }
|
|
|
|
+ return collect($settings)
|
|
|
|
+ ->filter(function($item, $key) {
|
|
|
|
+ return in_array($key, array_keys(self::defaultSettings())) == true;
|
|
|
|
+ })
|
|
|
|
+ ->map(function($item, $key) {
|
|
|
|
+ if($key == 'compose_settings') {
|
|
|
|
+ $cs = self::defaultSettings()['compose_settings'];
|
|
|
|
+ return array_merge($cs, $item ?? []);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($key == 'other') {
|
|
|
|
+ $other = self::defaultSettings()['other'];
|
|
|
|
+ return array_merge($other, $item ?? []);
|
|
|
|
+ }
|
|
|
|
+ return $item;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static function canEmbed($id)
|
|
|
|
+ {
|
|
|
|
+ return self::settings($id)['other']['disable_embeds'] == false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static function defaultSettings()
|
|
|
|
+ {
|
|
|
|
+ return [
|
|
|
|
+ 'crawlable' => true,
|
|
|
|
+ 'public_dm' => false,
|
|
|
|
+ 'reduce_motion' => false,
|
|
|
|
+ 'high_contrast_mode' => false,
|
|
|
|
+ 'video_autoplay' => false,
|
|
|
|
+ 'show_profile_follower_count' => true,
|
|
|
|
+ 'show_profile_following_count' => true,
|
|
|
|
+ 'compose_settings' => [
|
|
|
|
+ 'default_scope' => 'public',
|
|
|
|
+ 'default_license' => 1,
|
|
|
|
+ 'media_descriptions' => false
|
|
|
|
+ ],
|
|
|
|
+ 'other' => [
|
|
|
|
+ 'advanced_atom' => false,
|
|
|
|
+ 'disable_embeds' => false,
|
|
|
|
+ 'mutual_mention_notifications' => false,
|
|
|
|
+ 'hide_collections' => false,
|
|
|
|
+ 'hide_like_counts' => false,
|
|
|
|
+ 'hide_groups' => false,
|
|
|
|
+ 'hide_stories' => false,
|
|
|
|
+ 'disable_cw' => false,
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
public static function syncPostCount($id)
|
|
public static function syncPostCount($id)
|
|
{
|
|
{
|
|
$profile = Profile::find($id);
|
|
$profile = Profile::find($id);
|