From 209dfbd134e1a2cc02e7c24c158d786fa4dda61d Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Sun, 23 Jan 2022 15:42:56 +0000
Subject: [PATCH] fix(activitypub): set created_by to null for reblog if no
 user + update episode oembed data

---
 app/Config/Embed.php                   |  4 ++--
 app/Config/Fediverse.php               |  8 ++++++++
 app/Controllers/EpisodeController.php  | 20 +++++++++++---------
 app/Libraries/NoteObject.php           |  7 +------
 modules/Fediverse/Config/Fediverse.php |  4 ++--
 modules/Fediverse/Models/PostModel.php |  7 ++++++-
 themes/cp_app/embed.php                | 12 ++++++------
 7 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/app/Config/Embed.php b/app/Config/Embed.php
index 0c97f86f08..4fda8a8636 100644
--- a/app/Config/Embed.php
+++ b/app/Config/Embed.php
@@ -13,7 +13,7 @@ class Embed extends BaseConfig
      * Embeddable player config
      * --------------------------------------------------------------------------
      */
-    public int $width = 600;
+    public int $width = 485;
 
-    public int $height = 144;
+    public int $height = 112;
 }
diff --git a/app/Config/Fediverse.php b/app/Config/Fediverse.php
index 56c460f07a..64494907f4 100644
--- a/app/Config/Fediverse.php
+++ b/app/Config/Fediverse.php
@@ -10,10 +10,18 @@ declare(strict_types=1);
 
 namespace Config;
 
+use App\Libraries\NoteObject;
 use Modules\Fediverse\Config\Fediverse as FediverseBaseConfig;
 
 class Fediverse extends FediverseBaseConfig
 {
+    /**
+     * --------------------------------------------------------------------
+     * ActivityPub Objects
+     * --------------------------------------------------------------------
+     */
+    public string $noteObject = NoteObject::class;
+
     public function __construct()
     {
         parent::__construct();
diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php
index 971bfb80f1..1e8a114d74 100644
--- a/app/Controllers/EpisodeController.php
+++ b/app/Controllers/EpisodeController.php
@@ -205,14 +205,16 @@ class EpisodeController extends BaseController
             'html' =>
                 '<iframe src="' .
                 $this->episode->embed_url .
-                '" width="100%" height="144" frameborder="0" scrolling="no"></iframe>',
-            'width' => 600,
-            'height' => 144,
-            'thumbnail_url' => $this->episode->cover->large_url,
+                '" width="100%" height="' . config('Embed')->height . '" frameborder="0" scrolling="no"></iframe>',
+            'width' => config('Embed')
+                ->width,
+            'height' => config('Embed')
+                ->height,
+            'thumbnail_url' => $this->episode->cover->og_url,
             'thumbnail_width' => config('Images')
-                ->podcastCoverSizes['large']['width'],
+                ->podcastCoverSizes['og']['width'],
             'thumbnail_height' => config('Images')
-                ->podcastCoverSizes['large']['height'],
+                ->podcastCoverSizes['og']['height'],
         ]);
     }
 
@@ -227,9 +229,9 @@ class EpisodeController extends BaseController
         $oembed->addChild('provider_url', $this->podcast->link);
         $oembed->addChild('author_name', $this->podcast->title);
         $oembed->addChild('author_url', $this->podcast->link);
-        $oembed->addChild('thumbnail', $this->episode->cover->large_url);
-        $oembed->addChild('thumbnail_width', (string) config('Images')->podcastCoverSizes['large']['width']);
-        $oembed->addChild('thumbnail_height', (string) config('Images')->podcastCoverSizes['large']['height']);
+        $oembed->addChild('thumbnail', $this->episode->cover->og_url);
+        $oembed->addChild('thumbnail_width', (string) config('Images')->podcastCoverSizes['og']['width']);
+        $oembed->addChild('thumbnail_height', (string) config('Images')->podcastCoverSizes['og']['height']);
         $oembed->addChild(
             'html',
             htmlentities(
diff --git a/app/Libraries/NoteObject.php b/app/Libraries/NoteObject.php
index 71720ad747..4f27a0416f 100644
--- a/app/Libraries/NoteObject.php
+++ b/app/Libraries/NoteObject.php
@@ -24,12 +24,7 @@ class NoteObject extends FediverseNoteObject
 
         if ($post->episode_id) {
             $this->content =
-                '<a href="' .
-                $post->episode->link .
-                '" target="_blank" rel="noopener noreferrer">' .
-                $post->episode->title .
-                '</a><br/>' .
-                $post->message_html;
+                '<a href="' . $post->episode->link . '">' . $post->episode->title . '</a><br/>' . $post->message_html;
         }
     }
 }
