Unverified Commit 9d23c7e7 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(avatar): use default avatar when no avatar url has been set

- get avatar and cover urls from entity: if no image exists, retrieve the default ones.
- always
set icon and image in actor object: set the default ones if podcast hasn't set them.

fixes #111
parent e2b85a1d
Pipeline #827 passed with stage
in 5 minutes and 55 seconds
......@@ -11,4 +11,15 @@ class ActivityPub extends ActivityPubBase
*/
public $actorObject = 'App\Libraries\PodcastActor';
public $noteObject = 'App\Libraries\NoteObject';
/**
* --------------------------------------------------------------------
* Default avatar and cover images
* --------------------------------------------------------------------
*/
public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg';
public $defaultAvatarImageMimetype = 'image/jpeg';
public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg';
public $defaultCoverImageMimetype = 'image/jpeg';
}
......@@ -19,4 +19,15 @@ class ActivityPub extends BaseConfig
*/
public $actorObject = 'ActivityPub\Objects\ActorObject';
public $noteObject = 'ActivityPub\Objects\NoteObject';
/**
* --------------------------------------------------------------------
* Default avatar and cover images
* --------------------------------------------------------------------
*/
public $defaultAvatarImagePath = 'assets/images/avatar-default.jpg';
public $defaultAvatarImageMimetype = 'image/jpeg';
public $defaultCoverImagePath = 'assets/images/cover-default.jpg';
public $defaultCoverImageMimetype = 'image/jpeg';
}
......@@ -54,12 +54,14 @@ class AddActors extends Migration
'avatar_image_url' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
],
// constraint is 13 because the longest safe mimetype for images is image/svg+xml,
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#image_types
'avatar_image_mimetype' => [
'type' => 'VARCHAR',
'constraint' => 13,
'null' => true,
],
'cover_image_url' => [
'type' => 'VARCHAR',
......
......@@ -36,8 +36,8 @@ class Actor extends Entity
'summary' => '?string',
'private_key' => '?string',
'public_key' => '?string',
'avatar_image_url' => 'string',
'avatar_image_mimetype' => 'string',
'avatar_image_url' => '?string',
'avatar_image_mimetype' => '?string',
'cover_image_url' => '?string',
'cover_image_mimetype' => '?string',
'inbox_url' => 'string',
......@@ -81,4 +81,40 @@ class Actor extends Entity
return $this->followers;
}
public function getAvatarImageUrl()
{
if (empty($this->attributes['avatar_image_url'])) {
return base_url(config('ActivityPub')->defaultAvatarImagePath);
}
return $this->attributes['avatar_image_url'];
}
public function getAvatarImageMimetype()
{
if (empty($this->attributes['avatar_image_mimetype'])) {
return config('ActivityPub')->defaultAvatarImageMimetype;
}
return $this->attributes['avatar_image_mimetype'];
}
public function getCoverImageUrl()
{
if (empty($this->attributes['cover_image_url'])) {
return base_url(config('ActivityPub')->defaultCoverImagePath);
}
return $this->attributes['cover_image_url'];
}
public function getCoverImageMimetype()
{
if (empty($this->attributes['cover_image_mimetype'])) {
return config('ActivityPub')->defaultCoverImageMimetype;
}
return $this->attributes['cover_image_mimetype'];
}
}
......@@ -91,13 +91,12 @@ class ActorObject extends ObjectType
$this->outbox = $actor->outbox_url;
$this->followers = $actor->followers_url;
if ($actor->cover_image_url) {
$this->image = [
'type' => 'Image',
'mediaType' => $actor->cover_image_mimetype,
'url' => $actor->cover_image_url,
];
}
$this->image = [
'type' => 'Image',
'mediaType' => $actor->cover_image_mimetype,
'url' => $actor->cover_image_url,
];
$this->icon = [
'type' => 'Image',
'mediaType' => $actor->avatar_image_mimetype,
......
......@@ -297,12 +297,6 @@ class PodcastModel extends Model
'public_key' => $publickey,
'display_name' => $data['data']['title'],
'summary' => $data['data']['description_html'],
'avatar_image_url' => '',
'avatar_image_mimetype' => '',
'cover_image_url' => base_url(
'assets/images/castopod-cover-default.jpg',
),
'cover_image_mimetype' => 'image/jpeg',
'inbox_url' => url_to('inbox', $username),
'outbox_url' => url_to('outbox', $username),
'followers_url' => url_to('followers', $username),
......@@ -342,6 +336,7 @@ class PodcastModel extends Model
$actor->display_name = $podcast->title;
$actor->summary = $podcast->description_html;
$actor->avatar_image_url = $podcast->image->thumbnail_url;
$actor->avatar_image_mimetype = $podcast->image_mimetype;
if ($actor->hasChanged()) {
$actorModel->update($actor->id, $actor);
......
<header id="main-header" class="fixed top-0 left-0 flex-col flex-shrink-0 h-screen transform -translate-x-full sm:left-auto sm:-translate-x-0 sm:sticky w-80 sm:w-64 lg:w-80 xl:w-112 sm:flex">
<?php if ($podcast->actor->cover_image_url): ?>
<img src="<?= $podcast->actor
->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/>
<?php else: ?>
<div class="w-full h-48 bg-pine-900"></div>
<?php endif; ?>
<img src="<?= $podcast->actor
->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/>
<div class="flex items-center justify-between px-4 py-2 mb-4 lg:px-6 -mt-14 lg:-mt-16 xl:-mt-20">
<img src="<?= $podcast->image
->thumbnail_url ?>" alt="<?= $podcast->title ?>" class="h-24 rounded-full shadow-xl xl:h-36 lg:h-28 ring-4 ring-pine-50" />
......
......@@ -31,11 +31,7 @@
'ActivityPub.follow.subtitle',
) ?></h1>
<div class="flex flex-col w-full max-w-xs -mt-24 overflow-hidden bg-white shadow rounded-xl">
<?php if ($actor->cover_image_url): ?>
<img src="<?= $actor->cover_image_url ?>" alt="" class="object-cover w-full h-32 bg-pine-800" />
<?php else: ?>
<div class="w-full h-32 bg-pine-800"></div>
<?php endif; ?>
<div class="flex px-4 py-2">
<img src="<?= $actor->avatar_image_url ?>" alt="<?= $actor->display_name ?>"
class="w-16 h-16 mr-4 -mt-8 rounded-full shadow-xl ring-2 ring-white" />
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment