Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

refactor: standardize post platform data structure and simplify display logic in PostResource

Paulo Castellanodc75e2b3814d
diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php
index 752fffae1..3460169c0 100644
--- a/app/Http/Controllers/App/PostController.php
+++ b/app/Http/Controllers/App/PostController.php
@@ -12,6 +12,7 @@ use App\Enums\Post\Action as PostAction;
use App\Enums\Post\Status as PostStatus;
use App\Enums\SocialAccount\Platform;
use App\Http\Requests\App\Post\UpdatePostRequest;
+use App\Http\Resources\Api\PostResource;
use App\Http\Resources\App\PlatformConfigResource;
use App\Http\Resources\App\SocialAccountResource;
use App\Models\Post;
@@ -228,7 +229,7 @@ class PostController extends Controller
return Inertia::render('posts/Show', [
'workspace' => $workspace,
- 'post' => $post,
+ 'post' => (new PostResource($post))->resolve(),
]);
}
diff --git a/app/Http/Resources/Api/PostPlatformResource.php b/app/Http/Resources/Api/PostPlatformResource.php
index ca7712cb7..147179e90 100644
--- a/app/Http/Resources/Api/PostPlatformResource.php
+++ b/app/Http/Resources/Api/PostPlatformResource.php
@@ -20,6 +20,14 @@ class PostPlatformResource extends JsonResource
'content_type' => $this->content_type?->value,
'status' => $this->status?->value,
'enabled' => $this->enabled,
+ 'platform_url' => $this->platform_url,
+ 'published_at' => $this->published_at?->format('Y-m-d H:i:s'),
+ 'error_message' => $this->error_message,
+ // Display fields fall back to snapshots (platform_name/username/avatar)
+ // so deleted accounts still render correctly in the post history.
+ 'display_name' => $this->display_name,
+ 'display_username' => $this->display_username,
+ 'display_avatar' => $this->display_avatar,
'social_account' => new SocialAccountResource($this->whenLoaded('socialAccount')),
];
}
diff --git a/app/Models/Post.php b/app/Models/Post.php
index 30aeb4efc..77328c361 100644
--- a/app/Models/Post.php
+++ b/app/Models/Post.php
@@ -96,7 +96,7 @@ class Post extends Model
public function scopePublished(Builder $query): Builder
{
- return $query->where('status', PostStatus::Published);
+ return $query->whereIn('status', [PostStatus::Published, PostStatus::PartiallyPublished]);
}
public function scopeFailed(Builder $query): Builder
diff --git a/resources/js/pages/posts/Show.vue b/resources/js/pages/posts/Show.vue
index dc0e01697..f2424f135 100644
--- a/resources/js/pages/posts/Show.vue
+++ b/resources/js/pages/posts/Show.vue
@@ -33,9 +33,9 @@ interface SocialAccount {
interface PostPlatform {
id: string;
platform: string;
- platform_name: string | null;
- platform_username: string | null;
- platform_avatar: string | null;
+ display_name: string;
+ display_username: string | null;
+ display_avatar: string | null;
content_type: string | null;
status: 'pending' | 'publishing' | 'published' | 'failed';
platform_url: string | null;
@@ -52,7 +52,7 @@ interface Post {
status: string;
scheduled_at: string | null;
published_at: string | null;
- post_platforms: PostPlatform[];
+ platforms: PostPlatform[];
labels?: { id: string; name: string; color: string }[];
}
@@ -66,7 +66,7 @@ const props = defineProps<{
post: Post;
}>();
-const enabledPlatforms = computed(() => props.post.post_platforms.filter((pp) => pp.enabled));
+const enabledPlatforms = computed(() => props.post.platforms.filter((pp) => pp.enabled));
const publishedCount = computed(() => enabledPlatforms.value.filter((pp) => pp.status === 'published').length);
const failedCount = computed(() => enabledPlatforms.value.filter((pp) => pp.status === 'failed').length);
@@ -79,14 +79,11 @@ const pageTitle = computed(() => {
return snippet ? `${trans('posts.show.title')} · ${snippet}${props.post.content.length > 60 ? '…' : ''}` : trans('posts.show.title');
});
-const getDisplayName = (pp: PostPlatform): string =>
- pp.social_account?.display_name ?? pp.platform_name ?? pp.platform;
+const getDisplayName = (pp: PostPlatform): string => pp.display_name ?? pp.platform;
-const getDisplayUsername = (pp: PostPlatform): string | null =>
- pp.social_account?.username ?? pp.platform_username;
+const getDisplayUsername = (pp: PostPlatform): string | null => pp.display_username;
-const getDisplayAvatar = (pp: PostPlatform): string | null =>
- pp.social_account?.avatar_url ?? pp.platform_avatar;
+const getDisplayAvatar = (pp: PostPlatform): string | null => pp.display_avatar;
const formatDateTime = (date: string | null): string =>
date ? dayjs.utc(date).local().format('D MMM YYYY, HH:mm') : '';
diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.php
index 5dad4fdaf..e664d2a61 100644
--- a/tests/Feature/PostControllerTest.php
+++ b/tests/Feature/PostControllerTest.php
@@ -653,7 +653,7 @@ test('show page renders for non-editable posts', function () {
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->component('posts/Show', false)
- ->has('post.post_platforms', 1)
+ ->has('post.platforms', 1)
);
});