diff --git a/modules/Fediverse/Config/Fediverse.php b/modules/Fediverse/Config/Fediverse.php
index 96a12b5063..6b052df7d1 100644
--- a/modules/Fediverse/Config/Fediverse.php
+++ b/modules/Fediverse/Config/Fediverse.php
@@ -30,11 +30,11 @@ class Fediverse extends BaseConfig
      * Default avatar and cover images
      * --------------------------------------------------------------------
      */
-    public string $defaultAvatarImagePath = 'media/castopod-avatar_fediveration.jpg';
+    public string $defaultAvatarImagePath = 'media/avatar-default.jpg';
 
     public string $defaultAvatarImageMimetype = 'image/jpeg';
 
-    public string $defaultCoverImagePath = 'media/castopod-banner-pine_fediveration.jpg';
+    public string $defaultCoverImagePath = 'media/banner-default.jpg';
 
     public string $defaultCoverImageMimetype = 'image/jpeg';
 
diff --git a/modules/Fediverse/Models/PostModel.php b/modules/Fediverse/Models/PostModel.php
index dd1a9f4b99..9762b24ebc 100644
--- a/modules/Fediverse/Models/PostModel.php
+++ b/modules/Fediverse/Models/PostModel.php
@@ -469,11 +469,16 @@ class PostModel extends BaseUuidModel
     {
         $this->db->transStart();
 
+        $userId = null;
+        if (function_exists('user_id')) {
+            $userId = user_id();
+        }
+
         $reblog = new Post([
             'actor_id' => $actor->id,
             'reblog_of_id' => $post->id,
             'published_at' => Time::now(),
-            'created_by' => user_id(),
+            'created_by' => $userId,
         ]);
 
         // add reblog
diff --git a/themes/cp_app/embed.php b/themes/cp_app/embed.php
index 9adf406f9f..f18a7138e8 100644
--- a/themes/cp_app/embed.php
+++ b/themes/cp_app/embed.php
@@ -20,17 +20,17 @@
 </head>
 
 <body class="flex" style="background: <?= $themeData['background'] ?>; color: <?= $themeData['text'] ?>;">
-    <img src="<?= $episode->cover->thumbnail_url ?>" alt="<?= $episode->title ?>" class="flex-shrink w-36 h-36 aspect-square" loading="lazy" />
-    <div class="flex flex-col items-start flex-1 min-w-0 px-4 pt-4 h-36">
+    <img src="<?= $episode->cover->thumbnail_url ?>" alt="<?= $episode->title ?>" class="flex-shrink w-28 h-28 aspect-square" loading="lazy" />
+    <div class="flex flex-col items-start flex-1 min-w-0 px-4 pt-4 h-28">
         <a href="https://castopod.org/" class="absolute top-0 right-0 mt-1 mr-2 text-2xl text-pine-500 hover:opacity-75" title="<?= lang('Common.powered_by', [
             'castopod' => 'Castopod',
-        ]) ?>" target="_blank" rel="noopener noreferrer"><?= icon('podcasting/castopod') ?></a>
+        ]) ?>"><?= icon('podcasting/castopod') ?></a>
         <div class="flex gap-x-2">
             <?= episode_numbering($episode->number, $episode->season_number, 'text-xs font-semibold !no-underline border px-1 border-gray-500', true) ?>
-            <a href="<?= route_to('podcast-activity', $podcast->handle) ?>" style="color: <?= $themeData['text'] ?>;" class="text-xs truncate opacity-75 hover:opacity-100" target="_blank"><?= $podcast->title ?></a>
+            <a href="<?= route_to('podcast-activity', $podcast->handle) ?>" style="color: <?= $themeData['text'] ?>;" class="text-xs truncate opacity-75 hover:opacity-100"><?= $podcast->title ?></a>
         </div>
-        <a href="<?= $episode->link ?>" class="flex flex-col items-start text-sm" style="color: <?= $themeData['text'] ?>;" target="_blank">
-            <h1 class="text-lg font-semibold leading-tight opacity-100 line-clamp-2 hover:opacity-75"><?= $episode->title ?></h1>
+        <a href="<?= $episode->link ?>" class="flex flex-col items-start text-sm" style="color: <?= $themeData['text'] ?>;">
+            <h1 class="font-semibold leading-tight opacity-100 line-clamp-2 hover:opacity-75"><?= $episode->title ?></h1>
         </a>
         <vm-player
                 id="castopod-vm-player"
-- 
GitLab