diff --git a/app/Jobs/AvatarPipeline/RemoteAvatarFetchFromUrl.php b/app/Jobs/AvatarPipeline/RemoteAvatarFetchFromUrl.php new file mode 100644 index 000000000..cee52f6ea --- /dev/null +++ b/app/Jobs/AvatarPipeline/RemoteAvatarFetchFromUrl.php @@ -0,0 +1,91 @@ +profile = $profile; + $this->url = $url; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $profile = $this->profile; + + if(boolval(config_cache('pixelfed.cloud_storage')) == false && boolval(config_cache('federation.avatars.store_local')) == false) { + return 1; + } + + if($profile->domain == null || $profile->private_key) { + return 1; + } + + $avatar = Avatar::whereProfileId($profile->id)->first(); + + if(!$avatar) { + $avatar = new Avatar; + $avatar->profile_id = $profile->id; + $avatar->is_remote = true; + $avatar->remote_url = $this->url; + $avatar->save(); + } else { + $avatar->remote_url = $this->url; + $avatar->is_remote = true; + $avatar->save(); + } + + MediaStorageService::avatar($avatar, boolval(config_cache('pixelfed.cloud_storage')) == false); + + return 1; + } +} diff --git a/app/Jobs/ProfilePipeline/HandleUpdateActivity.php b/app/Jobs/ProfilePipeline/HandleUpdateActivity.php index 2c5a4456b..3fe49b3d7 100644 --- a/app/Jobs/ProfilePipeline/HandleUpdateActivity.php +++ b/app/Jobs/ProfilePipeline/HandleUpdateActivity.php @@ -13,7 +13,7 @@ use App\Profile; use App\Util\ActivityPub\Helpers; use Cache; use Purify; -use App\Jobs\AvatarPipeline\RemoteAvatarFetch; +use App\Jobs\AvatarPipeline\RemoteAvatarFetchFromUrl; use App\Util\Lexer\Autolink; class HandleUpdateActivity implements ShouldQueue @@ -82,8 +82,8 @@ class HandleUpdateActivity implements ShouldQueue $profile->save(); } - if(isset($payload['object']['icon'])) { - RemoteAvatarFetch::dispatch($profile)->onQueue('low'); + if(isset($payload['object']['icon']) && isset($payload['object']['icon']['url'])) { + RemoteAvatarFetch::dispatch($profile, $payload['object']['icon']['url'])->onQueue('low'); } else { $profile->avatar->update(['remote_url' => null]); Cache::forget('avatar:' . $profile->id);