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.

feat: proactive connection check for at-risk posts + SocialAccount name centralization (#256)

Paulo Castellanoa147c7414ba8
diff --git a/.gitignore b/.gitignore
index e61ad860e..f65483e19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,4 @@ yarn-error.log
/.vscode
/.zed
/docs/
+/.superpowers/
diff --git a/app/Actions/Post/SyncPostPlatforms.php b/app/Actions/Post/SyncPostPlatforms.php
index 20fa77806..b0709fdbf 100644
--- a/app/Actions/Post/SyncPostPlatforms.php
+++ b/app/Actions/Post/SyncPostPlatforms.php
@@ -31,7 +31,7 @@ class SyncPostPlatforms
$post->postPlatforms()->create([
'social_account_id' => $account->id,
'platform' => $account->platform->value,
- 'platform_name' => $account->display_name,
+ 'platform_name' => $account->accountDisplayName(),
'platform_username' => $account->username,
'platform_avatar' => $account->getRawOriginal('avatar_url'),
'content_type' => ContentType::defaultFor($account->platform),
diff --git a/app/Console/Commands/CheckUpcomingPostConnections.php b/app/Console/Commands/CheckUpcomingPostConnections.php
new file mode 100644
index 000000000..2a6bf4500
--- /dev/null
+++ b/app/Console/Commands/CheckUpcomingPostConnections.php
@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Console\Commands;
+
+use App\Enums\Post\Status as PostStatus;
+use App\Enums\PostPlatform\Status as PostPlatformStatus;
+use App\Jobs\VerifyUpcomingPostConnections;
+use App\Models\PostPlatform;
+use Illuminate\Console\Command;
+
+class CheckUpcomingPostConnections extends Command
+{
+ protected $signature = 'social:check-upcoming-connections';
+
+ protected $description = 'Proactively verify social connections for posts scheduled within the next hour';
+
+ public function handle(): void
+ {
+ $workspaceIds = PostPlatform::query()
+ ->where('post_platforms.status', PostPlatformStatus::Pending)
+ ->enabled()
+ // Mirrors VerifyUpcomingPostConnections::atRiskPostPlatforms() —
+ // a paused account can't be the reason to dispatch a job for its
+ // workspace, since the job itself will skip it too. whereHas()
+ // already excludes a null social_account_id (nothing to join to).
+ ->whereHas('socialAccount', fn ($query) => $query->where('is_active', true))
+ ->where(function ($query) {
+ $query->whereNull('post_platforms.connection_warning_sent_at')
+ ->orWhere('post_platforms.connection_warning_sent_at', '<', now()->subDay());
+ })
+ ->join('posts', 'posts.id', '=', 'post_platforms.post_id')
+ ->where('posts.status', PostStatus::Scheduled)
+ ->whereBetween('posts.scheduled_at', [now(), now()->addHour()])
+ ->distinct()
+ ->pluck('posts.workspace_id');
+
+ foreach ($workspaceIds as $workspaceId) {
+ VerifyUpcomingPostConnections::dispatch($workspaceId);
+ }
+
+ $this->info("Dispatched {$workspaceIds->count()} upcoming-post connection checks.");
+ }
+}
diff --git a/app/Console/Commands/RecoverStuckPosts.php b/app/Console/Commands/RecoverStuckPosts.php
index a4cee4b49..617a02ac4 100644
--- a/app/Console/Commands/RecoverStuckPosts.php
+++ b/app/Console/Commands/RecoverStuckPosts.php
@@ -24,7 +24,7 @@ class RecoverStuckPosts extends Command
->where('updated_at', '<=', now()->subHour())
->each(function (Post $post) use (&$count) {
$post->postPlatforms()
- ->where('enabled', true)
+ ->enabled()
->whereIn('status', [PlatformStatus::Publishing, PlatformStatus::Pending, PlatformStatus::Retrying])
->where('updated_at', '<=', now()->subHour())
->update([
@@ -39,7 +39,7 @@ class RecoverStuckPosts extends Command
// Delayed platform-unavailable retries keep the platform Retrying with a
// fresh updated_at — do not finalize the post while that work is still live.
$stillActive = $post->postPlatforms()
- ->where('enabled', true)
+ ->enabled()
->whereIn('status', [PlatformStatus::Publishing, PlatformStatus::Pending, PlatformStatus::Retrying])
->exists();
@@ -47,7 +47,7 @@ class RecoverStuckPosts extends Command
return;
}
- $enabledPlatforms = $post->postPlatforms()->where('enabled', true)->get();
+ $enabledPlatforms = $post->postPlatforms()->enabled()->get();
$total = $enabledPlatforms->count();
$publishedCount = $enabledPlatforms->where('status', PlatformStatus::Published)->count();
diff --git a/app/Enums/Notification/Type.php b/app/Enums/Notification/Type.php
index 04263b505..f4dc9663c 100644
--- a/app/Enums/Notification/Type.php
+++ b/app/Enums/Notification/Type.php
@@ -11,6 +11,7 @@ enum Type: string
case PostPartiallyPublished = 'post_partially_published';
case PostReady = 'post_ready';
case AccountDisconnected = 'account_disconnected';
+ case PostAtRisk = 'post_at_risk';
case InviteReceived = 'invite_received';
case MemberJoined = 'member_joined';
case MemberRemoved = 'member_removed';
diff --git a/app/Enums/SocialAccount/Platform.php b/app/Enums/SocialAccount/Platform.php
index 1849c36d8..e665ed453 100644
--- a/app/Enums/SocialAccount/Platform.php
+++ b/app/Enums/SocialAccount/Platform.php
@@ -310,6 +310,25 @@ enum Platform: string
};
}
+ /**
+ * Whether ConnectionVerifier has a real per-account token refresh flow
+ * for this platform. Facebook/InstagramFacebook use Page tokens and
+ * Mastodon's tokens don't expire (see defaultTokenTtlSeconds()); Telegram
+ * and Discord authenticate with one bot token shared across every
+ * connected account of that platform, with no per-account credential to
+ * refresh at all. For these, a rejected verify call can't be retried
+ * after a refresh — there's nothing to refresh.
+ */
+ public function hasTokenRefreshFlow(): bool
+ {
+ return match ($this) {
+ self::LinkedIn, self::LinkedInPage, self::X, self::Bluesky,
+ self::YouTube, self::TikTok, self::Pinterest,
+ self::Threads, self::Instagram => true,
+ default => false,
+ };
+ }
+
/**
* The `platform` column values of the platforms that refresh by extending
* their access token in place (Instagram and Threads — see
diff --git a/app/Exceptions/Social/BlueskyPublishException.php b/app/Exceptions/Social/BlueskyPublishException.php
index b6fc6b1a1..3dc6b9a66 100644
--- a/app/Exceptions/Social/BlueskyPublishException.php
+++ b/app/Exceptions/Social/BlueskyPublishException.php
@@ -19,7 +19,7 @@ class BlueskyPublishException extends SocialPublishException
$error = data_get($body, 'error', '');
$errorMessage = data_get($body, 'message', 'An unknown Bluesky error occurred.');
- if (in_array($error, ['ExpiredToken', 'InvalidToken'], true)) {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: $errorMessage,
platformErrorCode: $error,
@@ -74,4 +74,17 @@ class BlueskyPublishException extends SocialPublishException
{
return 'bluesky';
}
+
+ /**
+ * Whether this response confirms the account's own session token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead Bluesky session looks like.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ $error = data_get($response->json(), 'error', '');
+
+ return in_array($error, ['ExpiredToken', 'InvalidToken'], true);
+ }
}
diff --git a/app/Exceptions/Social/DiscordPublishException.php b/app/Exceptions/Social/DiscordPublishException.php
index 3aaa40cf5..4de3bcb84 100644
--- a/app/Exceptions/Social/DiscordPublishException.php
+++ b/app/Exceptions/Social/DiscordPublishException.php
@@ -86,4 +86,26 @@ class DiscordPublishException extends SocialPublishException
{
return 'discord';
}
+
+ /**
+ * Whether this response confirms the bot lost access to THIS specific
+ * guild (kicked, missing access, or the guild is gone) — used by
+ * ConnectionVerifier against getGuild's response.
+ *
+ * Deliberately NOT the same check fromApiResponse() uses above, and not
+ * called from it: fromApiResponse() classifies channel-message responses
+ * (channel-send scope, where a 403 there stays a Permission-category
+ * publish failure rather than disconnecting the account — the bot could
+ * still be a guild member with access to other channels), while this
+ * classifies getGuild responses (guild-membership scope, where the same
+ * 403/404 unambiguously means the bot is out of this guild entirely).
+ * 401 is excluded from both: Discord auth is one bot token shared across
+ * every connected account, so a 401 means that shared token is
+ * misconfigured (an operator problem), never evidence that this specific
+ * guild connection is dead.
+ */
+ public static function isConfirmedDeadGuild(Response $response): bool
+ {
+ return in_array($response->status(), [403, 404], true);
+ }
}
diff --git a/app/Exceptions/Social/LinkedInPublishException.php b/app/Exceptions/Social/LinkedInPublishException.php
index aad4a0887..2b881242f 100644
--- a/app/Exceptions/Social/LinkedInPublishException.php
+++ b/app/Exceptions/Social/LinkedInPublishException.php
@@ -18,7 +18,7 @@ class LinkedInPublishException extends SocialPublishException
$errorMessage = data_get($body, 'message', $rawResponse);
- if ($statusCode === 401) {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: $errorMessage ?? 'Access token has expired or been revoked',
platformErrorCode: (string) $statusCode,
@@ -61,4 +61,15 @@ class LinkedInPublishException extends SocialPublishException
{
return 'linkedin';
}
+
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead LinkedIn/LinkedIn Page token looks like.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ return $response->status() === 401;
+ }
}
diff --git a/app/Exceptions/Social/MastodonPublishException.php b/app/Exceptions/Social/MastodonPublishException.php
index 782f8ab49..b06710b10 100644
--- a/app/Exceptions/Social/MastodonPublishException.php
+++ b/app/Exceptions/Social/MastodonPublishException.php
@@ -18,7 +18,7 @@ class MastodonPublishException extends SocialPublishException
$errorMessage = data_get($body, 'error', 'An unknown Mastodon error occurred.');
- if ($status === 401) {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: $errorMessage,
platformErrorCode: (string) $status,
@@ -91,4 +91,23 @@ class MastodonPublishException extends SocialPublishException
{
return 'mastodon';
}
+
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead Mastodon token looks like.
+ *
+ * 403 is deliberately NOT included here: on the write-scoped /statuses
+ * endpoint a 403 can mean the app only has read scope, which doesn't
+ * prove the token itself is dead (see 'mastodon publisher throws
+ * permission exception on forbidden'). ConnectionVerifier adds its own
+ * 403 check on top of this one, because verify_credentials is the
+ * lowest-privilege read endpoint — a 403 there means the token has no
+ * access at all, a stronger and different signal than a write-scope 403.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ return $response->status() === 401;
+ }
}
diff --git a/app/Exceptions/Social/PinterestPublishException.php b/app/Exceptions/Social/PinterestPublishException.php
index 58ad92c23..ca13f92ab 100644
--- a/app/Exceptions/Social/PinterestPublishException.php
+++ b/app/Exceptions/Social/PinterestPublishException.php
@@ -16,7 +16,7 @@ class PinterestPublishException extends SocialPublishException
$body = $response->json();
$rawResponse = $response->body();
- if ($status === 401) {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: data_get($body, 'message', 'Access token has expired or been revoked'),
platformErrorCode: (string) $status,
@@ -90,4 +90,15 @@ class PinterestPublishException extends SocialPublishException
{
return 'pinterest';
}
+
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead Pinterest token looks like.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ return $response->status() === 401;
+ }
}
diff --git a/app/Exceptions/Social/TelegramPublishException.php b/app/Exceptions/Social/TelegramPublishException.php
index 56675239a..1cf837b7c 100644
--- a/app/Exceptions/Social/TelegramPublishException.php
+++ b/app/Exceptions/Social/TelegramPublishException.php
@@ -65,4 +65,25 @@ class TelegramPublishException extends SocialPublishException
{
return 'telegram';
}
+
+ /**
+ * Whether this response confirms the bot lost access to THIS specific
+ * chat (kicked, blocked, or the chat was deleted) — used by
+ * ConnectionVerifier against getChat's response.
+ *
+ * Deliberately NOT the same check fromApiResponse() uses above, and not
+ * called from it: fromApiResponse() classifies sendMessage/sendPhoto
+ * responses (message-send scope, where a 403 there stays a
+ * Permission-category publish failure rather than disconnecting the
+ * account — the bot could still reach other chats fine), while this
+ * classifies getChat responses (chat-read scope, where the same 400/403
+ * unambiguously means this one chat is gone). 401 is excluded from both:
+ * Telegram auth is one bot token shared across every connected account,
+ * so a 401 means that shared token is misconfigured (an operator
+ * problem), never evidence that this specific chat connection is dead.
+ */
+ public static function isConfirmedDeadChat(Response $response): bool
+ {
+ return in_array($response->status(), [400, 403], true);
+ }
}
diff --git a/app/Exceptions/Social/TikTokPublishException.php b/app/Exceptions/Social/TikTokPublishException.php
index 5d8cf1c64..fa87e12eb 100644
--- a/app/Exceptions/Social/TikTokPublishException.php
+++ b/app/Exceptions/Social/TikTokPublishException.php
@@ -18,7 +18,7 @@ class TikTokPublishException extends SocialPublishException
$errorCode = data_get($body, 'error.code');
$errorMessage = data_get($body, 'error.message', 'An unknown TikTok error occurred.');
- if ($errorCode === 'access_token_invalid') {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: $errorMessage,
platformErrorCode: $errorCode,
@@ -79,4 +79,29 @@ class TikTokPublishException extends SocialPublishException
{
return 'tiktok';
}
+
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead TikTok token looks like. 10001/10002 are the numeric forms of
+ * the same access_token_invalid/expired conditions TikTok also reports.
+ *
+ * A bare HTTP 401 is deliberately NOT treated as confirmed-dead here:
+ * TikTok also returns 401 for scope_not_authorized/scope_permission_missed
+ * (missing video.publish grant — see
+ * https://developers.tiktok.com/doc/content-posting-api-reference-direct-post),
+ * which is a scope gap, not a dead token, and must stay a Permission-category
+ * publish failure (see the match arms above) rather than disconnecting the
+ * account. ConnectionVerifier adds its own bare-401 check on top of this
+ * one, because /v2/user/info/ only needs the always-granted user.info.basic
+ * scope — a 401 there can't be a scope gap, so it's an unambiguous signal
+ * the token itself is dead.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ $errorCode = data_get($response->json(), 'error.code');
+
+ return in_array($errorCode, ['access_token_invalid', 'access_token_expired', 10001, 10002]);
+ }
}
diff --git a/app/Exceptions/Social/XPublishException.php b/app/Exceptions/Social/XPublishException.php
index d08a3f6aa..aed3abd94 100644
--- a/app/Exceptions/Social/XPublishException.php
+++ b/app/Exceptions/Social/XPublishException.php
@@ -22,7 +22,7 @@ class XPublishException extends SocialPublishException
$typeSuffix = $type !== '' ? basename((string) $type) : '';
- if ($statusCode === 401 || str_contains((string) $type, 'unsupported-authentication')) {
+ if (self::isConfirmedDeadToken($response)) {
throw new TokenExpiredException(
message: $detail ?: 'Access token has expired or been revoked',
platformErrorCode: $typeSuffix ?: (string) $statusCode,
@@ -113,4 +113,17 @@ class XPublishException extends SocialPublishException
{
return 'x';
}
+
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead X token looks like.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ $type = (string) data_get($response->json(), 'type', '');
+
+ return $response->status() === 401 || str_contains($type, 'unsupported-authentication');
+ }
}
diff --git a/app/Exceptions/Social/YouTubePublishException.php b/app/Exceptions/Social/YouTubePublishException.php
index 45acd79f0..8fec88a34 100644
--- a/app/Exceptions/Social/YouTubePublishException.php
+++ b/app/Exceptions/Social/YouTubePublishException.php
@@ -17,10 +17,18 @@ class YouTubePublishException extends SocialPublishException
$rawResponse = $response->body();
$reason = data_get($body, 'error.errors.0.reason');
+ $fallbackMessage = data_get($body, 'error.message', 'An unknown YouTube error occurred.');
+
+ if (self::isConfirmedDeadToken($response)) {
+ throw new TokenExpiredException(
+ message: $fallbackMessage,
+ platformErrorCode: $reason,
+ );
+ }
[$message, $category] = self::mapReasonToMessageAndCategory(
reason: $reason,
- fallbackMessage: data_get($body, 'error.message', 'An unknown YouTube error occurred.'),
+ fallbackMessage: $fallbackMessage,
);
return new static(
@@ -62,6 +70,17 @@ class YouTubePublishException extends SocialPublishException
return 'youtube';
}
+ /**
+ * Whether this response confirms the account's own access_token is dead
+ * (not merely a transient or content-specific failure). Shared with
+ * ConnectionVerifier so both the publish and verify paths agree on what
+ * a dead YouTube token looks like.
+ */
+ public static function isConfirmedDeadToken(Response $response): bool
+ {
+ return $response->status() === 401;
+ }
+
/**
* @return array{string, ErrorCategory}
*/
diff --git a/app/Http/Controllers/App/AnalyticsController.php b/app/Http/Controllers/App/AnalyticsController.php
index 919486bf8..cac42f7c6 100644
--- a/app/Http/Controllers/App/AnalyticsController.php
+++ b/app/Http/Controllers/App/AnalyticsController.php
@@ -51,8 +51,8 @@ class AnalyticsController extends Controller
->map(fn (SocialAccount $account) => [
'id' => $account->id,
'platform' => $account->platform->value,
- 'display_name' => $account->display_name,
'username' => $account->username,
+ 'display_label' => $account->display_label,
'avatar_url' => $account->avatar_url,
]);
diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php
index c1ebc395b..61981c895 100644
--- a/app/Http/Controllers/App/PostController.php
+++ b/app/Http/Controllers/App/PostController.php
@@ -46,7 +46,7 @@ class PostController extends Controller
$this->authorize('view', $workspace);
$query = $workspace->posts()
- ->with(['postPlatforms' => fn ($query) => $query->where('enabled', true)->with('socialAccount'), 'user', 'labels']);
+ ->with(['postPlatforms' => fn ($query) => $query->enabled()->with('socialAccount'), 'user', 'labels']);
if ($status) {
$query = match ($status) {
@@ -123,7 +123,7 @@ class PostController extends Controller
};
$posts = $workspace->posts()
- ->with(['postPlatforms' => fn ($query) => $query->where('enabled', true)->with('socialAccount')])
+ ->with(['postPlatforms' => fn ($query) => $query->enabled()->with('socialAccount')])
->whereBetween('scheduled_at', [$rangeStart->copy()->utc(), $rangeEnd->copy()->utc()])
->orderBy('scheduled_at')
->get()
diff --git a/app/Http/Resources/App/SocialAccountResource.php b/app/Http/Resources/App/SocialAccountResource.php
index e4bef4e52..ee476b448 100644
--- a/app/Http/Resources/App/SocialAccountResource.php
+++ b/app/Http/Resources/App/SocialAccountResource.php
@@ -21,6 +21,8 @@ class SocialAccountResource extends JsonResource
'platform_user_id' => $this->platform_user_id,
'username' => $this->username,
'display_name' => $this->display_name,
+ 'display_label' => $this->display_label,
+ 'handle_label' => $this->handle_label,
'avatar_url' => $this->avatar_url,
'profile_url' => $this->profile_url,
'status' => $this->status,
diff --git a/app/Jobs/PublishPost.php b/app/Jobs/PublishPost.php
index 792a53681..d2ad9a186 100644
--- a/app/Jobs/PublishPost.php
+++ b/app/Jobs/PublishPost.php
@@ -21,7 +21,7 @@ class PublishPost implements ShouldQueue
{
$this->post->markAsPublishing();
- foreach ($this->post->postPlatforms()->where('enabled', true)->get() as $postPlatform) {
+ foreach ($this->post->postPlatforms()->enabled()->get() as $postPlatform) {
PublishToSocialPlatform::dispatch($postPlatform);
}
}
diff --git a/app/Jobs/PublishToSocialPlatform.php b/app/Jobs/PublishToSocialPlatform.php
index a39c6b3b6..27a3a90e3 100644
--- a/app/Jobs/PublishToSocialPlatform.php
+++ b/app/Jobs/PublishToSocialPlatform.php
@@ -331,7 +331,7 @@ class PublishToSocialPlatform implements ShouldBeUnique, ShouldQueue
$publishedPlatforms = $post->postPlatforms()
->with('socialAccount')
- ->where('enabled', true)
+ ->enabled()
->get()
->filter(fn ($pp) => $pp->status === PostPlatformStatus::Published)
->map(fn ($pp) => $pp->platform->label().' (@'.data_get($pp, 'socialAccount.username', '').')')
@@ -384,7 +384,7 @@ class PublishToSocialPlatform implements ShouldBeUnique, ShouldQueue
$failedPlatforms = $post->postPlatforms()
->with('socialAccount')
- ->where('enabled', true)
+ ->enabled()
->get()
->filter(fn ($pp) => $pp->status === PostPlatformStatus::Failed)
->map(fn ($pp) => $pp->platform->label().' (@'.data_get($pp, 'socialAccount.username', '').')')
diff --git a/app/Jobs/SendNotification.php b/app/Jobs/SendNotification.php
index 4065393b8..1709cee5c 100644
--- a/app/Jobs/SendNotification.php
+++ b/app/Jobs/SendNotification.php
@@ -14,6 +14,7 @@ use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
+use Throwable;
class SendNotification implements ShouldQueue
{
@@ -60,7 +61,7 @@ class SendNotification implements ShouldQueue
}
}
- public function failed(\Throwable $exception): void
+ public function failed(Throwable $exception): void
{
Log::error('SendNotification job failed', [
'user_id' => $this->user->id,
diff --git a/app/Jobs/VerifyUpcomingPostConnections.php b/app/Jobs/VerifyUpcomingPostConnections.php
new file mode 100644
index 000000000..b2186f7b3
--- /dev/null
+++ b/app/Jobs/VerifyUpcomingPostConnections.php
@@ -0,0 +1,365 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Jobs;
+
+use App\Enums\Notification\Channel;
+use App\Enums\Notification\Type;
+use App\Enums\PostPlatform\Status as PostPlatformStatus;
+use App\Enums\SocialAccount\Status as SocialAccountStatus;
+use App\Exceptions\PlatformUnavailableException;
+use App\Exceptions\TokenExpiredException;
+use App\Mail\PostAtRisk;
+use App\Models\PostPlatform;
+use App\Models\SocialAccount;
+use App\Models\User;
+use App\Models\Workspace;
+use App\Services\Social\ConnectionVerifier;
+use Exception;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Queue\Queueable;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+
+class VerifyUpcomingPostConnections implements ShouldBeUnique, ShouldQueue
+{
+ use Queueable;
+
+ public int $tries = 1;
+
+ public int $timeout = 120;
+
+ // Covers the timeout plus queue-wait headroom, up to the full 15-minute
+ // schedule cadence — a stuck/slow run can't leave a stale lock blocking
+ // the next legitimate dispatch for this workspace.
+ public int $uniqueFor = 900;
+
+ // How long to wait before re-notifying about an account that's already
+ // known broken, even if new posts keep entering the risk window in the
+ // meantime — otherwise a busy schedule with a dead token sends a fresh
+ // email every 15 minutes for as long as the account stays broken.
+ private const RENOTIFY_COOLDOWN_MINUTES = 60;
+
+ // Grace period after an account transitions to broken during which we
+ // skip our own notification, on the assumption another process (the
+ // daily sweep, RefreshExpiringTokens) just sent AccountDisconnected for
+ // the same event — avoids two different emails landing at once.
+ private const RECENTLY_DISCONNECTED_GRACE_MINUTES = 5;
+
+ // How long a successful verify() is trusted (via SocialAccount::last_verified_at)
+ // before re-checking the same account again. Combined with VERIFY_LEAD_MINUTES
+ // below, this caps a healthy account at ~1 real API call per at-risk post
+ // instead of one every 15-minute tick for the full 1-hour risk window —
+ // platform rate-limit budget is finite and shared across the whole app.
+ private const VERIFIED_WITHIN_MINUTES = 40;
+
+ // Don't spend an API call verifying an account until its nearest at-risk
+ // post is this close to publishing. A token that's already dead stays
+ // dead, so checking earlier buys no extra safety — only less API budget
+ // spent per post, while still leaving enough lead time to reconnect.
+ private const VERIFY_LEAD_MINUTES = 30;
+
+ public function __construct(public string $workspaceId) {}
+
+ public function uniqueId(): string
+ {
+ return $this->workspaceId;
+ }
+
+ public function handle(ConnectionVerifier $verifier): void
+ {
+ $workspace = Workspace::find($this->workspaceId);
+
+ if (! $workspace) {
+ return;
+ }
+
+ $postPlatforms = $this->atRiskPostPlatforms();
+
+ if ($postPlatforms->isEmpty()) {
+ return;
+ }
+
+ $atRisk = new Collection;
+
+ foreach ($postPlatforms->groupBy('social_account_id') as $group) {
+ $account = $group->first()->socialAccount;
+
+ if (! $account) {
+ // The account was hard-deleted between the main query and its
+ // eager-loaded relation resolving (two separate queries) —
+ // nothing left to verify or warn about for this group.
+ continue;
+ }
+
+ $group = $group->filter(fn (PostPlatform $pp) => $pp->post !== null);
+
+ if ($group->isEmpty()) {
+ // Same race as above, but for the post: every row in this
+ // batch was hard-deleted between the main query and its
+ // eager-loaded relation resolving.
+ continue;
+ }
+
+ // atRiskPostPlatforms()'s is_active guard only runs at query
+ // time; this job can take real wall-clock time working through
+ // a workspace, so re-check fresh (paused/deleted since then
+ // shouldn't burn an API call or warn about it). Keep workspace
+ // eager-loaded — SocialAccountObserver reads it when
+ // markAsTokenExpired() below updates the account (#255).
+ $account = SocialAccount::active()->with('workspace')->find($account->id);
+
+ if (! $account) {
+ continue;
+ }
+
+ if (in_array($account->status, [SocialAccountStatus::TokenExpired, SocialAccountStatus::Disconnected], true)) {
+ if ($this->recentlyWarnedAbout($account) || $this->recentlyDisconnected($account)) {
+ continue;
+ }
+
+ // Already known broken from an earlier run — don't re-verify,
+ // just warn about the posts that entered the window since then.
+ $atRisk->push(['account' => $account, 'postPlatforms' => $group]);
+
+ continue;
+ }
+
+ if ($account->last_verified_at?->isAfter(now()->subMinutes(self::VERIFIED_WITHIN_MINUTES))) {
+ // Confirmed healthy recently enough — trust it instead of
+ // hitting the platform API again on every 15-minute tick.
+ continue;
+ }
+
+ $nearestScheduledAt = $group->min(fn (PostPlatform $pp) => $pp->post->scheduled_at);
+
+ if ($nearestScheduledAt->isAfter(now()->addMinutes(self::VERIFY_LEAD_MINUTES))) {
+ // Not close enough to publishing yet — defer the actual API
+ // call to a later run instead of spending budget checking
+ // every 15-minute tick for the full 1-hour risk window.
+ continue;
+ }
+
+ try {
+ $verifier->verify($account);
+ $account->update(['last_verified_at' => now()]);
+ } catch (PlatformUnavailableException $e) {
+ Log::warning('Upcoming-post connection check skipped: platform unavailable', [
+ 'account_id' => $account->id,
+ 'platform' => $account->platform->value,
+ 'error' => $e->getMessage(),
+ ]);
+
+ continue;
+ } catch (TokenExpiredException $e) {
+ try {
+ // Re-check right before mutating: if the account is no longer
+ // Connected here, a concurrent process (e.g. RefreshExpiringTokens)
+ // beat us to discovering and announcing this same break via its
+ // own AccountDisconnected email. Only skip in that case — not
+ // when disconnected_at is fresh purely because our own update
+ // below is about to set it for the first time.
+ if ($account->refresh()->status !== SocialAccountStatus::Connected && $this->recentlyDisconnected($account)) {
+ continue;
+ }
+
+ $account->markAsTokenExpired($e->getMessage(), notify: false);
+ $account->refresh();
+ } catch (Exception $lockOrDbError) {
+ // Covers the account being deleted mid-run (refresh()
+ // throws ModelNotFoundException) as well as infrastructure
+ // failures inside markAsTokenExpired() itself (its
+ // Cache::lock() or ->update() call). An exception thrown
+ // from inside a catch block isn't routed to a sibling
+ // catch, so this must be handled here to avoid aborting
+ // the run for every other account in this workspace.
+ Log::error('Failed to mark account token_expired for upcoming-post check', [
+ 'account_id' => $account->id,
+ 'platform' => $account->platform->value,
+ 'error' => $lockOrDbError->getMessage(),
+ ]);
+
+ continue;
+ }
+
+ // markAsTokenExpired() no-ops if it couldn't acquire the
+ // account's status lock (another process — e.g. a concurrent
+ // publish attempt or the daily check — holds it). Only warn
+ // once the status change is confirmed; a lost race here just
+ // means this account is picked up again on the next run.
+ if ($account->status !== SocialAccountStatus::TokenExpired) {
+ Log::warning('Upcoming-post connection check: could not mark account token_expired (status lock contended), deferring to next run', [
+ 'account_id' => $account->id,
+ 'platform' => $account->platform->value,
+ ]);
+
+ continue;
+ }
+
+ $atRisk->push(['account' => $account, 'postPlatforms' => $group]);
+ } catch (Exception $e) {
+ Log::error('Failed to verify social account connection for upcoming-post check', [
+ 'account_id' => $account->id,
+ 'platform' => $account->platform->value,
+ 'error' => $e->getMessage(),
+ ]);
+
+ // Unknown error — don't mark as broken, retry next run.
+ continue;
+ }
+ }
+
+ if ($atRisk->isEmpty()) {
+ return;
+ }
+
+ $owner = $workspace->owner;
+
+ if (! $owner) {
+ // No owner to notify — leave these rows unwarned so a future run
+ // (once the workspace has an owner) can pick them back up.
+ return;
+ }
+
+ // Conditioned on the same "unwarned" window atRiskPostPlatforms() selected
+ // on, so a concurrent run that already claimed some or all of these
+ // exact rows (the ShouldBeUnique lock's TTL matches the schedule
+ // cadence, so two instances can briefly overlap if a run takes
+ // unusually long) never gets re-claimed here. lockForUpdate() closes
+ // the gap between reading which rows are still claimable and
+ // stamping them — without it, two overlapping runs could both read
+ // "unclaimed" for the same row before either writes.
+ $warnedIds = $atRisk->flatMap(fn (array $group) => $group['postPlatforms']->pluck('id'));
+ $claimedIds = DB::transaction(function () use ($warnedIds) {
+ $claimableIds = PostPlatform::whereIn('id', $warnedIds)
+ ->where(function ($query) {
+ $query->whereNull('connection_warning_sent_at')
+ ->orWhere('connection_warning_sent_at', '<', now()->subDay());
+ })
+ // Two overlapping runs can both claim rows here (see comment
+ // above the transaction) — locking in a consistent order
+ // (primary key) prevents them from deadlocking by acquiring
+ // the same two rows' locks in opposite order.
+ ->orderBy('id')
+ ->lockForUpdate()
+ ->pluck('id');
+
+ if ($claimableIds->isEmpty()) {
+ return $claimableIds;
+ }
+
+ PostPlatform::whereIn('id', $claimableIds)->update(['connection_warning_sent_at' => now()]);
+
+ return $claimableIds;
+ }, attempts: 3);
+
+ if ($claimedIds->isEmpty()) {
+ return;
+ }
+
+ // (Pre-existing trade-off, not introduced by this transaction: a
+ // crash between the DB transaction above and notifyOwner() below
+ // loses the warning for 24h, until atRiskPostPlatforms()'s re-check window.)
+
+ // A concurrent run may have already claimed some (not all) of these
+ // rows between when $atRisk was built and the claim above — narrow
+ // the notification down to what THIS run actually claimed, so the
+ // email never lists an account/post pair another run is already
+ // notifying about. $claimedIds is a non-empty subset of $warnedIds,
+ // which is exactly the union of every group's post_platform ids, so
+ // at least one group is guaranteed to survive this filter.
+ $atRisk = $atRisk
+ ->map(function (array $group) use ($claimedIds) {
+ $group['postPlatforms'] = $group['postPlatforms']->filter(
+ fn (PostPlatform $pp) => $claimedIds->containsStrict($pp->id)
+ );
+
+ return $group;
+ })
+ ->filter(fn (array $group) => $group['postPlatforms']->isNotEmpty());
+
+ $this->notifyOwner($owner, $workspace, $atRisk);
+ }
+
+ /**
+ * Whether we've already sent a PostAtRisk notification covering this
+ * account within the cooldown window — checked against any of its
+ * post_platforms, not just the ones in the current batch.
+ */
+ private function recentlyWarnedAbout(SocialAccount $account): bool
+ {
+ return PostPlatform::query()
+ ->where('social_account_id', $account->id)
+ ->where('connection_warning_sent_at', '>=', now()->subMinutes(self::RENOTIFY_COOLDOWN_MINUTES))
+ ->exists();
+ }
+
+ /**
+ * Whether the account broke recently enough that another process (the
+ * daily sweep, a proactive token refresh) likely just sent its own
+ * AccountDisconnected email for the same event.
+ */
+ private function recentlyDisconnected(SocialAccount $account): bool
+ {
+ return $account->disconnected_at?->isAfter(now()->subMinutes(self::RECENTLY_DISCONNECTED_GRACE_MINUTES)) ?? false;
+ }
+
+ /**
+ * @return Collection<int, PostPlatform>
+ */
+ private function atRiskPostPlatforms(): Collection
+ {
+ return PostPlatform::query()
+ ->where('status', PostPlatformStatus::Pending)
+ ->enabled() // PublishPost only iterates enabled platforms — an at-risk warning for a disabled one would be a false positive.
+ // A paused account already fails at publish time with
+ // posts.errors.account_inactive before any platform API call
+ // (PublishToSocialPlatform::handle()) — verifying it here would
+ // waste a real API call and, if the token also happens to be
+ // dead, warn the owner to "reconnect" an account they paused on
+ // purpose. whereHas() already excludes a null social_account_id
+ // (nothing to join to).
+ ->whereHas('socialAccount', fn ($query) => $query->where('is_active', true))
+ ->where(function ($query) {
+ $query->whereNull('connection_warning_sent_at')
+ ->orWhere('connection_warning_sent_at', '<', now()->subDay());
+ })
+ ->whereHas('post', function ($query) {
+ $query->where('workspace_id', $this->workspaceId)
+ ->scheduled()
+ ->whereBetween('scheduled_at', [now(), now()->addHour()]);
+ })
+ // socialAccount.workspace is eager-loaded even though this job
+ // never reads it directly — SocialAccountObserver::notifyOnboarding()
+ // (fired by the ->update() calls below via markAsTokenExpired())
+ // accesses $account->workspace, and lazy loading is disabled
+ // app-wide. Dropping this eager load throws LazyLoadingViolationException
+ // the moment a second account in the same run gets updated (see #255).
+ ->with(['socialAccount.workspace', 'post'])
+ ->get();
+ }
+
+ /**
+ * @param Collection<int, array{account: SocialAccount, postPlatforms: Collection<int, PostPlatform>}> $atRisk
+ */
+ private function notifyOwner(User $owner, Workspace $workspace, Collection $atRisk): void
+ {
+ $postPlatforms = $atRisk->flatMap(fn (array $group) => $group['postPlatforms']);
+ $postCount = $postPlatforms->pluck('post_id')->unique()->count();
+ $postPlatformIds = $postPlatforms->pluck('id')->all();
+
+ SendNotification::dispatch(
+ user: $owner,
+ workspaceId: $workspace->id,
+ type: Type::PostAtRisk,
+ channel: Channel::Both,
+ title: trans_choice('notifications.post_at_risk.title', $postCount, ['count' => $postCount]),
+ body: $atRisk->map(fn (array $group) => $group['account']->platform->label().' ('.$group['account']->handle().')')->implode(', '),
+ data: ['workspace_id' => $workspace->id],
+ mailable: new PostAtRisk($workspace, $postPlatformIds, $postCount),
+ );
+ }
+}
diff --git a/app/Jobs/VerifyWorkspaceConnections.php b/app/Jobs/VerifyWorkspaceConnections.php
index 6d01c9571..128965d95 100644
--- a/app/Jobs/VerifyWorkspaceConnections.php
+++ b/app/Jobs/VerifyWorkspaceConnections.php
@@ -120,7 +120,7 @@ class VerifyWorkspaceConnections implements ShouldQueue
}
$accountNames = $disconnectedAccounts
- ->map(fn ($account) => $account->platform->label().' (@'.($account->username ?? $account->display_name).')')
+ ->map(fn ($account) => $account->platform->label().' ('.$account->handle().')')
->implode(', ');
SendNotification::dispatch(
diff --git a/app/Mail/AccountDisconnected.php b/app/Mail/AccountDisconnected.php
index 3c063521d..e6345ac7c 100644
--- a/app/Mail/AccountDisconnected.php
+++ b/app/Mail/AccountDisconnected.php
@@ -33,7 +33,7 @@ class AccountDisconnected extends Mailable implements ShouldQueue
public function content(): Content
{
$platformName = $this->account->platform->label();
- $accountName = $this->account->display_name ?? $this->account->username;
+ $accountName = $this->account->accountDisplayName();
$workspaceName = $this->account->workspace->name;
return new Content(
diff --git a/app/Mail/PostAtRisk.php b/app/Mail/PostAtRisk.php
new file mode 100644
index 000000000..174790204
--- /dev/null
+++ b/app/Mail/PostAtRisk.php
@@ -0,0 +1,121 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Mail;
+
+use App\Models\PostPlatform;
+use App\Models\Workspace;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Collection;
+
+class PostAtRisk extends Mailable implements ShouldQueue
+{
+ use Queueable, SerializesModels;
+
+ /**
+ * Rehydrated, grouped-by-account rows — computed once (lazily, at send
+ * time, never on the queue payload).
+ */
+ private ?Collection $atRiskGroups = null;
+
+ /**
+ * Only the workspace (a real Eloquent model, reduced to a lightweight
+ * identifier by SerializesModels), the post_platform IDs, and the count
+ * observed at dispatch time are carried on the queue payload. The rows
+ * themselves are rehydrated in atRiskGroups() so the queued job's
+ * serialized size stays small and the account/post details reflect
+ * state as of send time, not as of dispatch time.
+ *
+ * $count drives the subject and preview text specifically — kept as the
+ * dispatch-time value (rather than re-derived from the rehydrated rows)
+ * so it always matches the in-app notification's title, which is built
+ * from this same count in VerifyUpcomingPostConnections::notifyOwner().
+ * If a row disappears between dispatch and send, the subject may then
+ * differ from the number of rows actually listed in the body — an
+ * acceptable rare edge case, in exchange for the subject never
+ * disagreeing with the in-app notification.
+ *
+ * @param array<int, string> $postPlatformIds
+ */
+ public function __construct(
+ public Workspace $workspace,
+ public array $postPlatformIds,
+ public int $count
+ ) {}
+
+ public function envelope(): Envelope
+ {
+ return new Envelope(
+ subject: $this->subjectFor($this->count),
+ );
+ }
+
+ public function content(): Content
+ {
+ return new Content(
+ view: 'mail.post-at-risk',
+ with: [
+ 'title' => 'Posts May Fail to Publish',
+ 'previewText' => $this->subjectFor($this->count),
+ 'intro' => "The following social accounts in your {$this->workspace->name} workspace need to be reconnected before these scheduled posts can publish:",
+ 'reconnectCta' => 'Please reconnect these accounts now to avoid missing your scheduled posts.',
+ 'buttonText' => 'Reconnect Accounts',
+ 'workspace' => $this->workspace,
+ 'atRiskGroups' => $this->atRiskGroups(),
+ 'url' => route('app.accounts'),
+ ],
+ );
+ }
+
+ /**
+ * @return Collection<int, array{account: mixed, postPlatforms: Collection<int, PostPlatform>, postsLabel: string}>
+ */
+ private function atRiskGroups(): Collection
+ {
+ if ($this->atRiskGroups !== null) {
+ return $this->atRiskGroups;
+ }
+
+ $postPlatforms = PostPlatform::query()
+ ->with(['socialAccount', 'post'])
+ ->whereIn('id', $this->postPlatformIds)
+ ->get();
+
+ return $this->atRiskGroups = $postPlatforms->groupBy('social_account_id')
+ // The account can be null if it was hard-deleted between dispatch
+ // and send — nothing meaningful to render for it (no platform, no
+ // handle), so it's dropped rather than crashing the render.
+ ->filter(fn (Collection $group) => $group->first()->socialAccount !== null)
+ ->map(function (Collection $group) {
+ $postCount = $group->count();
+ $times = $group->sortBy(fn ($pp) => $pp->post->scheduled_at)
+ ->map(fn ($pp) => $pp->post->scheduled_at->format('H:i'))
+ ->implode(', ');
+ $noun = $postCount === 1 ? 'post' : 'posts';
+
+ return [
+ 'account' => $group->first()->socialAccount,
+ 'postPlatforms' => $group,
+ 'postsLabel' => "{$postCount} {$noun} scheduled: {$times} UTC",
+ ];
+ })->values();
+ }
+
+ private function subjectFor(int $count): string
+ {
+ $noun = $count === 1 ? 'post is' : 'posts are';
+
+ return "{$count} {$noun} at risk in {$this->workspace->name}";
+ }
+
+ public function attachments(): array
+ {
+ return [];
+ }
+}
diff --git a/app/Mail/PostPublishFailed.php b/app/Mail/PostPublishFailed.php
index 2d422d109..94415503f 100644
--- a/app/Mail/PostPublishFailed.php
+++ b/app/Mail/PostPublishFailed.php
@@ -32,7 +32,7 @@ class PostPublishFailed extends Mailable implements ShouldQueue
{
$failedPlatforms = $this->post->postPlatforms()
->with('socialAccount')
- ->where('enabled', true)
+ ->enabled()
->get()
->filter(fn ($pp) => $pp->status === Status::Failed)
->map(fn ($pp) => [
diff --git a/app/Mail/PostPublished.php b/app/Mail/PostPublished.php
index f67196197..ead767f8d 100644
--- a/app/Mail/PostPublished.php
+++ b/app/Mail/PostPublished.php
@@ -32,7 +32,7 @@ class PostPublished extends Mailable implements ShouldQueue
{
$publishedPlatforms = $this->post->postPlatforms()
->with('socialAccount')
- ->where('enabled', true)
+ ->enabled()
->get()
->filter(fn ($pp) => $pp->status === Status::Published)
->map(fn ($pp) => [
diff --git a/app/Mcp/Tools/Post/PublishPostTool.php b/app/Mcp/Tools/Post/PublishPostTool.php
index 16278625c..fb038870f 100644
--- a/app/Mcp/Tools/Post/PublishPostTool.php
+++ b/app/Mcp/Tools/Post/PublishPostTool.php
@@ -47,7 +47,7 @@ class PublishPostTool extends Tool
return $denied;
}
- if (! $post->postPlatforms()->where('enabled', true)->exists()) {
+ if (! $post->postPlatforms()->enabled()->exists()) {
return Response::error('Post has no enabled platforms. Use update-post-tool to enable at least one platform first.');
}
diff --git a/app/Models/NotificationPreference.php b/app/Models/NotificationPreference.php
index cd5f39d01..04d02a26a 100644
--- a/app/Models/NotificationPreference.php
+++ b/app/Models/NotificationPreference.php
@@ -4,13 +4,16 @@ declare(strict_types=1);
namespace App\Models;
+use Database\Factories\NotificationPreferenceFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NotificationPreference extends Model
{
- use HasUuids;
+ /** @use HasFactory<NotificationPreferenceFactory> */
+ use HasFactory, HasUuids;
protected $fillable = [
'user_id',
diff --git a/app/Models/Post.php b/app/Models/Post.php
index 8d587d7f1..4c1d764b4 100644
--- a/app/Models/Post.php
+++ b/app/Models/Post.php
@@ -148,7 +148,7 @@ class Post extends Model
public function allowedMediaTypes(): array
{
$platforms = $this->postPlatforms()
- ->where('enabled', true)
+ ->enabled()
->with('socialAccount')
->get()
->pluck('socialAccount.platform')
diff --git a/app/Models/PostPlatform.php b/app/Models/PostPlatform.php
index 2063471c7..35f0f0dda 100644
--- a/app/Models/PostPlatform.php
+++ b/app/Models/PostPlatform.php
@@ -8,6 +8,7 @@ use App\Enums\PostPlatform\ContentType;
use App\Enums\PostPlatform\Status;
use App\Enums\SocialAccount\Platform as SocialPlatform;
use Database\Factories\PostPlatformFactory;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -35,6 +36,7 @@ class PostPlatform extends Model
'error_context',
'published_at',
'meta',
+ 'connection_warning_sent_at',
];
protected function casts(): array
@@ -47,6 +49,7 @@ class PostPlatform extends Model
'published_at' => 'datetime',
'meta' => 'array',
'error_context' => 'array',
+ 'connection_warning_sent_at' => 'datetime',
];
}
@@ -60,12 +63,22 @@ class PostPlatform extends Model
return $this->belongsTo(SocialAccount::class);
}
+ /**
+ * Only platforms still enabled for publishing — disabled ones are
+ * excluded from PublishPost, so anything else that mirrors publish
+ * eligibility (previews, validation, proactive checks) must too.
+ */
+ public function scopeEnabled(Builder $query): Builder
+ {
+ return $query->where('post_platforms.enabled', true);
+ }
+
/**
* Get display name, falling back to snapshot if account was deleted.
*/
public function getDisplayNameAttribute(): string
{
- return $this->socialAccount?->display_name ?? $this->platform_name ?? $this->platform->label();
+ return $this->socialAccount?->accountDisplayName() ?? $this->platform_name ?? $this->platform->label();
}
/**
diff --git a/app/Models/SocialAccount.php b/app/Models/SocialAccount.php
index 21a3f5730..61adc357b 100644
--- a/app/Models/SocialAccount.php
+++ b/app/Models/SocialAccount.php
@@ -46,6 +46,7 @@ class SocialAccount extends Model
'error_message',
'disconnected_at',
'last_used_at',
+ 'last_verified_at',
];
protected $hidden = [
@@ -53,6 +54,11 @@ class SocialAccount extends Model
'refresh_token',
];
+ protected $appends = [
+ 'display_label',
+ 'handle_label',
+ ];
+
protected function casts(): array
{
return [
@@ -64,6 +70,7 @@ class SocialAccount extends Model
'token_expires_at' => 'datetime',
'disconnected_at' => 'datetime',
'last_used_at' => 'datetime',
+ 'last_verified_at' => 'datetime',
'scopes' => 'array',
'meta' => 'array',
];
@@ -145,6 +152,49 @@ class SocialAccount extends Model
);
}
+ /**
+ * "@handle" for notification bodies — the more specific identifier
+ * (username) wins over the friendlier display name when both are set.
+ * Every connector requests enough scope to always populate at least one
+ * of username/display_name (e.g. TikTok always requests user.info.profile);
+ * the platform label is a last-resort fallback, not an expected path.
+ */
+ public function handle(): string
+ {
+ return '@'.($this->username ?: $this->display_name ?: $this->platform->label());
+ }
+
+ /**
+ * Friendly label for email templates — the display name wins over the
+ * username when both are set.
+ */
+ public function accountDisplayName(): string
+ {
+ return $this->display_name ?: $this->username ?: $this->platform->label();
+ }
+
+ /**
+ * Frontend-facing mirror of accountDisplayName() — appended to JSON so
+ * Vue components stop re-implementing this fallback.
+ */
+ protected function displayLabel(): Attribute
+ {
+ return Attribute::make(
+ get: fn () => $this->accountDisplayName(),
+ );
+ }
+
+ /**
+ * Frontend-facing mirror of handle() without the "@" prefix — templates
+ * that render their own "@" (e.g. platform previews) use this instead.
+ */
+ protected function handleLabel(): Attribute
+ {
+ return Attribute::make(
+ get: fn () => $this->username ?: $this->display_name ?: $this->platform->label(),
+ );
+ }
+
public function markAsDisconnected(string $errorMessage): void
{
$lock = Cache::lock("social_account_status:{$this->id}", 10);
@@ -163,7 +213,7 @@ class SocialAccount extends Model
if ($wasConnected && $this->workspace->owner) {
$placeholders = [
'platform' => $this->platform->label(),
- 'account' => '@'.($this->username ?? $this->display_name),
+ 'account' => $this->handle(),
];
SendNotification::dispatch(
@@ -204,7 +254,7 @@ class SocialAccount extends Model
if ($notify && $wasUsable && $this->workspace->owner) {
$placeholders = [
'platform' => $this->platform->label(),
- 'account' => '@'.($this->username ?? $this->display_name),
+ 'account' => $this->handle(),
];
SendNotification::dispatch(
diff --git a/app/Models/User.php b/app/Models/User.php
index c730af1e7..dd9795dbb 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -116,7 +116,7 @@ class User extends Authenticatable implements MustVerifyEmail, OAuthenticatable
return match ($type) {
NotificationType::PostPublished => $preference->post_published,
NotificationType::PostFailed, NotificationType::PostPartiallyPublished => $preference->post_failed,
- NotificationType::AccountDisconnected => $preference->account_disconnected,
+ NotificationType::AccountDisconnected, NotificationType::PostAtRisk => $preference->account_disconnected,
NotificationType::MentionedInComment => $preference->mentioned_in_comment ?? true,
default => true,
};
diff --git a/app/Rules/ContentTypeCompatibleWithMedia.php b/app/Rules/ContentTypeCompatibleWithMedia.php
index 983728597..e8fd27cf2 100644
--- a/app/Rules/ContentTypeCompatibleWithMedia.php
+++ b/app/Rules/ContentTypeCompatibleWithMedia.php
@@ -77,7 +77,7 @@ class ContentTypeCompatibleWithMedia implements DataAwareRule, ValidationRule
])->all();
}
- return $post->postPlatforms()->where('enabled', true)->get()->values()
+ return $post->postPlatforms()->enabled()->get()->values()
->map(fn ($postPlatform, $index): array => [
'key' => "platforms.{$index}.content_type",
'content_type' => $postPlatform->content_type?->value,
diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.php
index 64fc11930..a12b3ff95 100644
--- a/app/Services/Image/TemplateImageGenerator.php
+++ b/app/Services/Image/TemplateImageGenerator.php
@@ -362,7 +362,7 @@ class TemplateImageGenerator
$footerColor = '#9ca3af';
$username = $socialAccount->username ?? '';
- $displayName = $socialAccount->display_name ?? '';
+ $displayName = $socialAccount->display_label;
// Footer row anchored from the bottom: avatar + handle + displayName
// share the same vertical center so they line up cleanly.
@@ -748,7 +748,7 @@ class TemplateImageGenerator
$nameX = $avatarX + $avatarSize + 16;
- $displayNameText = $socialAccount->display_name ?? '';
+ $displayNameText = $socialAccount->display_label;
$handleText = '@'.($socialAccount->username ?? '');
$nameBox = $fontBold ? imagettfbbox($nameSize, 0, $fontBold, $displayNameText) : [0, 0, 0, 0, 0, 0, 0, 0];
$handleBox = $fontLight ? imagettfbbox($handleSize, 0, $fontLight, $handleText) : [0, 0, 0, 0, 0, 0, 0, 0];
diff --git a/app/Services/Social/ConnectionVerifier.php b/app/Services/Social/ConnectionVerifier.php
index 2ae7570fd..954e83298 100644
--- a/app/Services/Social/ConnectionVerifier.php
+++ b/app/Services/Social/ConnectionVerifier.php
@@ -6,6 +6,15 @@ namespace App\Services\Social;
use App\Enums\SocialAccount\Platform;
use App\Exceptions\PlatformUnavailableException;
+use App\Exceptions\Social\BlueskyPublishException;
+use App\Exceptions\Social\DiscordPublishException;
+use App\Exceptions\Social\LinkedInPublishException;
+use App\Exceptions\Social\MastodonPublishException;
+use App\Exceptions\Social\PinterestPublishException;
+use App\Exceptions\Social\TelegramPublishException;
+use App\Exceptions\Social\TikTokPublishException;
+use App\Exceptions\Social\XPublishException;
+use App\Exceptions\Social\YouTubePublishException;
use App\Exceptions\TokenExpiredException;
use App\Models\SocialAccount;
use App\Services\Social\Discord\DiscordClient;
@@ -38,6 +47,16 @@ class ConnectionVerifier
try {
return $this->callVerifyEndpoint($account);
} catch (TokenExpiredException $e) {
+ if (! $account->platform->hasTokenRefreshFlow()) {
+ // Facebook/InstagramFacebook (Page tokens) and Mastodon
+ // tokens don't expire, and Telegram/Discord authenticate
+ // with one bot token shared across every connected account
+ // of that platform — none of them have anything to refresh,
+ // so retrying would just repeat this identical rejection
+ // while burning a call against a budget shared app-wide.
+ throw $e;
+ }
+
// Verify returned 401: the access_token is actually invalid.
// Refresh and retry once with the new token.
return $this->refreshThenVerify($account, $e);
@@ -365,11 +384,18 @@ class ConnectionVerifier
])
->get(config('trypost.platforms.linkedin.api').'/rest/userinfo');
- if ($response->status() === 401) {
+ if (LinkedInPublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('LinkedIn access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyLinkedInPage(SocialAccount $account): bool
@@ -383,11 +409,18 @@ class ConnectionVerifier
'q' => 'roleAssignee',
]);
- if ($response->status() === 401) {
+ if (LinkedInPublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('LinkedIn Page access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyX(SocialAccount $account): bool
@@ -395,11 +428,18 @@ class ConnectionVerifier
$response = Http::withToken($account->access_token)
->get(config('trypost.platforms.x.api').'/users/me');
- if ($response->status() === 401) {
+ if (XPublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('X access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyInstagram(SocialAccount $account): bool
@@ -460,14 +500,22 @@ class ConnectionVerifier
'fields' => 'open_id,display_name',
]);
- $body = $response->json() ?? [];
- $errorCode = $body['error']['code'] ?? null;
-
- if ($response->status() === 401 || in_array($errorCode, ['access_token_invalid', 'access_token_expired', 10001, 10002])) {
+ // 401 here (unlike a publish-time 401, which TikTok also returns for
+ // scope_not_authorized/scope_permission_missed) is unambiguous: this
+ // endpoint only needs the always-granted user.info.basic scope, so a
+ // 401 can't be a scope gap. See TikTokPublishException::isConfirmedDeadToken().
+ if (TikTokPublishException::isConfirmedDeadToken($response) || $response->status() === 401) {
throw new TokenExpiredException('TikTok access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyYouTube(SocialAccount $account): bool
@@ -478,11 +526,18 @@ class ConnectionVerifier
'mine' => 'true',
]);
- if ($response->status() === 401) {
+ if (YouTubePublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('YouTube access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyPinterest(SocialAccount $account): bool
@@ -490,11 +545,18 @@ class ConnectionVerifier
$response = Http::withToken($account->access_token)
->get(config('trypost.platforms.pinterest.api').'/user_account');
- if ($response->status() === 401) {
+ if (PinterestPublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('Pinterest access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyBluesky(SocialAccount $account): bool
@@ -506,14 +568,18 @@ class ConnectionVerifier
'actor' => $account->platform_user_id,
]);
- $body = $response->json() ?? [];
- $error = $body['error'] ?? null;
-
- if ($error === 'ExpiredToken' || $error === 'InvalidToken') {
+ if (BlueskyPublishException::isConfirmedDeadToken($response)) {
throw new TokenExpiredException('Bluesky access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
private function verifyTelegram(SocialAccount $account): bool
@@ -523,13 +589,31 @@ class ConnectionVerifier
'chat_id' => data_get($account->meta, 'chat_id'),
]);
- return $response->successful() && data_get($response->json(), 'ok') === true;
+ if ($response->successful() && data_get($response->json(), 'ok') === true) {
+ return true;
+ }
+
+ if (TelegramPublishException::isConfirmedDeadChat($response)) {
+ throw new TokenExpiredException('Telegram bot no longer has access to the chat');
+ }
+
+ throw new PlatformUnavailableException("Telegram getChat failed ({$response->status()}).", $response->status());
}
private function verifyDiscord(SocialAccount $account): bool
{
// The guild endpoint succeeds only while the bot is still a member.
- return app(DiscordClient::class)->getGuild((string) $account->platform_user_id)->successful();
+ $response = app(DiscordClient::class)->getGuild((string) $account->platform_user_id);
+
+ if ($response->successful()) {
+ return true;
+ }
+
+ if (DiscordPublishException::isConfirmedDeadGuild($response)) {
+ throw new TokenExpiredException('Discord bot no longer has access to the guild');
+ }
+
+ throw new PlatformUnavailableException("Discord guild lookup failed ({$response->status()}).", $response->status());
}
private function verifyMastodon(SocialAccount $account): bool
@@ -539,10 +623,22 @@ class ConnectionVerifier
$response = Http::withToken($account->access_token)
->get("{$instance}/api/v1/accounts/verify_credentials");
- if ($response->status() === 401 || $response->status() === 403) {
+ // 403 here (unlike a publish-time 403 on the write-scoped /statuses
+ // endpoint) means even read access is gone — verify_credentials is
+ // the lowest-privilege endpoint every authorized app token can
+ // reach, so a 403 confirms total revocation, not a scope gap. See
+ // MastodonPublishException::isConfirmedDeadToken().
+ if (MastodonPublishException::isConfirmedDeadToken($response) || $response->status() === 403) {
throw new TokenExpiredException('Mastodon access token is invalid or expired');
}
- return $response->successful();
+ if ($response->successful()) {
+ return true;
+ }
+
+ throw new PlatformUnavailableException(
+ "{$account->platform->label()} verify failed ({$response->status()}).",
+ $response->status(),
+ );
}
}
diff --git a/app/Support/PostPlatformMetaRules.php b/app/Support/PostPlatformMetaRules.php
index cfb57b80d..15cc71046 100644
--- a/app/Support/PostPlatformMetaRules.php
+++ b/app/Support/PostPlatformMetaRules.php
@@ -140,7 +140,7 @@ class PostPlatformMetaRules
{
$errors = [];
- foreach ($post->postPlatforms()->where('enabled', true)->get()->values() as $index => $postPlatform) {
+ foreach ($post->postPlatforms()->enabled()->get()->values() as $index => $postPlatform) {
$violation = self::requiredMetaViolation($postPlatform->platform, $postPlatform->meta);
if ($violation !== null) {
diff --git a/database/factories/NotificationPreferenceFactory.php b/database/factories/NotificationPreferenceFactory.php
new file mode 100644
index 000000000..2a5901df0
--- /dev/null
+++ b/database/factories/NotificationPreferenceFactory.php
@@ -0,0 +1,31 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Database\Factories;
+
+use App\Models\NotificationPreference;
+use App\Models\User;
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/**
+ * @extends Factory<NotificationPreference>
+ */
+class NotificationPreferenceFactory extends Factory
+{
+ /**
+ * Define the model's default state.
+ *
+ * @return array<string, mixed>
+ */
+ public function definition(): array
+ {
+ return [
+ 'user_id' => User::factory(),
+ 'post_published' => true,
+ 'post_failed' => true,
+ 'account_disconnected' => true,
+ 'mentioned_in_comment' => true,
+ ];
+ }
+}
diff --git a/database/migrations/2026_08_08_090000_add_connection_warning_sent_at_to_post_platforms_table.php b/database/migrations/2026_08_08_090000_add_connection_warning_sent_at_to_post_platforms_table.php
new file mode 100644
index 000000000..66850b741
--- /dev/null
+++ b/database/migrations/2026_08_08_090000_add_connection_warning_sent_at_to_post_platforms_table.php
@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ public function up(): void
+ {
+ Schema::table('post_platforms', function (Blueprint $table) {
+ $table->timestamp('connection_warning_sent_at')->nullable()->after('error_context');
+ $table->index(['status', 'enabled', 'connection_warning_sent_at']);
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table('post_platforms', function (Blueprint $table) {
+ $table->dropIndex(['status', 'enabled', 'connection_warning_sent_at']);
+ $table->dropColumn('connection_warning_sent_at');
+ });
+ }
+};
diff --git a/database/migrations/2026_08_08_204549_add_last_verified_at_to_social_accounts_table.php b/database/migrations/2026_08_08_204549_add_last_verified_at_to_social_accounts_table.php
new file mode 100644
index 000000000..d4de8b8cc
--- /dev/null
+++ b/database/migrations/2026_08_08_204549_add_last_verified_at_to_social_accounts_table.php
@@ -0,0 +1,24 @@
+<?php
+
+declare(strict_types=1);
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ public function up(): void
+ {
+ Schema::table('social_accounts', function (Blueprint $table) {
+ $table->timestamp('last_verified_at')->nullable()->after('last_used_at');
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table('social_accounts', function (Blueprint $table) {
+ $table->dropColumn('last_verified_at');
+ });
+ }
+};
diff --git a/lang/ar/notifications.php b/lang/ar/notifications.php
index 552b50284..799c1bc7c 100644
--- a/lang/ar/notifications.php
+++ b/lang/ar/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'يحتاج حساب :platform إلى إعادة الربط',
'body' => 'انتهت جلسة :account — يرجى إعادة الربط لمواصلة النشر',
],
+ 'post_at_risk' => [
+ 'title' => '{1} منشور واحد قادم معرض للخطر|{2} منشوران قادمان معرضان للخطر|[3,10] :count منشورات قادمة معرضة للخطر|[11,*] :count منشورًا قادمًا معرضًا للخطر',
+ ],
];
diff --git a/lang/de/notifications.php b/lang/de/notifications.php
index 9d91e8d87..8abf45f2b 100644
--- a/lang/de/notifications.php
+++ b/lang/de/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform-Konto muss erneut verbunden werden',
'body' => 'Sitzung von :account abgelaufen – bitte verbinde es erneut, um weiter zu posten',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count bevorstehender Beitrag ist gefährdet|[2,*] :count bevorstehende Beiträge sind gefährdet',
+ ],
];
diff --git a/lang/el/notifications.php b/lang/el/notifications.php
index 88f8ff080..ebb9a5137 100644
--- a/lang/el/notifications.php
+++ b/lang/el/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Ο λογαριασμός :platform χρειάζεται επανασύνδεση',
'body' => 'Η συνεδρία :account έληξε — επανασυνδεθείτε για να συνεχίσετε να δημοσιεύετε',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count επερχόμενη ανάρτηση κινδυνεύει|[2,*] :count επερχόμενες αναρτήσεις κινδυνεύουν',
+ ],
];
diff --git a/lang/en/notifications.php b/lang/en/notifications.php
index 338fd5ee6..a51f6fa12 100644
--- a/lang/en/notifications.php
+++ b/lang/en/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform account needs to be reconnected',
'body' => ':account session expired — please reconnect to keep posting',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count upcoming post is at risk|[2,*] :count upcoming posts are at risk',
+ ],
];
diff --git a/lang/es/notifications.php b/lang/es/notifications.php
index 0f6620aa5..7956aa38f 100644
--- a/lang/es/notifications.php
+++ b/lang/es/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Cuenta de :platform necesita reconectarse',
'body' => 'La sesión de :account expiró — reconéctala para seguir publicando',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count próxima publicación está en riesgo|[2,*] :count próximas publicaciones están en riesgo',
+ ],
];
diff --git a/lang/fr/notifications.php b/lang/fr/notifications.php
index dd8b0b477..4d12beed1 100644
--- a/lang/fr/notifications.php
+++ b/lang/fr/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Le compte :platform doit être reconnecté',
'body' => 'La session de :account a expiré — veuillez reconnecter pour continuer à publier',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count publication à venir est à risque|[2,*] :count publications à venir sont à risque',
+ ],
];
diff --git a/lang/it/notifications.php b/lang/it/notifications.php
index 23e602502..ec283247d 100644
--- a/lang/it/notifications.php
+++ b/lang/it/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'L\'account :platform deve essere ricollegato',
'body' => 'Sessione di :account scaduta — ricollegalo per continuare a pubblicare',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count post imminente è a rischio|[2,*] :count post imminenti sono a rischio',
+ ],
];
diff --git a/lang/ja/notifications.php b/lang/ja/notifications.php
index f2f2ccb2f..b839c1990 100644
--- a/lang/ja/notifications.php
+++ b/lang/ja/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform アカウントの再接続が必要です',
'body' => ':account のセッションの有効期限が切れました — 投稿を続けるには再接続してください',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count 件の予定投稿にリスクがあります|[2,*] :count 件の予定投稿にリスクがあります',
+ ],
];
diff --git a/lang/ko/notifications.php b/lang/ko/notifications.php
index a7534682b..25abc4371 100644
--- a/lang/ko/notifications.php
+++ b/lang/ko/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform 계정을 재연결해야 합니다',
'body' => ':account 세션이 만료되었습니다 — 계속 게시하려면 재연결하세요',
],
+ 'post_at_risk' => [
+ 'title' => '{1} 예정된 게시물 :count건이 위험합니다|[2,*] 예정된 게시물 :count건이 위험합니다',
+ ],
];
diff --git a/lang/nl/notifications.php b/lang/nl/notifications.php
index aa97841e2..f7de37d47 100644
--- a/lang/nl/notifications.php
+++ b/lang/nl/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform-account moet opnieuw worden gekoppeld',
'body' => 'Sessie van :account verlopen — koppel opnieuw om te blijven posten',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count aankomende post loopt risico|[2,*] :count aankomende posts lopen risico',
+ ],
];
diff --git a/lang/pl/notifications.php b/lang/pl/notifications.php
index 52c29ef69..c0ba06860 100644
--- a/lang/pl/notifications.php
+++ b/lang/pl/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Konto :platform wymaga ponownego połączenia',
'body' => 'Sesja :account wygasła — połącz ponownie, aby dalej publikować',
],
+ 'post_at_risk' => [
+ 'title' => ':count nadchodzący post jest zagrożony|:count nadchodzące posty są zagrożone|:count nadchodzących postów jest zagrożonych',
+ ],
];
diff --git a/lang/pt-BR/notifications.php b/lang/pt-BR/notifications.php
index f929f57cb..43c078d5c 100644
--- a/lang/pt-BR/notifications.php
+++ b/lang/pt-BR/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Conta do :platform precisa ser reconectada',
'body' => 'Sessão de :account expirou — reconecte pra continuar postando',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count post agendado está em risco|[2,*] :count posts agendados estão em risco',
+ ],
];
diff --git a/lang/ru/notifications.php b/lang/ru/notifications.php
index 85e0aa42c..b92e54a4d 100644
--- a/lang/ru/notifications.php
+++ b/lang/ru/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Аккаунт :platform требует переподключения',
'body' => 'Сессия :account истекла — переподключите, чтобы продолжить публикацию',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count запланированный пост под угрозой|[2,4] :count запланированных поста под угрозой|[5,*] :count запланированных постов под угрозой',
+ ],
];
diff --git a/lang/tr/notifications.php b/lang/tr/notifications.php
index 94ca6b1bf..75679f675 100644
--- a/lang/tr/notifications.php
+++ b/lang/tr/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform hesabının yeniden bağlanması gerekiyor',
'body' => ':account oturumunun süresi doldu — paylaşıma devam etmek için lütfen yeniden bağlanın',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count planlanan gönderi risk altında|[2,*] :count planlanan gönderi risk altında',
+ ],
];
diff --git a/lang/uk/notifications.php b/lang/uk/notifications.php
index 0987d4518..bd93ce6f9 100644
--- a/lang/uk/notifications.php
+++ b/lang/uk/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => 'Акаунт :platform потрібно перепідключити',
'body' => 'Сесію :account завершено — перепідключіть, щоб продовжити публікацію',
],
+ 'post_at_risk' => [
+ 'title' => '{1} :count запланована публікація під загрозою|[2,*] :count заплановані публікації під загрозою',
+ ],
];
diff --git a/lang/zh/notifications.php b/lang/zh/notifications.php
index 643c912f1..949e7e1ca 100644
--- a/lang/zh/notifications.php
+++ b/lang/zh/notifications.php
@@ -15,4 +15,7 @@ return [
'title' => ':platform 账号需要重新连接',
'body' => ':account 会话已过期——请重新连接以继续发帖',
],
+ 'post_at_risk' => [
+ 'title' => '{1} 有 :count 篇待发布的帖子存在风险|[2,*] 有 :count 篇待发布的帖子存在风险',
+ ],
];
diff --git a/maizzle/components/footer-authenticated.html b/maizzle/components/footer-authenticated.html
new file mode 100644
index 000000000..66dba8687
--- /dev/null
+++ b/maizzle/components/footer-authenticated.html
@@ -0,0 +1,48 @@
+<tr>
+ <td align="center" class="text-center text-zinc-600 text-xs p-6">
+ <p class="m-0 mb-2">
+ Open-source social media scheduling tool
+ </p>
+
+ <p class="m-0 mt-2">
+ <a href="@{{ route('app.notifications.preferences') }}" target="_blank"
+ class="text-zinc-600 [text-decoration:none] hover:![text-decoration:underline]">
+ Manage notifications
+ </a>
+ </p>
+
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" class="mx-auto mt-4">
+ <tr>
+ <td class="px-1">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="@{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="@{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="@{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="@{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="@{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram">
+ </a>
+ </td>
+ </tr>
+ </table>
+
+ <p class="m-0 mt-3">
+ &copy; @{{ date('Y') }} TryPost.it
+ </p>
+ </td>
+</tr>
diff --git a/maizzle/components/footer.html b/maizzle/components/footer.html
index e184c7692..0feba36c5 100644
--- a/maizzle/components/footer.html
+++ b/maizzle/components/footer.html
@@ -1,22 +1,41 @@
-<script props>
- module.exports = {
- unsubscribe_url: props.unsubscribe_url
- }
-</script>
-
<tr>
<td align="center" class="text-center text-zinc-600 text-xs p-6">
<p class="m-0 mb-2">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
- <p class="m-0 mt-2">
- <a href="{{ unsubscribe_url }}" target="_blank"
- class="text-zinc-600 [text-decoration:none] hover:![text-decoration:underline]">
- Unsubscribe
- </a>
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" class="mx-auto mt-3">
+ <tr>
+ <td class="px-1">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="@{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="@{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="@{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="@{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord">
+ </a>
+ </td>
+ <td class="px-1">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="@{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram">
+ </a>
+ </td>
+ </tr>
+ </table>
+
+ <p class="m-0 mt-3">
+ &copy; @{{ date('Y') }} TryPost.it
</p>
- @endif
</td>
-</tr>
\ No newline at end of file
+</tr>
diff --git a/maizzle/images/social/discord.png b/maizzle/images/social/discord.png
new file mode 100644
index 000000000..290fc4542
Binary files /dev/null and b/maizzle/images/social/discord.png differ
diff --git a/maizzle/images/social/github.png b/maizzle/images/social/github.png
new file mode 100644
index 000000000..8caa67b57
Binary files /dev/null and b/maizzle/images/social/github.png differ
diff --git a/maizzle/images/social/instagram.png b/maizzle/images/social/instagram.png
new file mode 100644
index 000000000..8140f2daf
Binary files /dev/null and b/maizzle/images/social/instagram.png differ
diff --git a/maizzle/images/social/x.png b/maizzle/images/social/x.png
new file mode 100644
index 000000000..1033d816b
Binary files /dev/null and b/maizzle/images/social/x.png differ
diff --git a/maizzle/images/social/youtube.png b/maizzle/images/social/youtube.png
new file mode 100644
index 000000000..33509fcb8
Binary files /dev/null and b/maizzle/images/social/youtube.png differ
diff --git a/maizzle/templates/account-disconnected.html b/maizzle/templates/account-disconnected.html
index 6b0d9b265..b572c9be7 100644
--- a/maizzle/templates/account-disconnected.html
+++ b/maizzle/templates/account-disconnected.html
@@ -40,7 +40,7 @@
</td>
</tr>
</table>
- <x-footer />
+ <x-footer-authenticated />
</td>
</tr>
</table>
diff --git a/maizzle/templates/mentioned-in-comment.html b/maizzle/templates/mentioned-in-comment.html
index d2d73da13..99b705656 100644
--- a/maizzle/templates/mentioned-in-comment.html
+++ b/maizzle/templates/mentioned-in-comment.html
@@ -30,7 +30,7 @@
</td>
</tr>
</table>
- <x-footer />
+ <x-footer-authenticated />
</td>
</tr>
</table>
diff --git a/maizzle/templates/post-at-risk.html b/maizzle/templates/post-at-risk.html
new file mode 100644
index 000000000..1fa088ca0
--- /dev/null
+++ b/maizzle/templates/post-at-risk.html
@@ -0,0 +1,57 @@
+<x-main>
+ <div class="bg-zinc-50 sm:px-4 font-sans">
+ <table align="center">
+ <tr>
+ <td class="w-[552px] max-w-full">
+ <x-header />
+
+ <table class="w-full">
+ <tr>
+ <td class="p-12 sm:px-6 text-base text-zinc-700 bg-white rounded shadow-sm">
+ <h1 class="m-0 mb-6 text-2xl sm:leading-8 text-black font-semibold">
+ @{{ $title }}
+ </h1>
+
+ <p class="m-0 leading-6">
+ @{{ $intro }}
+ </p>
+
+ <table class="w-full mt-4" style="border-collapse: collapse">
+ @foreach($atRiskGroups as $group)
+ <tr>
+ <td class="py-3" style="border-bottom: 1px solid #e4e4e7">
+ <div style="display: flex; align-items: center">
+ <div style="width: 8px; height: 8px; border-radius: 50%; background-color: @{{ $group['account']->platform->color() }}; margin-right: 12px"></div>
+ <div>
+ <strong class="text-zinc-900">@{{ $group['account']->platform->label() }}</strong>
+ <span class="text-zinc-500"> - @{{ $group['account']->accountDisplayName() }}</span>
+ <div class="text-zinc-500" style="font-size: 14px; margin-top: 4px">
+ @{{ $group['postsLabel'] }}
+ </div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ @endforeach
+ </table>
+
+ <p class="m-0 mt-4 leading-6">
+ @{{ $reconnectCta }}
+ </p>
+
+ <x-spacer height="24px" />
+
+ <div class="flex items-center justify-center">
+ <x-button href="@{{ $url }}">
+ @{{ $buttonText }} &rarr;
+ </x-button>
+ </div>
+ </td>
+ </tr>
+ </table>
+ <x-footer-authenticated />
+ </td>
+ </tr>
+ </table>
+ </div>
+</x-main>
diff --git a/maizzle/templates/post-publish-failed.html b/maizzle/templates/post-publish-failed.html
index 206dc8b8d..b0f986bac 100644
--- a/maizzle/templates/post-publish-failed.html
+++ b/maizzle/templates/post-publish-failed.html
@@ -42,7 +42,7 @@
</td>
</tr>
</table>
- <x-footer />
+ <x-footer-authenticated />
</td>
</tr>
</table>
diff --git a/maizzle/templates/post-published.html b/maizzle/templates/post-published.html
index ad79ddad9..bac501173 100644
--- a/maizzle/templates/post-published.html
+++ b/maizzle/templates/post-published.html
@@ -42,7 +42,7 @@
</td>
</tr>
</table>
- <x-footer />
+ <x-footer-authenticated />
</td>
</tr>
</table>
diff --git a/maizzle/templates/workspace-connections-disconnected.html b/maizzle/templates/workspace-connections-disconnected.html
index 3e94c864b..d9de6a73a 100644
--- a/maizzle/templates/workspace-connections-disconnected.html
+++ b/maizzle/templates/workspace-connections-disconnected.html
@@ -24,9 +24,7 @@
<div style="width: 8px; height: 8px; border-radius: 50%; background-color: @{{ $account->platform->color() }}; margin-right: 12px"></div>
<div>
<strong class="text-zinc-900">@{{ $account->platform->label() }}</strong>
- @if($account->display_name || $account->username)
- <span class="text-zinc-500"> - @{{ $account->display_name ?? $account->username }}</span>
- @endif
+ <span class="text-zinc-500"> - @{{ $account->accountDisplayName() }}</span>
</div>
</div>
</td>
@@ -58,7 +56,7 @@
</td>
</tr>
</table>
- <x-footer />
+ <x-footer-authenticated />
</td>
</tr>
</table>
diff --git a/public/images/emails/social/discord.png b/public/images/emails/social/discord.png
new file mode 100644
index 000000000..290fc4542
Binary files /dev/null and b/public/images/emails/social/discord.png differ
diff --git a/public/images/emails/social/github.png b/public/images/emails/social/github.png
new file mode 100644
index 000000000..8caa67b57
Binary files /dev/null and b/public/images/emails/social/github.png differ
diff --git a/public/images/emails/social/instagram.png b/public/images/emails/social/instagram.png
new file mode 100644
index 000000000..8140f2daf
Binary files /dev/null and b/public/images/emails/social/instagram.png differ
diff --git a/public/images/emails/social/x.png b/public/images/emails/social/x.png
new file mode 100644
index 000000000..1033d816b
Binary files /dev/null and b/public/images/emails/social/x.png differ
diff --git a/public/images/emails/social/youtube.png b/public/images/emails/social/youtube.png
new file mode 100644
index 000000000..33509fcb8
Binary files /dev/null and b/public/images/emails/social/youtube.png differ
diff --git a/resources/js/components/MentionTextarea.vue b/resources/js/components/MentionTextarea.vue
index 0a3c27727..85778b48d 100644
--- a/resources/js/components/MentionTextarea.vue
+++ b/resources/js/components/MentionTextarea.vue
@@ -5,6 +5,7 @@ import { nextTick, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Textarea } from '@/components/ui/textarea';
+import { getInitials } from '@/composables/useInitials';
import debounce from '@/debounce';
import { search as searchMembers } from '@/routes/app/workspace/members';
@@ -294,7 +295,7 @@ onBeforeUnmount(() => closePopover());
>
<Avatar class="h-6 w-6 shrink-0">
<AvatarImage v-if="member.avatar_url" :src="member.avatar_url" :alt="member.name" />
- <AvatarFallback class="text-[10px]">{{ member.name.charAt(0).toUpperCase() }}</AvatarFallback>
+ <AvatarFallback class="text-[10px]">{{ getInitials(member.name) }}</AvatarFallback>
</Avatar>
<div class="min-w-0 flex-1">
<p class="truncate text-sm font-medium">{{ member.name }}</p>
diff --git a/resources/js/components/SocialAccountsGrid.vue b/resources/js/components/SocialAccountsGrid.vue
index 6e2bcc63d..808b0c5f6 100644
--- a/resources/js/components/SocialAccountsGrid.vue
+++ b/resources/js/components/SocialAccountsGrid.vue
@@ -19,6 +19,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip';
+import { getInitials } from '@/composables/useInitials';
import { useOAuthPopup } from '@/composables/useOAuthPopup';
import { getPlatformLogo } from '@/composables/usePlatformLogo';
import { toggle as toggleAccount } from '@/routes/app/accounts';
@@ -29,6 +30,8 @@ export interface SocialAccount {
platform_user_id: string;
username: string;
display_name: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string;
status: 'connected' | 'disconnected' | 'token_expired' | null;
is_active: boolean;
@@ -201,10 +204,7 @@ const isDisconnected = (account: SocialAccount | null): boolean => {
v-if="platform.connected && platform.account"
class="truncate text-sm text-muted-foreground"
>
- @{{
- platform.account.username ||
- platform.account.display_name
- }}
+ @{{ platform.account.handle_label }}
</p>
<p v-else class="text-sm text-muted-foreground">
{{ trans('accounts.not_connected') }}
@@ -244,13 +244,13 @@ const isDisconnected = (account: SocialAccount | null): boolean => {
:src="platform.account.avatar_url"
/>
<AvatarFallback class="text-xs">
- {{ platform.account.display_name?.charAt(0) }}
+ {{ getInitials(platform.account.display_label) }}
</AvatarFallback>
</Avatar>
<span
class="max-w-[120px] truncate text-sm font-medium"
>
- {{ platform.account.display_name }}
+ {{ platform.account.display_label }}
</span>
</div>
<div class="flex items-center gap-1">
diff --git a/resources/js/components/accounts/NetworkConnectGrid.vue b/resources/js/components/accounts/NetworkConnectGrid.vue
index e1532f752..314beabd4 100644
--- a/resources/js/components/accounts/NetworkConnectGrid.vue
+++ b/resources/js/components/accounts/NetworkConnectGrid.vue
@@ -27,6 +27,8 @@ export interface ConnectedAccount {
network: string;
username: string;
display_name: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
status: 'connected' | 'disconnected' | 'token_expired' | null;
}
@@ -170,7 +172,7 @@ const { openOAuthPopup } = useOAuthPopup((result) => {
const disconnectAccount = (account: ConnectedAccount) => {
disconnectModal.value?.open({
url: disconnect.url(account.id),
- confirmText: account.username || account.display_name,
+ confirmText: account.handle_label,
});
};
@@ -321,10 +323,7 @@ const cardState = computed((): Record<string, CardStateValue> => {
v-else
class="mt-0.5 truncate text-xs leading-tight text-foreground/70"
>
- {{
- cardConnection[platform.value]?.display_name ||
- cardConnection[platform.value]?.username
- }}
+ {{ cardConnection[platform.value]?.display_label }}
</p>
</div>
diff --git a/resources/js/components/analytics/AnalyticsAccountSelector.vue b/resources/js/components/analytics/AnalyticsAccountSelector.vue
index ea72b3fa6..aa1125a95 100644
--- a/resources/js/components/analytics/AnalyticsAccountSelector.vue
+++ b/resources/js/components/analytics/AnalyticsAccountSelector.vue
@@ -14,6 +14,7 @@ import {
CommandList,
} from '@/components/ui/command';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
+import { getInitials } from '@/composables/useInitials';
import { getPlatformLabel, getPlatformLogo } from '@/composables/usePlatformLogo';
import type { AnalyticsAccount } from './types';
@@ -53,9 +54,9 @@ const select = (account: AnalyticsAccount) => {
<template v-if="selected">
<div class="relative shrink-0">
<Avatar class="size-7 rounded-full border-2 border-foreground shadow-2xs">
- <AvatarImage v-if="selected.avatar_url" :src="selected.avatar_url" :alt="selected.display_name" />
+ <AvatarImage v-if="selected.avatar_url" :src="selected.avatar_url" :alt="selected.display_label" />
<AvatarFallback class="rounded-full bg-violet-100 text-xs font-bold text-foreground">
- {{ selected.display_name?.charAt(0) }}
+ {{ getInitials(selected.display_label) }}
</AvatarFallback>
</Avatar>
<span class="absolute -bottom-1 -right-1 inline-flex size-4 items-center justify-center overflow-hidden rounded-full border-2 border-foreground bg-card shadow-2xs">
@@ -67,7 +68,7 @@ const select = (account: AnalyticsAccount) => {
</span>
</div>
<span class="min-w-0 flex-1 truncate">
- <span class="font-bold text-foreground">{{ selected.display_name }}</span>
+ <span class="font-bold text-foreground">{{ selected.display_label }}</span>
<span v-if="selected.username" class="ml-1.5 text-xs font-medium text-foreground/60">
@{{ selected.username }}
</span>
@@ -95,9 +96,9 @@ const select = (account: AnalyticsAccount) => {
>
<div class="relative shrink-0">
<Avatar class="size-9 rounded-full border-2 border-foreground shadow-2xs">
- <AvatarImage v-if="account.avatar_url" :src="account.avatar_url" :alt="account.display_name" />
+ <AvatarImage v-if="account.avatar_url" :src="account.avatar_url" :alt="account.display_label" />
<AvatarFallback class="rounded-full bg-violet-100 font-bold text-foreground">
- {{ account.display_name?.charAt(0) }}
+ {{ getInitials(account.display_label) }}
</AvatarFallback>
</Avatar>
<span class="absolute -bottom-1 -right-1 inline-flex size-5 items-center justify-center overflow-hidden rounded-full border-2 border-foreground bg-card shadow-2xs">
@@ -109,7 +110,7 @@ const select = (account: AnalyticsAccount) => {
</span>
</div>
<div class="min-w-0 flex-1">
- <p class="truncate font-bold text-foreground">{{ account.display_name }}</p>
+ <p class="truncate font-bold text-foreground">{{ account.display_label }}</p>
<p v-if="account.username" class="truncate text-xs font-medium text-foreground/60">
@{{ account.username }}
</p>
diff --git a/resources/js/components/analytics/types.ts b/resources/js/components/analytics/types.ts
index a4ce75dbb..0cf0bb822 100644
--- a/resources/js/components/analytics/types.ts
+++ b/resources/js/components/analytics/types.ts
@@ -1,7 +1,7 @@
export interface AnalyticsAccount {
id: string;
platform: string;
- display_name: string;
username: string | null;
+ display_label: string;
avatar_url: string | null;
}
diff --git a/resources/js/components/automations/config/GenerateNodeConfig.vue b/resources/js/components/automations/config/GenerateNodeConfig.vue
index 0f1abd6a7..b3311ed63 100644
--- a/resources/js/components/automations/config/GenerateNodeConfig.vue
+++ b/resources/js/components/automations/config/GenerateNodeConfig.vue
@@ -24,6 +24,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -302,7 +303,7 @@ const channels = computed<Channel[]>(() =>
return {
id: account.id,
platform: account.platform,
- displayName: account.display_name,
+ displayName: account.display_label,
username: account.username,
avatarUrl: account.avatar_url,
socialAccount: account,
diff --git a/resources/js/components/posts/create/AiPostWizard.vue b/resources/js/components/posts/create/AiPostWizard.vue
index 9c2dcfd8a..42e0209d9 100644
--- a/resources/js/components/posts/create/AiPostWizard.vue
+++ b/resources/js/components/posts/create/AiPostWizard.vue
@@ -24,6 +24,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -306,13 +307,13 @@ const startGeneration = async () => {
<img
v-if="account.avatar_url"
:src="account.avatar_url"
- :alt="account.display_name"
+ :alt="account.display_label"
class="size-full object-cover"
/>
<img v-else :src="getPlatformLogo(account.platform)" :alt="account.platform" class="size-4" />
</span>
<div class="min-w-0 flex-1">
- <p class="truncate text-xs font-bold leading-tight text-foreground">{{ account.display_name }}</p>
+ <p class="truncate text-xs font-bold leading-tight text-foreground">{{ account.display_label }}</p>
<p v-if="account.username" class="truncate text-xs font-medium text-foreground/60">@{{ account.username }}</p>
</div>
<IconCheck v-if="selectedAccountId === account.id" class="absolute right-2 top-2 size-3.5 text-foreground" stroke-width="3" />
diff --git a/resources/js/components/posts/editor/DiscordSettings.vue b/resources/js/components/posts/editor/DiscordSettings.vue
index 2393db83b..799c93a06 100644
--- a/resources/js/components/posts/editor/DiscordSettings.vue
+++ b/resources/js/components/posts/editor/DiscordSettings.vue
@@ -16,6 +16,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -194,7 +195,7 @@ const updateEmbed = (index: number, patch: Partial<EmbedDraft>) =>
<img :src="getPlatformLogo('discord')" alt="Discord" class="size-full object-cover" />
</span>
<span class="truncate font-bold text-foreground">{{ $t('posts.form.discord.settings') }}</span>
- <span v-if="socialAccount?.display_name" class="truncate font-medium text-foreground/60">·&nbsp;{{ socialAccount.display_name }}</span>
+ <span v-if="socialAccount?.display_label" class="truncate font-medium text-foreground/60">·&nbsp;{{ socialAccount.display_label }}</span>
</span>
<IconChevronUp v-if="open" class="size-4 shrink-0 text-foreground/60" />
<IconChevronDown v-else class="size-4 shrink-0 text-foreground/60" />
@@ -204,12 +205,12 @@ const updateEmbed = (index: number, patch: Partial<EmbedDraft>) =>
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.discord.posting_to') }}</p>
- <p class="truncate text-sm font-bold text-foreground">{{ socialAccount.display_name }}</p>
+ <p class="truncate text-sm font-bold text-foreground">{{ socialAccount.display_label }}</p>
</div>
</div>
diff --git a/resources/js/components/posts/editor/FacebookSettings.vue b/resources/js/components/posts/editor/FacebookSettings.vue
index 65d5ef215..9d76b8637 100644
--- a/resources/js/components/posts/editor/FacebookSettings.vue
+++ b/resources/js/components/posts/editor/FacebookSettings.vue
@@ -14,6 +14,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -103,13 +104,13 @@ const warning = computed(() => getMediaValidationWarning(props.contentType, prop
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.facebook.posting_to') }}</p>
<p class="truncate text-sm">
- <span class="font-bold text-foreground">{{ socialAccount.display_name }}</span>
+ <span class="font-bold text-foreground">{{ socialAccount.display_label }}</span>
<span v-if="socialAccount?.username" class="font-medium text-foreground/60">&nbsp;@{{ socialAccount.username }}</span>
</p>
</div>
diff --git a/resources/js/components/posts/editor/InstagramSettings.vue b/resources/js/components/posts/editor/InstagramSettings.vue
index 1c16b4975..a294eb948 100644
--- a/resources/js/components/posts/editor/InstagramSettings.vue
+++ b/resources/js/components/posts/editor/InstagramSettings.vue
@@ -14,6 +14,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -103,13 +104,13 @@ const warning = computed(() => getMediaValidationWarning(props.contentType, prop
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.instagram.posting_to') }}</p>
<p class="truncate text-sm">
- <span class="font-bold text-foreground">{{ socialAccount.display_name }}</span>
+ <span class="font-bold text-foreground">{{ socialAccount.display_label }}</span>
<span v-if="socialAccount?.username" class="font-medium text-foreground/60">&nbsp;@{{ socialAccount.username }}</span>
</p>
</div>
diff --git a/resources/js/components/posts/editor/LinkedInSettings.vue b/resources/js/components/posts/editor/LinkedInSettings.vue
index 7dae56f89..0885f1099 100644
--- a/resources/js/components/posts/editor/LinkedInSettings.vue
+++ b/resources/js/components/posts/editor/LinkedInSettings.vue
@@ -14,6 +14,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -77,13 +78,13 @@ const documentTitle = computed({
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.linkedin.posting_to') }}</p>
<p class="truncate text-sm">
- <span class="font-bold text-foreground">{{ socialAccount.display_name }}</span>
+ <span class="font-bold text-foreground">{{ socialAccount.display_label }}</span>
<span v-if="socialAccount?.username" class="font-medium text-foreground/60">&nbsp;@{{ socialAccount.username }}</span>
</p>
</div>
diff --git a/resources/js/components/posts/editor/PinterestSettings.vue b/resources/js/components/posts/editor/PinterestSettings.vue
index dfd8d8ce2..033408aac 100644
--- a/resources/js/components/posts/editor/PinterestSettings.vue
+++ b/resources/js/components/posts/editor/PinterestSettings.vue
@@ -28,6 +28,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -153,13 +154,13 @@ const linkError = computed<string | undefined>(() => {
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.pinterest.posting_to') }}</p>
<p class="truncate text-sm">
- <span class="font-bold text-foreground">{{ socialAccount.display_name }}</span>
+ <span class="font-bold text-foreground">{{ socialAccount.display_label }}</span>
<span v-if="socialAccount?.username" class="font-medium text-foreground/60">&nbsp;@{{ socialAccount.username }}</span>
</p>
</div>
diff --git a/resources/js/components/posts/editor/PostEditorTabs.vue b/resources/js/components/posts/editor/PostEditorTabs.vue
index 039dfbf83..3c4148ec6 100644
--- a/resources/js/components/posts/editor/PostEditorTabs.vue
+++ b/resources/js/components/posts/editor/PostEditorTabs.vue
@@ -13,6 +13,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
diff --git a/resources/js/components/posts/editor/PreviewTab.vue b/resources/js/components/posts/editor/PreviewTab.vue
index e28561ac2..4d78a418e 100644
--- a/resources/js/components/posts/editor/PreviewTab.vue
+++ b/resources/js/components/posts/editor/PreviewTab.vue
@@ -14,6 +14,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -36,7 +38,7 @@ const props = defineProps<{
}>();
const getPlatformAvatar = (pp: PostPlatform): string | null => pp.social_account?.avatar_url ?? pp.platform_avatar ?? null;
-const getPlatformDisplayName = (pp: PostPlatform): string => pp.social_account?.display_name ?? pp.platform_name ?? pp.platform;
+const getPlatformDisplayName = (pp: PostPlatform): string => pp.social_account?.display_label ?? pp.platform_name ?? pp.platform;
const activeId = ref<string | null>(props.platforms[0]?.id ?? null);
diff --git a/resources/js/components/posts/editor/ScheduleTab.vue b/resources/js/components/posts/editor/ScheduleTab.vue
index f05e90f54..e53b6be50 100644
--- a/resources/js/components/posts/editor/ScheduleTab.vue
+++ b/resources/js/components/posts/editor/ScheduleTab.vue
@@ -18,6 +18,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -110,7 +111,7 @@ const videoDurationSec = computed(() => {
});
const getPlatformDisplayName = (pp: PostPlatform): string =>
- pp.social_account?.display_name ?? pp.platform_name ?? pp.platform;
+ pp.social_account?.display_label ?? pp.platform_name ?? pp.platform;
const getPlatformAvatar = (pp: PostPlatform): string | null =>
pp.social_account?.avatar_url ?? pp.platform_avatar ?? null;
diff --git a/resources/js/components/posts/editor/TikTokSettings.vue b/resources/js/components/posts/editor/TikTokSettings.vue
index 68945b87b..d4e02a757 100644
--- a/resources/js/components/posts/editor/TikTokSettings.vue
+++ b/resources/js/components/posts/editor/TikTokSettings.vue
@@ -24,6 +24,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -258,13 +259,13 @@ watch(
<div v-if="socialAccount" class="flex items-center gap-3 rounded-lg bg-foreground/5 p-3">
<Avatar
:src="socialAccount.avatar_url"
- :name="socialAccount.display_name"
+ :name="socialAccount.display_label"
class="size-9 shrink-0 rounded-full border-2 border-foreground shadow-2xs"
/>
<div class="min-w-0 flex-1">
<p class="text-[11px] font-black uppercase tracking-widest text-foreground/60">{{ $t('posts.form.tiktok.posting_to') }}</p>
<p class="truncate text-sm">
- <span class="font-bold text-foreground">{{ socialAccount.display_name }}</span>
+ <span class="font-bold text-foreground">{{ socialAccount.display_label }}</span>
<span v-if="socialAccount?.username" class="font-medium text-foreground/60">&nbsp;@{{ socialAccount.username }}</span>
</p>
</div>
diff --git a/resources/js/components/posts/previews/BlueskyPreview.vue b/resources/js/components/posts/previews/BlueskyPreview.vue
index fb44a45ca..a47dead1a 100644
--- a/resources/js/components/posts/previews/BlueskyPreview.vue
+++ b/resources/js/components/posts/previews/BlueskyPreview.vue
@@ -3,6 +3,7 @@ import { computed, toRef } from 'vue';
import LinkCard from "@/components/posts/previews/LinkCard.vue";
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { useLinkCard } from '@/composables/useLinkCard';
import { isVideoMedia } from '@/composables/useMedia';
import date from '@/date';
@@ -13,6 +14,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -67,16 +69,16 @@ const { card: linkCard, loading: linkCardLoading } = useLinkCard(
<div class="flex items-start gap-3">
<!-- Avatar -->
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="h-11 w-11 rounded-full object-cover shrink-0" />
+ :alt="socialAccount.display_label" class="h-11 w-11 rounded-full object-cover shrink-0" />
<div v-else
class="h-11 w-11 rounded-full bg-gradient-to-br from-[#0085ff] to-[#00d4ff] flex items-center justify-center text-white font-semibold shrink-0">
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<!-- Name and handle -->
<div class="flex-1 min-w-0">
<div class="font-semibold text-[15px] text-black dark:text-white">
- {{ socialAccount.display_name }}
+ {{ socialAccount.display_label }}
</div>
<div class="text-[14px] text-neutral-500 dark:text-[#7b8d9e] truncate">
@{{ socialAccount.username || 'handle' }}.bsky.social
@@ -188,11 +190,11 @@ const { card: linkCard, loading: linkCardLoading } = useLinkCard(
<!-- Reply input -->
<div class="px-4 py-3 border-t border-neutral-200 dark:border-[#1e3a5f] flex items-center gap-3">
- <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="socialAccount.display_name"
+ <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="socialAccount.display_label"
class="h-8 w-8 rounded-full object-cover shrink-0" />
<div v-else
class="h-8 w-8 rounded-full bg-gradient-to-br from-[#0085ff] to-[#00d4ff] flex items-center justify-center text-white text-xs font-semibold shrink-0">
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="flex-1 text-[15px] text-neutral-400 dark:text-[#7b8d9e]">
Write your reply
diff --git a/resources/js/components/posts/previews/DiscordPreview.vue b/resources/js/components/posts/previews/DiscordPreview.vue
index 8bd842deb..d35575e37 100644
--- a/resources/js/components/posts/previews/DiscordPreview.vue
+++ b/resources/js/components/posts/previews/DiscordPreview.vue
@@ -3,6 +3,7 @@ import { trans } from 'laravel-vue-i18n';
import { computed } from 'vue';
import VideoPreview from '@/components/posts/previews/VideoPreview.vue';
+import { getInitials } from '@/composables/useInitials';
import { isVideoMedia } from '@/composables/useMedia';
import date from '@/date';
import type { MediaItem } from '@/types/media';
@@ -12,6 +13,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -58,19 +60,19 @@ const postedAtLabel = computed(() =>
<img
v-if="socialAccount.avatar_url"
:src="socialAccount.avatar_url"
- :alt="socialAccount.display_name"
+ :alt="socialAccount.display_label"
class="h-10 w-10 shrink-0 rounded-full object-cover"
/>
<div
v-else
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-[#5865F2] font-semibold text-white"
>
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="min-w-0 flex-1">
<div class="flex items-baseline gap-2">
- <span class="text-[15px] font-medium text-[#060607]">{{ socialAccount.display_name || 'TryPost' }}</span>
+ <span class="text-[15px] font-medium text-[#060607]">{{ socialAccount.display_label }}</span>
<span class="rounded bg-[#5865F2] px-1 text-[10px] font-bold uppercase tracking-wide text-white">Bot</span>
<span class="text-[11px] text-[#5c5e66]">{{ postedAtLabel }}</span>
</div>
diff --git a/resources/js/components/posts/previews/FacebookPreview.vue b/resources/js/components/posts/previews/FacebookPreview.vue
index faad3f2ef..a6ff12c77 100644
--- a/resources/js/components/posts/previews/FacebookPreview.vue
+++ b/resources/js/components/posts/previews/FacebookPreview.vue
@@ -4,6 +4,7 @@ import { trans } from 'laravel-vue-i18n';
import { computed } from 'vue';
import PostMediaPreview from '@/components/posts/previews/PostMediaPreview.vue';
+import { getInitials } from '@/composables/useInitials';
import date from '@/date';
import type { MediaItem } from '@/types/media';
@@ -12,6 +13,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -72,7 +74,6 @@ const truncatedContent = computed(() => {
return props.content.substring(0, 100) + '...';
});
-const displayName = computed(() => props.socialAccount.display_name || props.socialAccount.username);
</script>
<template>
@@ -114,14 +115,14 @@ const displayName = computed(() => props.socialAccount.display_name || props.soc
<!-- Post Header -->
<div class="flex-shrink-0 flex items-center px-3 py-2">
<div class="flex items-center gap-2 flex-1">
- <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="displayName"
+ <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="socialAccount.display_label"
class="w-10 h-10 rounded-full object-cover" />
<div v-else
class="w-10 h-10 rounded-full bg-[#1877f2] flex items-center justify-center text-white font-bold">
- {{ displayName?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="flex flex-col min-w-0">
- <span class="text-[13px] font-semibold leading-tight">{{ displayName }}</span>
+ <span class="text-[13px] font-semibold leading-tight">{{ socialAccount.display_label }}</span>
<div class="flex items-center gap-1 text-[11px] text-[#65676b] dark:text-[#b0b3b8]">
<span>{{ postedAtLabel }}</span>
<span>·</span>
@@ -291,7 +292,7 @@ const displayName = computed(() => props.socialAccount.display_name || props.soc
class="w-full h-full object-cover" />
<div v-else
class="w-full h-full bg-[#1877f2] flex items-center justify-center text-white font-bold text-xs">
- {{ displayName?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
</div>
@@ -303,9 +304,9 @@ const displayName = computed(() => props.socialAccount.display_name || props.soc
class="w-8 h-8 rounded-full object-cover border border-white/30" />
<div v-else
class="w-8 h-8 rounded-full bg-[#1877f2] flex items-center justify-center text-white font-bold text-[12px] border border-white/30">
- {{ displayName?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
- <span class="text-white text-[13px] font-semibold drop-shadow-lg">{{ displayName }}</span>
+ <span class="text-white text-[13px] font-semibold drop-shadow-lg">{{ socialAccount.display_label }}</span>
<button class="px-3 py-1 bg-[#1877f2] text-white text-[11px] font-semibold rounded-md">
Follow
</button>
@@ -388,10 +389,10 @@ const displayName = computed(() => props.socialAccount.display_name || props.soc
class="w-8 h-8 rounded-full object-cover border-2 border-black" />
<div v-else
class="w-8 h-8 rounded-full bg-[#1877f2] flex items-center justify-center text-white font-bold text-[11px] border-2 border-black">
- {{ displayName?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
- <span class="text-white text-[13px] font-semibold drop-shadow-lg">{{ displayName }}</span>
+ <span class="text-white text-[13px] font-semibold drop-shadow-lg">{{ socialAccount.display_label }}</span>
<span class="text-white/70 text-[11px] drop-shadow">2h</span>
</div>
<div class="flex items-center gap-3">
@@ -410,7 +411,7 @@ const displayName = computed(() => props.socialAccount.display_name || props.soc
<!-- Bottom Reply Bar -->
<div v-if="media.length > 0" class="absolute bottom-3 left-3 right-3 flex items-center gap-2 z-10">
<div class="flex-1 bg-white/20 backdrop-blur-md rounded-full px-4 py-2.5 border border-white/20">
- <span class="text-white/80 text-[13px]">Reply to {{ displayName }}...</span>
+ <span class="text-white/80 text-[13px]">Reply to {{ socialAccount.display_label }}...</span>
</div>
<svg class="w-7 h-7 text-white drop-shadow-lg" viewBox="0 0 24 24" fill="currentColor">
<path
diff --git a/resources/js/components/posts/previews/InstagramPreview.vue b/resources/js/components/posts/previews/InstagramPreview.vue
index 324a369a0..dfb42111a 100644
--- a/resources/js/components/posts/previews/InstagramPreview.vue
+++ b/resources/js/components/posts/previews/InstagramPreview.vue
@@ -15,6 +15,7 @@ import { computed } from 'vue';
import PostMediaPreview from '@/components/posts/previews/PostMediaPreview.vue';
import VerticalMediaCanvas from '@/components/posts/previews/VerticalMediaCanvas.vue';
+import { getInitials } from '@/composables/useInitials';
import { ContentType } from '@/types/content-type';
import type { MediaItem } from '@/types/media';
@@ -23,6 +24,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -84,8 +87,6 @@ const truncatedCaption = computed(() => {
if (props.content.length <= 80) return props.content;
return props.content.substring(0, 80) + '...';
});
-
-const username = computed(() => props.socialAccount.username || props.socialAccount.display_name);
</script>
<template>
@@ -111,15 +112,15 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
style="background: conic-gradient(from 180deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5, #feda75)">
<div class="p-[1.5px] bg-white dark:bg-black rounded-full">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="w-7 h-7 rounded-full object-cover" />
+ :alt="socialAccount.display_label" class="w-7 h-7 rounded-full object-cover" />
<div v-else
class="w-7 h-7 rounded-full bg-gradient-to-br from-[#833ab4] to-[#fd1d1d] flex items-center justify-center text-white font-semibold text-[10px]">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
</div>
<div class="flex flex-col min-w-0">
- <span class="text-[12px] font-semibold leading-tight truncate">{{ username }}</span>
+ <span class="text-[12px] font-semibold leading-tight truncate">{{ socialAccount.handle_label }}</span>
</div>
</div>
<IconDots class="w-4 h-4 flex-shrink-0" />
@@ -155,7 +156,7 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<!-- Caption -->
<div v-if="content" class="flex-shrink-0 px-2.5 py-0.5">
<p class="text-[12px] line-clamp-2">
- <span class="font-semibold">{{ username }}</span>
+ <span class="font-semibold">{{ socialAccount.handle_label }}</span>
<span class="ml-1">{{ content }}</span>
</p>
</div>
@@ -206,9 +207,9 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
class="w-7 h-7 rounded-full object-cover border border-white/30" />
<div v-else
class="w-7 h-7 rounded-full bg-gradient-to-br from-[#833ab4] to-[#fd1d1d] flex items-center justify-center text-white font-semibold text-[10px] border border-white/30">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
- <span class="text-white text-[12px] font-semibold drop-shadow-lg">{{ username }}</span>
+ <span class="text-white text-[12px] font-semibold drop-shadow-lg">{{ socialAccount.handle_label }}</span>
<button class="px-2 py-0.5 border border-white/70 rounded text-white text-[10px] font-semibold">
Follow
</button>
@@ -257,13 +258,13 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
class="w-7 h-7 rounded-full object-cover" />
<div v-else
class="w-7 h-7 rounded-full bg-gradient-to-br from-[#833ab4] to-[#fd1d1d] flex items-center justify-center text-white font-semibold text-[10px]">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
</div>
<span class="text-[12px] font-semibold"
:class="media.length > 0 ? 'text-white drop-shadow-lg' : 'text-[#262626] dark:text-white'">{{
- username
+ socialAccount.handle_label
}}</span>
<span class="text-[10px]"
:class="media.length > 0 ? 'text-white/70 drop-shadow' : 'text-[#737373] dark:text-white/70'">2h</span>
diff --git a/resources/js/components/posts/previews/LinkedInPreview.vue b/resources/js/components/posts/previews/LinkedInPreview.vue
index e42e0383c..066d7c9e3 100644
--- a/resources/js/components/posts/previews/LinkedInPreview.vue
+++ b/resources/js/components/posts/previews/LinkedInPreview.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { isDocumentMedia, isVideoMedia } from '@/composables/useMedia';
import type { MediaItem } from '@/types/media';
@@ -8,6 +9,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -30,16 +32,16 @@ defineProps<Props>();
<div class="flex items-start gap-3">
<div class="relative flex-shrink-0">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="h-12 w-12 rounded-full object-cover" />
+ :alt="socialAccount.display_label" class="h-12 w-12 rounded-full object-cover" />
<div v-else
class="h-12 w-12 rounded-full bg-[#0a66c2] flex items-center justify-center text-white font-semibold text-lg">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
<div class="flex-1 min-w-0">
<div class="flex items-center gap-1">
<p class="font-semibold text-[15px] text-[#000000e6] dark:text-[#ffffffe6]">
- {{ socialAccount.display_name }}
+ {{ socialAccount.display_label }}
</p>
<span class="text-[14px] text-[#00000099] dark:text-[#ffffff99]">• 1st</span>
</div>
@@ -123,11 +125,11 @@ defineProps<Props>();
<!-- Comment Input -->
<div class="px-2 py-4 flex items-center gap-2">
- <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="socialAccount.display_name"
+ <img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url" :alt="socialAccount.display_label"
class="h-8 w-8 rounded-full object-cover shrink-0" />
<div v-else
class="h-8 w-8 rounded-full bg-[#0a66c2] flex items-center justify-center text-white font-semibold text-sm shrink-0">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="flex-1 bg-[#f4f2ee] dark:bg-[#38434f] rounded-full px-4 py-2">
<span class="text-[14px] text-[#00000099] dark:text-[#ffffff99]">Leave your thoughts...</span>
diff --git a/resources/js/components/posts/previews/MastodonPreview.vue b/resources/js/components/posts/previews/MastodonPreview.vue
index 494e768bb..f038fa80a 100644
--- a/resources/js/components/posts/previews/MastodonPreview.vue
+++ b/resources/js/components/posts/previews/MastodonPreview.vue
@@ -2,6 +2,7 @@
import { computed } from 'vue';
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { isVideoMedia } from '@/composables/useMedia';
import date from '@/date';
import type { MediaItem } from '@/types/media';
@@ -11,6 +12,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -36,14 +38,14 @@ const postedAtLabel = computed(() => date.formatMastodonPreview(props.postedAt))
<!-- Author -->
<div class="flex items-center gap-3 mb-3">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="h-10 w-10 rounded-full object-cover" />
+ :alt="socialAccount.display_label" class="h-10 w-10 rounded-full object-cover" />
<div v-else
class="h-10 w-10 rounded-full bg-gradient-to-br from-[#6364ff] to-[#563acc] flex items-center justify-center text-white font-semibold">
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="flex-1 min-w-0">
<div class="font-bold text-[15px]">
- {{ socialAccount.display_name }}
+ {{ socialAccount.display_label }}
</div>
<div class="text-[14px] text-[#606984] dark:text-[#9baec8] truncate">
@{{ socialAccount.username || 'user' }}@mastodon.social
diff --git a/resources/js/components/posts/previews/PinterestPreview.vue b/resources/js/components/posts/previews/PinterestPreview.vue
index 230d7068d..93b307a3a 100644
--- a/resources/js/components/posts/previews/PinterestPreview.vue
+++ b/resources/js/components/posts/previews/PinterestPreview.vue
@@ -3,6 +3,7 @@ import { IconPhoto, IconStack2 } from '@tabler/icons-vue';
import { computed } from 'vue';
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { isVideoMedia } from '@/composables/useMedia';
import type { MediaItem } from '@/types/media';
@@ -11,6 +12,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -145,14 +147,14 @@ const pinLink = computed(() => (props.meta?.link as string | undefined) || '');
<img
v-if="socialAccount.avatar_url"
:src="socialAccount.avatar_url"
- :alt="socialAccount.display_name"
+ :alt="socialAccount.display_label"
class="h-6 w-6 rounded-full object-cover"
/>
<div v-else class="h-6 w-6 rounded-full bg-[#e60023] flex items-center justify-center text-white font-semibold text-[10px]">
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<span class="text-[12px] font-medium text-[#111111] dark:text-[#e0e0e0] truncate">
- {{ socialAccount.display_name }}
+ {{ socialAccount.display_label }}
</span>
</div>
</div>
diff --git a/resources/js/components/posts/previews/PlatformPreview.vue b/resources/js/components/posts/previews/PlatformPreview.vue
index 4d0d1d281..baf6a15b3 100644
--- a/resources/js/components/posts/previews/PlatformPreview.vue
+++ b/resources/js/components/posts/previews/PlatformPreview.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue';
+import { getPlatformLabel } from '@/composables/usePlatformLogo';
import type { MediaItem } from '@/types/media';
import BlueskyPreview from './BlueskyPreview.vue';
@@ -21,6 +22,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -42,6 +45,8 @@ const resolvedSocialAccount = computed((): SocialAccount => props.socialAccount
platform: props.platform,
display_name: '',
username: '',
+ display_label: getPlatformLabel(props.platform),
+ handle_label: getPlatformLabel(props.platform),
avatar_url: null,
});
diff --git a/resources/js/components/posts/previews/TelegramPreview.vue b/resources/js/components/posts/previews/TelegramPreview.vue
index 533f71eb4..a375ae566 100644
--- a/resources/js/components/posts/previews/TelegramPreview.vue
+++ b/resources/js/components/posts/previews/TelegramPreview.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import VideoPreview from '@/components/posts/previews/VideoPreview.vue';
+import { getInitials } from '@/composables/useInitials';
import { isVideoMedia } from '@/composables/useMedia';
import type { MediaItem } from '@/types/media';
@@ -8,6 +9,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -38,20 +40,20 @@ const sampleReactions = [
<img
v-if="socialAccount.avatar_url"
:src="socialAccount.avatar_url"
- :alt="socialAccount.display_name"
+ :alt="socialAccount.display_label"
class="h-9 w-9 rounded-full object-cover"
/>
<div
v-else
class="flex h-9 w-9 items-center justify-center rounded-full bg-gradient-to-br from-[#2aabee] to-[#229ed9] font-semibold text-white"
>
- {{ socialAccount.display_name?.charAt(0) }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<div class="min-w-0 flex-1">
<div
class="truncate text-[15px] font-semibold text-[#1f232b] dark:text-white"
>
- {{ socialAccount.display_name || 'Channel' }}
+ {{ socialAccount.display_label }}
</div>
<div class="text-[13px] text-[#707991] dark:text-[#708499]">
channel
diff --git a/resources/js/components/posts/previews/ThreadsPreview.vue b/resources/js/components/posts/previews/ThreadsPreview.vue
index 72977c587..d1b9255fa 100644
--- a/resources/js/components/posts/previews/ThreadsPreview.vue
+++ b/resources/js/components/posts/previews/ThreadsPreview.vue
@@ -1,8 +1,9 @@
<script setup lang="ts">
-import { computed, toRef } from 'vue';
+import { toRef } from 'vue';
import LinkCard from "@/components/posts/previews/LinkCard.vue";
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { useLinkCard } from '@/composables/useLinkCard';
import { isVideoMedia } from '@/composables/useMedia';
import type { MediaItem } from '@/types/media';
@@ -12,6 +13,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -23,8 +26,6 @@ interface Props {
const props = defineProps<Props>();
-const username = computed(() => props.socialAccount.username || props.socialAccount.display_name);
-
const { card: linkCard, loading: linkCardLoading } = useLinkCard(
toRef(props, 'content'),
toRef(props, 'media'),
@@ -69,17 +70,17 @@ const { card: linkCard, loading: linkCardLoading } = useLinkCard(
<!-- Avatar -->
<div class="w-9 h-9 rounded-full overflow-hidden flex-shrink-0">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="w-full h-full object-cover" />
+ :alt="socialAccount.display_label" class="w-full h-full object-cover" />
<div v-else
class="w-full h-full bg-gradient-to-br from-[#833ab4] via-[#fd1d1d] to-[#fcb045] flex items-center justify-center text-white font-bold text-sm">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
<!-- Name + verified -->
<div class="flex items-center gap-1 min-w-0">
<span class="font-semibold text-[15px] text-[#000000] dark:text-[#f5f5f5] truncate">
- {{ username }}
+ {{ socialAccount.handle_label }}
</span>
<!-- Verified badge -->
<svg class="h-3.5 w-3.5 text-[#0095f6] flex-shrink-0" viewBox="0 0 40 40" fill="currentColor">
diff --git a/resources/js/components/posts/previews/TikTokPreview.vue b/resources/js/components/posts/previews/TikTokPreview.vue
index c8c70d7e2..0b5007510 100644
--- a/resources/js/components/posts/previews/TikTokPreview.vue
+++ b/resources/js/components/posts/previews/TikTokPreview.vue
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { IconPlus } from '@tabler/icons-vue';
-import { computed } from 'vue';
import VerticalMediaCanvas from '@/components/posts/previews/VerticalMediaCanvas.vue';
+import { getInitials } from '@/composables/useInitials';
import type { MediaItem } from '@/types/media';
interface SocialAccount {
@@ -10,6 +10,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -19,7 +21,7 @@ interface Props {
media: MediaItem[];
}
-const props = defineProps<Props>();
+defineProps<Props>();
// Format engagement numbers like TikTok does
const formatNumber = (num: number): string => {
@@ -31,8 +33,6 @@ const formatNumber = (num: number): string => {
}
return num.toString();
};
-
-const username = computed(() => props.socialAccount.username || props.socialAccount.display_name);
</script>
<template>
@@ -90,10 +90,10 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<div class="relative mb-1">
<div class="w-11 h-11 rounded-full border-[1.5px] border-white overflow-hidden">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="w-full h-full object-cover" />
+ :alt="socialAccount.display_label" class="w-full h-full object-cover" />
<div v-else
class="w-full h-full bg-[#2f2f2f] flex items-center justify-center text-white font-bold text-sm">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
<div
@@ -150,7 +150,7 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<!-- Bottom info -->
<div v-if="media.length > 0" class="absolute left-3 right-14 bottom-[72px] text-white z-10">
<!-- Username -->
- <p class="font-bold text-[14px] drop-shadow-lg mb-1">@{{ username }}</p>
+ <p class="font-bold text-[14px] drop-shadow-lg mb-1">@{{ socialAccount.handle_label }}</p>
<!-- Caption -->
<div v-if="content" class="text-[13px] text-white drop-shadow-lg line-clamp-2 leading-[18px] mb-2">
@@ -165,7 +165,7 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<div class="flex items-center overflow-hidden">
<p class="text-[12px] whitespace-nowrap">
<span class="inline-flex animate-marquee">
- Original sound - {{ socialAccount.display_name }} &nbsp;&nbsp;&nbsp;
+ Original sound - {{ socialAccount.display_label }} &nbsp;&nbsp;&nbsp;
</span>
</p>
</div>
diff --git a/resources/js/components/posts/previews/XPreview.vue b/resources/js/components/posts/previews/XPreview.vue
index b213beb30..ccc4d23aa 100644
--- a/resources/js/components/posts/previews/XPreview.vue
+++ b/resources/js/components/posts/previews/XPreview.vue
@@ -3,6 +3,7 @@ import { computed, toRef } from 'vue';
import LinkCard from "@/components/posts/previews/LinkCard.vue";
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { useLinkCard } from '@/composables/useLinkCard';
import { isVideoMedia } from '@/composables/useMedia';
import date from '@/date';
@@ -13,6 +14,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -65,17 +67,17 @@ const { card: linkCard, loading: linkCardLoading } = useLinkCard(
<div class="flex items-center gap-2.5">
<!-- Avatar -->
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="h-10 w-10 rounded-full object-cover flex-shrink-0" />
+ :alt="socialAccount.display_label" class="h-10 w-10 rounded-full object-cover flex-shrink-0" />
<div v-else
class="h-10 w-10 rounded-full bg-[#1d9bf0] flex items-center justify-center text-white font-bold flex-shrink-0">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
<!-- Name + Username column -->
<div class="flex-1 min-w-0">
<div class="flex items-center gap-1">
<span class="font-bold text-[15px] text-[#0f1419] dark:text-[#e7e9ea] truncate">
- {{ socialAccount.display_name }}
+ {{ socialAccount.display_label }}
</span>
<!-- Verified Badge -->
<svg class="h-[18px] w-[18px] text-[#1d9bf0] flex-shrink-0" viewBox="0 0 22 22"
diff --git a/resources/js/components/posts/previews/YouTubePreview.vue b/resources/js/components/posts/previews/YouTubePreview.vue
index 9882b3b24..17ed90070 100644
--- a/resources/js/components/posts/previews/YouTubePreview.vue
+++ b/resources/js/components/posts/previews/YouTubePreview.vue
@@ -1,7 +1,6 @@
<script setup lang="ts">
-import { computed } from 'vue';
-
import VideoPreview from "@/components/posts/previews/VideoPreview.vue";
+import { getInitials } from '@/composables/useInitials';
import { isVideoMedia } from '@/composables/useMedia';
import type { MediaItem } from '@/types/media';
@@ -10,6 +9,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
@@ -19,7 +20,7 @@ interface Props {
media: MediaItem[];
}
-const props = defineProps<Props>();
+defineProps<Props>();
// Format engagement numbers like YouTube does
const formatNumber = (num: number): string => {
@@ -31,8 +32,6 @@ const formatNumber = (num: number): string => {
}
return num.toString();
};
-
-const username = computed(() => props.socialAccount.username || props.socialAccount.display_name);
</script>
<template>
@@ -152,13 +151,13 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<div class="flex items-center gap-2 mb-2">
<div class="w-8 h-8 rounded-full overflow-hidden flex-shrink-0">
<img v-if="socialAccount.avatar_url" :src="socialAccount.avatar_url"
- :alt="socialAccount.display_name" class="w-full h-full object-cover" />
+ :alt="socialAccount.display_label" class="w-full h-full object-cover" />
<div v-else
class="w-full h-full bg-[#ff0000] flex items-center justify-center text-white font-bold text-[10px]">
- {{ socialAccount.display_name?.charAt(0).toUpperCase() }}
+ {{ getInitials(socialAccount.display_label) }}
</div>
</div>
- <span class="text-[13px] font-medium">@{{ username }}</span>
+ <span class="text-[13px] font-medium">@{{ socialAccount.handle_label }}</span>
<button class="ml-auto bg-white text-black text-[12px] font-medium px-3 py-1 rounded-full">
Subscribe
</button>
@@ -174,7 +173,7 @@ const username = computed(() => props.socialAccount.username || props.socialAcco
<svg class="w-3 h-3 shrink-0" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z" />
</svg>
- <span class="text-[11px] text-white/80 truncate">{{ socialAccount.display_name }} - Original
+ <span class="text-[11px] text-white/80 truncate">{{ socialAccount.display_label }} - Original
audio</span>
</div>
</div>
diff --git a/resources/js/pages/posts/Calendar.vue b/resources/js/pages/posts/Calendar.vue
index dfda42f4a..00682767b 100644
--- a/resources/js/pages/posts/Calendar.vue
+++ b/resources/js/pages/posts/Calendar.vue
@@ -25,7 +25,8 @@ interface PostPlatform {
platform: string;
display_name: string;
username: string | null;
- };
+ display_label: string;
+ } | null;
}
interface Post {
@@ -348,7 +349,7 @@ const formatTime = (scheduledAt: string): string => {
</TooltipTrigger>
<TooltipContent>
<div class="space-y-0.5 text-xs">
- <p class="font-semibold">{{ pp.social_account?.display_name ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
+ <p class="font-semibold">{{ pp.social_account?.display_label ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
<p class="opacity-70">{{ getPlatformLabel(pp.platform) }}</p>
</div>
</TooltipContent>
@@ -433,7 +434,7 @@ const formatTime = (scheduledAt: string): string => {
</TooltipTrigger>
<TooltipContent>
<div class="space-y-0.5 text-xs">
- <p class="font-semibold">{{ pp.social_account?.display_name ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
+ <p class="font-semibold">{{ pp.social_account?.display_label ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
<p class="opacity-70">{{ getPlatformLabel(pp.platform) }}</p>
</div>
</TooltipContent>
@@ -533,7 +534,7 @@ const formatTime = (scheduledAt: string): string => {
</TooltipTrigger>
<TooltipContent>
<div class="space-y-0.5 text-xs">
- <p class="font-semibold">{{ pp.social_account?.display_name ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
+ <p class="font-semibold">{{ pp.social_account?.display_label ?? pp.platform }}<span v-if="pp.social_account?.username" class="font-normal opacity-80">&nbsp;·&nbsp;@{{ pp.social_account.username }}</span></p>
<p class="opacity-70">{{ getPlatformLabel(pp.platform) }}</p>
</div>
</TooltipContent>
diff --git a/resources/js/pages/posts/Create.vue b/resources/js/pages/posts/Create.vue
index be61608ad..8368da42d 100644
--- a/resources/js/pages/posts/Create.vue
+++ b/resources/js/pages/posts/Create.vue
@@ -15,6 +15,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
diff --git a/resources/js/pages/posts/Edit.vue b/resources/js/pages/posts/Edit.vue
index 82dd5fa20..c9b0218bc 100644
--- a/resources/js/pages/posts/Edit.vue
+++ b/resources/js/pages/posts/Edit.vue
@@ -33,6 +33,8 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
+ handle_label: string;
avatar_url: string | null;
}
diff --git a/resources/js/pages/posts/Index.vue b/resources/js/pages/posts/Index.vue
index 12fb109b9..d94e8caea 100644
--- a/resources/js/pages/posts/Index.vue
+++ b/resources/js/pages/posts/Index.vue
@@ -44,6 +44,7 @@ interface SocialAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
@@ -53,7 +54,7 @@ interface PostPlatform {
enabled: boolean;
platform: string;
status: string;
- social_account: SocialAccount;
+ social_account: SocialAccount | null;
}
interface Label {
@@ -249,7 +250,7 @@ useWorkspaceEcho(
<TooltipContent>
<div class="space-y-0.5 text-xs">
<p class="font-semibold">
- {{ pp.social_account?.display_name ?? pp.platform }}<span
+ {{ pp.social_account?.display_label ?? pp.platform }}<span
v-if="pp.social_account?.username"
class="font-normal opacity-80"
>&nbsp;·&nbsp;@{{ pp.social_account.username }}</span>
diff --git a/resources/js/types/channel.ts b/resources/js/types/channel.ts
index 81565fff7..8bbed59ed 100644
--- a/resources/js/types/channel.ts
+++ b/resources/js/types/channel.ts
@@ -5,6 +5,7 @@ export interface ChannelAccount {
platform: string;
display_name: string;
username: string;
+ display_label: string;
avatar_url: string | null;
}
diff --git a/resources/views/mail/account-disconnected.blade.php b/resources/views/mail/account-disconnected.blade.php
index 46e7b46c1..7b5ad9b11 100644
--- a/resources/views/mail/account-disconnected.blade.php
+++ b/resources/views/mail/account-disconnected.blade.php
@@ -105,13 +105,43 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
<p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
</a>
</p>
- @endif
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
</td>
</tr>
</table>
diff --git a/resources/views/mail/email-verification.blade.php b/resources/views/mail/email-verification.blade.php
index 5f9d0cfd8..f7a9b62c7 100644
--- a/resources/views/mail/email-verification.blade.php
+++ b/resources/views/mail/email-verification.blade.php
@@ -26,9 +26,6 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" media="screen">
<style>
- .hover-i-text-decoration-underline:hover {
- text-decoration: underline !important
- }
@media (max-width: 600px) {
.sm-my-8 {
margin-top: 32px !important;
@@ -100,13 +97,38 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
- <p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
- </a>
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 12px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
</p>
- @endif
</td>
</tr>
</table>
diff --git a/resources/views/mail/mentioned-in-comment.blade.php b/resources/views/mail/mentioned-in-comment.blade.php
index 83f5e349f..0e3ac9e92 100644
--- a/resources/views/mail/mentioned-in-comment.blade.php
+++ b/resources/views/mail/mentioned-in-comment.blade.php
@@ -97,13 +97,43 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
<p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
</a>
</p>
- @endif
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
</td>
</tr>
</table>
diff --git a/resources/views/mail/password-reset.blade.php b/resources/views/mail/password-reset.blade.php
index 4901dab40..23b95768e 100644
--- a/resources/views/mail/password-reset.blade.php
+++ b/resources/views/mail/password-reset.blade.php
@@ -26,9 +26,6 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" media="screen">
<style>
- .hover-i-text-decoration-underline:hover {
- text-decoration: underline !important
- }
@media (max-width: 600px) {
.sm-my-8 {
margin-top: 32px !important;
@@ -100,13 +97,38 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
- <p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
- </a>
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 12px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
</p>
- @endif
</td>
</tr>
</table>
diff --git a/resources/views/mail/post-at-risk.blade.php b/resources/views/mail/post-at-risk.blade.php
new file mode 100644
index 000000000..4a0c6f010
--- /dev/null
+++ b/resources/views/mail/post-at-risk.blade.php
@@ -0,0 +1,161 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:v="urn:schemas-microsoft-com:vml">
+<head>
+ <meta charset="utf-8">
+ <meta name="x-apple-disable-message-reformatting">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="format-detection" content="telephone=no, date=no, address=no, email=no, url=no">
+ <meta name="color-scheme" content="light">
+ <meta name="supported-color-schemes" content="light">
+ <!--[if mso]>
+ <noscript>
+ <xml>
+ <o:OfficeDocumentSettings xmlns:o="urn:schemas-microsoft-com:office:office">
+ <o:PixelsPerInch>96</o:PixelsPerInch>
+ </o:OfficeDocumentSettings>
+ </xml>
+ </noscript>
+ <style>
+ td,th,div,p,a,h1,h2,h3,h4,h5,h6 {font-family: "Segoe UI", sans-serif; mso-line-height-rule: exactly;}
+ </style>
+ <![endif]-->
+ @if(isset($title))
+ <title>{{ $title }}</title>
+ @endif
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" media="screen">
+ <style>
+ .hover-i-text-decoration-underline:hover {
+ text-decoration: underline !important
+ }
+ @media (max-width: 600px) {
+ .sm-my-8 {
+ margin-top: 32px !important;
+ margin-bottom: 32px !important
+ }
+ .sm-px-4 {
+ padding-left: 16px !important;
+ padding-right: 16px !important
+ }
+ .sm-px-6 {
+ padding-left: 24px !important;
+ padding-right: 24px !important
+ }
+ .sm-leading-8 {
+ line-height: 32px !important
+ }
+ }
+ </style>
+</head>
+<body style="margin: 0; width: 100%; padding: 0; -webkit-font-smoothing: antialiased; word-break: break-word">
+ @if(isset($previewText))
+ <div style="display: none">
+ {{ $previewText }}
+ &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847; &#8199;&#65279;&#847;
+ </div>
+ @endif
+ <div role="article" aria-roledescription="email" aria-label="{{ $title }}" lang="en">
+ <div class="sm-px-4" style="background-color: #fafafa; font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif">
+ <table align="center" cellpadding="0" cellspacing="0" role="none">
+ <tr>
+ <td style="width: 552px; max-width: 100%">
+ <div class="sm-my-8" style="margin-top: 48px; margin-bottom: 48px; text-align: center">
+ <a href="https://trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/logo-header.png') }}" width="160" alt="Trypost" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </div>
+ <table style="width: 100%" cellpadding="0" cellspacing="0" role="none">
+ <tr>
+ <td class="sm-px-6" style="border-radius: 4px; background-color: #fffffe; padding: 48px; font-size: 16px; color: #3f3f46; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05)">
+ <h1 class="sm-leading-8" style="margin: 0 0 24px; font-size: 24px; font-weight: 600; color: #000001">
+ {{ $title }}
+ </h1>
+ <p style="margin: 0; line-height: 24px">
+ {{ $intro }}
+ </p>
+ <table style="border-collapse: collapse; margin-top: 16px; width: 100%" cellpadding="0" cellspacing="0" role="none">
+ @foreach($atRiskGroups as $group)
+ <tr>
+ <td style="border-bottom: 1px solid #e4e4e7; padding-top: 12px; padding-bottom: 12px">
+ <div style="display: flex; align-items: center">
+ <div style="width: 8px; height: 8px; border-radius: 50%; background-color: {{ $group['account']->platform->color() }}; margin-right: 12px"></div>
+ <div>
+ <strong style="color: #18181b">{{ $group['account']->platform->label() }}</strong>
+ <span style="color: #71717a"> - {{ $group['account']->accountDisplayName() }}</span>
+ <div style="font-size: 14px; margin-top: 4px; color: #71717a">
+ {{ $group['postsLabel'] }}
+ </div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ @endforeach
+ </table>
+ <p style="margin: 16px 0 0; line-height: 24px">
+ {{ $reconnectCta }}
+ </p>
+ <div role="separator" style="line-height: 24px">&zwj;</div>
+ <div style="display: flex; align-items: center; justify-content: center">
+ <div>
+ <a href="{{ $url }}" style="display: inline-block; text-decoration: none; padding: 16px 24px; font-size: 16px; line-height: 1; border-radius: 8px; background-color: #262626; color: #ffffff">
+ <!--[if mso]><i style="mso-font-width: 150%; mso-text-raise: 31px" hidden>&emsp;</i><![endif]-->
+ <span style="mso-text-raise: 16px">{{ $buttonText }} &rarr;</span>
+ <!--[if mso]><i hidden style="mso-font-width: 150%">&emsp;&#8203;</i><![endif]-->
+ </a>
+ </div>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td align="center" style="padding: 24px; text-align: center; font-size: 12px; color: #52525b">
+ <p style="margin: 0 0 8px">
+ Open-source social media scheduling tool
+ </p>
+ <p style="margin: 8px 0 0">
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
+ </a>
+ </p>
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/resources/views/mail/post-publish-failed.blade.php b/resources/views/mail/post-publish-failed.blade.php
index 4c0fb4cf1..477aab6df 100644
--- a/resources/views/mail/post-publish-failed.blade.php
+++ b/resources/views/mail/post-publish-failed.blade.php
@@ -109,13 +109,43 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
<p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
</a>
</p>
- @endif
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
</td>
</tr>
</table>
diff --git a/resources/views/mail/post-published.blade.php b/resources/views/mail/post-published.blade.php
index ac81616b5..11bb0bc6d 100644
--- a/resources/views/mail/post-published.blade.php
+++ b/resources/views/mail/post-published.blade.php
@@ -109,13 +109,43 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
<p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
</a>
</p>
- @endif
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
</td>
</tr>
</table>
diff --git a/resources/views/mail/workspace-connections-disconnected.blade.php b/resources/views/mail/workspace-connections-disconnected.blade.php
index db5182211..0cb5d7ee1 100644
--- a/resources/views/mail/workspace-connections-disconnected.blade.php
+++ b/resources/views/mail/workspace-connections-disconnected.blade.php
@@ -82,9 +82,7 @@
<div style="width: 8px; height: 8px; border-radius: 50%; background-color: {{ $account->platform->color() }}; margin-right: 12px"></div>
<div>
<strong style="color: #18181b">{{ $account->platform->label() }}</strong>
- @if($account->display_name || $account->username)
- <span style="color: #71717a"> - {{ $account->display_name ?? $account->username }}</span>
- @endif
+ <span style="color: #71717a"> - {{ $account->accountDisplayName() }}</span>
</div>
</div>
</td>
@@ -122,13 +120,43 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
<p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
+ <a href="{{ route('app.notifications.preferences') }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
+ Manage notifications
</a>
</p>
- @endif
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 16px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
+ </p>
</td>
</tr>
</table>
diff --git a/resources/views/mail/workspace-invite.blade.php b/resources/views/mail/workspace-invite.blade.php
index 4e2192b17..84c3b97f9 100644
--- a/resources/views/mail/workspace-invite.blade.php
+++ b/resources/views/mail/workspace-invite.blade.php
@@ -26,9 +26,6 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet" media="screen">
<style>
- .hover-i-text-decoration-underline:hover {
- text-decoration: underline !important
- }
@media (max-width: 600px) {
.sm-my-8 {
margin-top: 32px !important;
@@ -101,13 +98,38 @@
<p style="margin: 0 0 8px">
Open-source social media scheduling tool
</p>
- @if(isset($unsubscribe_url))
- <p style="margin: 8px 0 0">
- <a href="{{ unsubscribe_url }}" target="_blank" class="hover-i-text-decoration-underline" style="color: #52525b; text-decoration: none">
- Unsubscribe
- </a>
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto; margin-top: 12px">
+ <tr>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://github.com/trypostit/trypost" target="_blank">
+ <img src="{{ asset('/images/emails/social/github.png') }}" width="20" height="20" alt="GitHub" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://x.com/trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/x.png') }}" width="20" height="20" alt="X" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.youtube.com/@trypostit" target="_blank">
+ <img src="{{ asset('/images/emails/social/youtube.png') }}" width="20" height="20" alt="YouTube" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://trypost.it/discord" target="_blank">
+ <img src="{{ asset('/images/emails/social/discord.png') }}" width="20" height="20" alt="Discord" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ <td style="padding-left: 4px; padding-right: 4px">
+ <a href="https://www.instagram.com/trypost.it" target="_blank">
+ <img src="{{ asset('/images/emails/social/instagram.png') }}" width="20" height="20" alt="Instagram" style="max-width: 100%; vertical-align: middle">
+ </a>
+ </td>
+ </tr>
+ </table>
+ <p style="margin: 12px 0 0">
+ &copy; {{ date('Y') }} TryPost.it
</p>
- @endif
</td>
</tr>
</table>
diff --git a/routes/console.php b/routes/console.php
index dd2b3ef6f..28d1ca1d2 100644
--- a/routes/console.php
+++ b/routes/console.php
@@ -7,6 +7,7 @@ use App\Console\Commands\Automation\ProcessAutomationDelays;
use App\Console\Commands\Automation\PruneDryRunAutomationRuns;
use App\Console\Commands\Automation\RecoverStuckAutomationRuns;
use App\Console\Commands\CheckSocialConnections;
+use App\Console\Commands\CheckUpcomingPostConnections;
use App\Console\Commands\ProcessScheduledPosts;
use App\Console\Commands\RecoverStuckPosts;
use App\Console\Commands\RefreshExpiringTokens;
@@ -14,6 +15,7 @@ use Illuminate\Support\Facades\Schedule;
Schedule::command(ProcessScheduledPosts::class)->everyMinute()->withoutOverlapping()->onOneServer();
Schedule::command(CheckSocialConnections::class)->daily()->withoutOverlapping()->onOneServer();
+Schedule::command(CheckUpcomingPostConnections::class)->everyFifteenMinutes()->withoutOverlapping()->onOneServer();
Schedule::command(RefreshExpiringTokens::class)->everyFifteenMinutes()->withoutOverlapping()->onOneServer();
Schedule::command(RecoverStuckPosts::class)->everyThirtyMinutes()->withoutOverlapping()->onOneServer();
Schedule::command(FireScheduleTriggers::class)->everyMinute()->withoutOverlapping()->onOneServer();
diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php
index b81ce1ae0..a5eedf698 100644
--- a/tests/Feature/Auth/EmailVerificationTest.php
+++ b/tests/Feature/Auth/EmailVerificationTest.php
@@ -95,3 +95,16 @@ test('already verified user visiting verification link is redirected without fir
Event::assertNotDispatched(Verified::class);
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
});
+
+test('verification email has no manage-notifications link — it is a transactional, unauthenticated email', function () {
+ $user = User::factory()->unverified()->create();
+
+ $html = view('mail.email-verification', [
+ 'title' => 'Verify your email address',
+ 'previewText' => 'Please verify your email address.',
+ 'user' => $user,
+ 'url' => 'https://example.com/verify',
+ ])->render();
+
+ expect($html)->not->toContain('Manage notifications');
+});
diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php
index 89d170ff4..0e10786fd 100644
--- a/tests/Feature/Auth/PasswordResetTest.php
+++ b/tests/Feature/Auth/PasswordResetTest.php
@@ -38,6 +38,19 @@ test('reset password screen can be rendered', function () {
});
});
+test('reset password email has no manage-notifications link — it is a transactional, unauthenticated email', function () {
+ $user = User::factory()->create();
+
+ $html = view('mail.password-reset', [
+ 'title' => 'Reset your password',
+ 'previewText' => 'Reset your password.',
+ 'user' => $user,
+ 'url' => 'https://example.com/reset',
+ ])->render();
+
+ expect($html)->not->toContain('Manage notifications');
+});
+
test('password can be reset with valid token', function () {
Notification::fake();
diff --git a/tests/Feature/Commands/CheckUpcomingPostConnectionsTest.php b/tests/Feature/Commands/CheckUpcomingPostConnectionsTest.php
new file mode 100644
index 000000000..932af396f
--- /dev/null
+++ b/tests/Feature/Commands/CheckUpcomingPostConnectionsTest.php
@@ -0,0 +1,187 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\PostPlatform\Status as PostPlatformStatus;
+use App\Jobs\VerifyUpcomingPostConnections;
+use App\Models\Post;
+use App\Models\PostPlatform;
+use App\Models\SocialAccount;
+use App\Models\Workspace;
+use Illuminate\Support\Facades\Event;
+use Illuminate\Support\Facades\Queue;
+
+test('dispatches the job once per workspace with at-risk posts, even with multiple posts', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->facebook()->create(['workspace_id' => $workspace->id]);
+
+ foreach (range(1, 5) as $i) {
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(10 * $i),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+ }
+
+ $this->artisan('social:check-upcoming-connections')
+ ->expectsOutput('Dispatched 1 upcoming-post connection checks.')
+ ->assertSuccessful();
+
+ Queue::assertPushed(VerifyUpcomingPostConnections::class, fn ($job) => $job->workspaceId === $workspace->id);
+});
+
+test('dispatches nothing when no workspace has posts in the window', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addHours(5),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $this->artisan('social:check-upcoming-connections')->assertSuccessful();
+
+ Queue::assertNothingPushed();
+});
+
+test('dispatches nothing when the only at-risk post_platform was already warned today', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => now()->subHours(2),
+ ]);
+
+ $this->artisan('social:check-upcoming-connections')
+ ->expectsOutput('Dispatched 0 upcoming-post connection checks.')
+ ->assertSuccessful();
+
+ Queue::assertNothingPushed();
+});
+
+test('dispatches nothing when the only at-risk post_platform is disabled', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->disabled()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $this->artisan('social:check-upcoming-connections')
+ ->expectsOutput('Dispatched 0 upcoming-post connection checks.')
+ ->assertSuccessful();
+
+ Queue::assertNothingPushed();
+});
+
+test('dispatches nothing when the only at-risk post_platform is on a paused account', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'is_active' => false,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $this->artisan('social:check-upcoming-connections')
+ ->expectsOutput('Dispatched 0 upcoming-post connection checks.')
+ ->assertSuccessful();
+
+ Queue::assertNothingPushed();
+});
+
+test('dispatches nothing when the only at-risk post is still a draft', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->draft()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $this->artisan('social:check-upcoming-connections')
+ ->expectsOutput('Dispatched 0 upcoming-post connection checks.')
+ ->assertSuccessful();
+
+ Queue::assertNothingPushed();
+});
+
+test('dispatches one job per distinct workspace when multiple workspaces have at-risk posts', function () {
+ Event::fake();
+ Queue::fake();
+
+ $workspaceA = Workspace::factory()->create();
+ $workspaceB = Workspace::factory()->create();
+
+ foreach ([$workspaceA, $workspaceB] as $workspace) {
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+ }
+
+ $this->artisan('social:check-upcoming-connections')->assertSuccessful();
+
+ Queue::assertPushed(VerifyUpcomingPostConnections::class, 2);
+});
diff --git a/tests/Feature/Jobs/VerifyUpcomingPostConnectionsTest.php b/tests/Feature/Jobs/VerifyUpcomingPostConnectionsTest.php
new file mode 100644
index 000000000..14a2eddb1
--- /dev/null
+++ b/tests/Feature/Jobs/VerifyUpcomingPostConnectionsTest.php
@@ -0,0 +1,1583 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\Notification\Channel;
+use App\Enums\Notification\Type;
+use App\Enums\PostPlatform\Status as PostPlatformStatus;
+use App\Enums\SocialAccount\Status as SocialAccountStatus;
+use App\Exceptions\PlatformUnavailableException;
+use App\Exceptions\TokenExpiredException;
+use App\Jobs\VerifyUpcomingPostConnections;
+use App\Mail\PostAtRisk;
+use App\Models\Notification;
+use App\Models\Post;
+use App\Models\PostPlatform;
+use App\Models\SocialAccount;
+use App\Models\Workspace;
+use App\Services\Social\ConnectionVerifier;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Http\Client\ConnectionException;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Mail;
+
+test('marks the account expired and queues a notification when verify throws TokenExpiredException', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($workspace, $postPlatform) {
+ return $mail->workspace->id === $workspace->id
+ && count($mail->postPlatformIds) === 1
+ && in_array($postPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('creates an in-app notification for the workspace owner alongside the email', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect(Notification::count())->toBe(1);
+
+ $notification = Notification::first();
+ expect($notification->user_id)->toBe($workspace->owner->id)
+ ->and($notification->workspace_id)->toBe($workspace->id)
+ ->and($notification->type)->toBe(Type::PostAtRisk)
+ ->and($notification->channel)->toBe(Channel::Both)
+ ->and($notification->title)->toBe('1 upcoming post is at risk');
+
+ // The in-app title and the email subject are built from the same count,
+ // captured once at dispatch time — they must never disagree.
+ Mail::assertQueued(PostAtRisk::class, fn ($mail) => $mail->count === 1);
+});
+
+test('defers to the next run instead of warning when markAsTokenExpired loses the account status lock', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ // Simulate a concurrent process (e.g. a publish attempt) already holding
+ // this account's status lock, so markAsTokenExpired() can't acquire it
+ // and silently no-ops.
+ $lock = Cache::lock("social_account_status:{$account->id}", 10);
+ $lock->get();
+
+ try {
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::Connected);
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+ } finally {
+ $lock->release();
+ }
+});
+
+test('verifies a distinct account only once even with multiple at-risk posts', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+
+ $postPlatforms = collect(range(1, 3))->map(function (int $i) use ($workspace, $account) {
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20 * $i),
+ ]);
+
+ return PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+ });
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Facebook access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ foreach ($postPlatforms as $postPlatform) {
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ }
+
+ Mail::assertQueued(PostAtRisk::class, fn ($mail) => count($mail->postPlatformIds) === 3);
+});
+
+test('ignores posts outside the 1-hour window', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addHours(3),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertNothingQueued();
+});
+
+test('ignores draft posts even with a scheduled_at inside the window', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->draft()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertNothingQueued();
+});
+
+test('ignores posts already warned', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => now()->subMinutes(5),
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertNothingQueued();
+});
+
+test('does not re-verify an account already known token_expired, but still warns about new posts', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'error_message' => 'Threads access token is invalid or expired',
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ Mail::assertQueued(PostAtRisk::class);
+});
+
+test('counts distinct posts, not post_platforms, when one post spans multiple broken accounts', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $accountOne = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'error_message' => 'Threads access token is invalid or expired',
+ ]);
+ $accountTwo = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'error_message' => 'Facebook access token is invalid or expired',
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $accountOne->id,
+ 'platform' => $accountOne->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $accountTwo->id,
+ 'platform' => $accountTwo->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ // Two post_platforms, but they belong to the same post — the count
+ // must reflect distinct posts, not post_platform rows.
+ Mail::assertQueued(PostAtRisk::class, fn ($mail) => $mail->count === 1 && count($mail->postPlatformIds) === 2);
+});
+
+test('does not re-verify an account already known disconnected, but still warns about new posts', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Disconnected,
+ 'error_message' => 'Threads account was disconnected',
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ Mail::assertQueued(PostAtRisk::class);
+});
+
+test('does not re-notify about an already-broken account within the cooldown, even for a brand-new at-risk post', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ ]);
+
+ // A post already warned about 10 minutes ago — still within the 1-hour
+ // renotify cooldown for this account.
+ $earlierPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(10),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $earlierPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => now()->subMinutes(10),
+ ]);
+
+ // A brand-new post that just entered the risk window — never warned.
+ $newPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $newPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $newPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ // Left unstamped so it's picked up once the cooldown expires, instead of
+ // being silently absorbed without ever being mentioned in an email.
+ expect($newPostPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('re-notifies about an already-broken account once the cooldown has passed', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ ]);
+
+ $earlierPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(10),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $earlierPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => now()->subMinutes(90),
+ ]);
+
+ $newPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $newPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $newPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($newPostPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ Mail::assertQueued(PostAtRisk::class);
+});
+
+test('skips notifying about a freshly-disconnected account to avoid a duplicate with AccountDisconnected', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'disconnected_at' => now()->subMinutes(2),
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('notifies about an already-broken account once the disconnection grace period has passed', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'disconnected_at' => now()->subMinutes(10),
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ Mail::assertQueued(PostAtRisk::class);
+});
+
+test('trusts a recently successful verification and does not re-verify within the same run window', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ 'last_verified_at' => now()->subMinutes(10),
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertNothingQueued();
+});
+
+test('re-verifies an account once the last successful verification has aged out', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ 'last_verified_at' => now()->subMinutes(56),
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturn(true);
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($account->fresh()->last_verified_at->isAfter(now()->subMinute()))->toBeTrue();
+});
+
+test('records last_verified_at after a successful verification', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ 'last_verified_at' => null,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturn(true);
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($account->fresh()->last_verified_at)->not->toBeNull();
+});
+
+test('defers verification until the post is within 30 minutes of publishing', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(55),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($account->fresh()->last_verified_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('verifies once the nearest post in the group crosses the 30-minute lead, even if others are farther out', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+
+ $nearPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(25),
+ ]);
+ $nearPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $nearPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $farPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(58),
+ ]);
+ $farPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $farPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturn(true);
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($account->fresh()->last_verified_at)->not->toBeNull();
+ expect($nearPostPlatform->fresh())->not->toBeNull();
+ expect($farPostPlatform->fresh())->not->toBeNull();
+});
+
+test('defers to the next run instead of duplicating AccountDisconnected when another process wins the race', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturnUsing(function () use ($account) {
+ // Simulate RefreshExpiringTokens/RefreshSocialToken discovering and
+ // announcing the same break (its own AccountDisconnected email)
+ // between when this job loaded the account as Connected and when
+ // its own verify() call returns.
+ $account->fresh()->update([
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'disconnected_at' => now(),
+ ]);
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('skips notifying when a concurrent run already claimed the warning window', function () {
+ // This simulates the "other run" serially, inside the same process and
+ // transaction, by mutating the row from within our own verify() mock —
+ // it proves the claim query's WHERE clause excludes an already-claimed
+ // row, not that ->lockForUpdate() itself prevents two real overlapping
+ // Postgres transactions from double-claiming. That needs two genuinely
+ // concurrent connections, which Pest's single-connection RefreshDatabase
+ // tests can't exercise.
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturnUsing(function () use ($postPlatform) {
+ // Simulate a second, overlapping run of this same job (the
+ // ShouldBeUnique lock's TTL matches the schedule cadence, so two
+ // instances can briefly overlap if a run takes unusually long)
+ // already claiming and warning about this exact post_platform,
+ // between this run's select and its own claim update below.
+ $postPlatform->update(['connection_warning_sent_at' => now()]);
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+ Mail::assertNothingQueued();
+});
+
+test('narrows the notification to only the rows this run actually claimed when a concurrent run claims some but not all', function () {
+ // Same caveat as the test above: the "other run" is simulated serially
+ // inside our own verify() mock, so this proves the post-claim narrowing
+ // logic, not ->lockForUpdate()'s row-locking behavior under two genuinely
+ // concurrent Postgres transactions (not reproducible with a single test
+ // connection).
+ Mail::fake();
+
+ // Both post_platforms belong to the SAME account/group deliberately —
+ // unlike a two-account version, this makes the scenario independent of
+ // which group a DB result set happens to return first (groupBy()
+ // preserves query order, and atRiskPostPlatforms() has no ORDER BY).
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+
+ $claimedByOtherRunPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $claimedByOtherRunPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $claimedByOtherRunPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $stillClaimableByThisRunPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(25),
+ ]);
+ $stillClaimableByThisRunPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $stillClaimableByThisRunPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->andReturnUsing(function () use ($claimedByOtherRunPostPlatform) {
+ // Simulate a second, overlapping run of this same job claiming
+ // one of this account's two post_platforms — mid-call, between
+ // this run's own read (already reflected in $atRisk) and its
+ // claim step below.
+ $claimedByOtherRunPostPlatform->update(['connection_warning_sent_at' => now()]);
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($stillClaimableByThisRunPostPlatform, $claimedByOtherRunPostPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($stillClaimableByThisRunPostPlatform->id, $mail->postPlatformIds, true)
+ && ! in_array($claimedByOtherRunPostPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('does not crash when the account is deleted between being loaded and the TokenExpiredException being handled', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturnUsing(function () use ($account) {
+ // Simulate the user disconnecting (hard-deleting) the account in the
+ // brief window between this job loading it and handling the
+ // exception thrown here.
+ SocialAccount::where('id', $account->id)->delete();
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('a deleted account does not abort the run for other accounts in the same workspace', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+
+ $deletedAccount = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $deletedPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(15),
+ ]);
+ $deletedPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $deletedPost->id,
+ 'social_account_id' => $deletedAccount->id,
+ 'platform' => $deletedAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $survivingAccount = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $survivingPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $survivingPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $survivingPost->id,
+ 'social_account_id' => $survivingAccount->id,
+ 'platform' => $survivingAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->with(Mockery::on(fn ($account) => $account->id === $deletedAccount->id))
+ ->andReturnUsing(function () use ($deletedAccount) {
+ SocialAccount::where('id', $deletedAccount->id)->delete();
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->with(Mockery::on(fn ($account) => $account->id === $survivingAccount->id))
+ ->andThrow(new TokenExpiredException('Facebook access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($deletedPostPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($survivingPostPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($survivingAccount->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($survivingPostPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($survivingPostPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('a post deleted between the main query and the eager-loaded post relation resolving does not crash the run', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+
+ $doomedPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(15),
+ ]);
+ $doomedPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $doomedPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $survivingPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $survivingPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $survivingPost->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ // atRiskPostPlatforms() runs the post_platforms select, then a separate
+ // eager-load query for the post relation. Deleting the post right after
+ // the first query — but before the second — reproduces the race: this
+ // job's in-memory PostPlatform row still exists, but its post relation
+ // resolves to null once the eager load runs.
+ // str_starts_with (not str_contains) deliberately excludes the
+ // recentlyWarnedAbout()/recentlyDisconnected() exists() subqueries —
+ // Laravel compiles ->exists() as "select exists(select * from
+ // \"post_platforms\" where ...)", which contains but doesn't start with
+ // this prefix, so those never trip the listener.
+ $listener = function ($query) use ($doomedPost) {
+ if (str_starts_with($query->sql, 'select * from "post_platforms"')) {
+ Post::where('id', $doomedPost->id)->delete();
+ }
+ };
+ DB::listen($listener);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ // post_platforms.post_id cascades on delete, so the row itself is gone —
+ // nothing left to warn about for it.
+ expect($doomedPostPlatform->fresh())->toBeNull();
+ expect($survivingPostPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($survivingPostPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($survivingPostPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('does not verify or warn about a post_platform on a paused account', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ 'is_active' => false,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('still verifies and warns about an active account when another account in the same workspace is paused', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+
+ $pausedAccount = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ 'is_active' => false,
+ ]);
+ $pausedPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $pausedPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $pausedPost->id,
+ 'social_account_id' => $pausedAccount->id,
+ 'platform' => $pausedAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $activeAccount = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $activePost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(25),
+ ]);
+ $activePostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $activePost->id,
+ 'social_account_id' => $activeAccount->id,
+ 'platform' => $activeAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ // andReturnUsing (rather than a single ->with()-constrained expectation)
+ // deliberately avoids a Mockery expectation-mismatch exception: the job's
+ // own catch (Exception $e) around verify() would silently swallow that,
+ // masking a missing is_active guard instead of failing the test.
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')
+ ->andReturnUsing(function (SocialAccount $account) use ($activeAccount) {
+ if ($account->id !== $activeAccount->id) {
+ // Only reachable if the is_active guard fails to exclude the paused account.
+ return true;
+ }
+
+ throw new TokenExpiredException('Threads access token is invalid or expired');
+ });
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($pausedAccount->fresh()->last_verified_at)->toBeNull();
+ expect($pausedPostPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($activePostPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($activePostPlatform, $pausedPostPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($activePostPlatform->id, $mail->postPlatformIds, true)
+ && ! in_array($pausedPostPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('does not verify or warn about an account paused mid-run, after atRiskPostPlatforms() already selected its post_platform', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ // atRiskPostPlatforms()'s is_active guard is query-time only — pause the
+ // account right after its main select runs (already passed the guard)
+ // but before the per-account loop reaches it, reproducing the race the
+ // fresh() re-check at the top of each account's iteration exists to close.
+ $listener = function ($query) use ($account) {
+ if (str_starts_with($query->sql, 'select * from "post_platforms"')) {
+ $account->update(['is_active' => false]);
+ }
+ };
+ DB::listen($listener);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('does not warn about an already token_expired account paused mid-run, after atRiskPostPlatforms() already selected its post_platform', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::TokenExpired,
+ 'error_message' => 'Threads access token is invalid or expired',
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ // The "already known broken" branch (no verify() call, straight to
+ // $atRisk) must respect the same mid-run pause race as the verify()
+ // path — an account paused between the main select and the loop
+ // reaching it shouldn't get warned about a connection its owner
+ // deliberately paused, even though it's already broken.
+ $listener = function ($query) use ($account) {
+ if (str_starts_with($query->sql, 'select * from "post_platforms"')) {
+ $account->update(['is_active' => false]);
+ }
+ };
+ DB::listen($listener);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('does not crash or warn when the account is hard-deleted mid-run, after atRiskPostPlatforms() already selected its post_platform', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ // Same race as the two tests above, but the account is hard-deleted
+ // instead of paused — social_account_id is nullOnDelete(), so the
+ // post_platform row survives with a dangling reference. The re-fetch
+ // guard must handle "row is gone" the same way it handles "row is
+ // paused": SocialAccount::active()->find() returns null either way.
+ // Deleting after the socialAccount eager-load query (rather than the
+ // main post_platforms select, like the two tests above) is deliberate:
+ // deleting that early would instead hit the pre-existing, unrelated
+ // "$account is null straight out of the eager load" branch — this
+ // needs the account to still resolve as non-null going into the loop,
+ // then disappear before the guard's own re-fetch runs.
+ $listener = function ($query) use ($account) {
+ if (str_starts_with($query->sql, 'select * from "social_accounts"')) {
+ $account->delete();
+ }
+ };
+ DB::listen($listener);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('does not warn and does not mark connection_warning_sent_at on PlatformUnavailableException', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new PlatformUnavailableException('Threads API returned 503'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::Connected);
+ Mail::assertNothingQueued();
+});
+
+test('does nothing when the account verifies successfully', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturn(true);
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::Connected);
+ Mail::assertNothingQueued();
+});
+
+test('an unexpected exception verifying one account does not abort the run for other accounts', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+
+ $brokenAccount = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $brokenPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $brokenPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $brokenPost->id,
+ 'social_account_id' => $brokenAccount->id,
+ 'platform' => $brokenAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $expiredAccount = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $expiredPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $expiredPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $expiredPost->id,
+ 'social_account_id' => $expiredAccount->id,
+ 'platform' => $expiredAccount->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->with(Mockery::on(fn ($account) => $account->id === $brokenAccount->id))
+ ->andThrow(new ConnectionException('Could not resolve host'));
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->with(Mockery::on(fn ($account) => $account->id === $expiredAccount->id))
+ ->andThrow(new TokenExpiredException('Facebook access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($brokenPostPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($brokenAccount->fresh()->status)->toBe(SocialAccountStatus::Connected);
+
+ expect($expiredPostPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($expiredAccount->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($expiredPostPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($expiredPostPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('ignores disabled platforms even inside the risk window', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ PostPlatform::factory()->disabled()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ Mail::assertNothingQueued();
+});
+
+test('does not leak another workspace\'s at-risk posts into this workspace\'s notification', function () {
+ Mail::fake();
+
+ $workspaceA = Workspace::factory()->create();
+ $accountA = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspaceA->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $postA = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspaceA->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatformA = PostPlatform::factory()->create([
+ 'post_id' => $postA->id,
+ 'social_account_id' => $accountA->id,
+ 'platform' => $accountA->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $workspaceB = Workspace::factory()->create();
+ $accountB = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspaceB->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $postB = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspaceB->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatformB = PostPlatform::factory()->create([
+ 'post_id' => $postB->id,
+ 'social_account_id' => $accountB->id,
+ 'platform' => $accountB->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')
+ ->once()
+ ->with(Mockery::on(fn ($account) => $account->id === $accountA->id))
+ ->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ $verifier->shouldNotReceive('verify')
+ ->with(Mockery::on(fn ($account) => $account->id === $accountB->id));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspaceA->id);
+
+ expect($postPlatformA->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($postPlatformB->fresh()->connection_warning_sent_at)->toBeNull();
+ expect($accountB->fresh()->status)->toBe(SocialAccountStatus::Connected);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($workspaceA, $postPlatformA, $postPlatformB) {
+ return $mail->workspace->id === $workspaceA->id
+ && in_array($postPlatformA->id, $mail->postPlatformIds, true)
+ && ! in_array($postPlatformB->id, $mail->postPlatformIds, true);
+ });
+
+ Mail::assertQueuedCount(1);
+});
+
+test('re-evaluates a post_platform warned more than a day ago instead of skipping it forever', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => now()->subDay()->subMinute(),
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull()
+ ->and($postPlatform->fresh()->connection_warning_sent_at->isAfter(now()->subMinute()))->toBeTrue();
+
+ Mail::assertQueued(PostAtRisk::class);
+});
+
+test('still skips a post_platform warned less than a day ago', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $warnedAt = now()->subHours(2);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => $warnedAt,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldNotReceive('verify');
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at->format('Y-m-d H:i:s'))
+ ->toBe($warnedAt->format('Y-m-d H:i:s'));
+ Mail::assertNothingQueued();
+});
+
+test('does not re-warn a re-armed post_platform when the account has since been reconnected', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $warnedAt = now()->subDay()->subMinute();
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ 'connection_warning_sent_at' => $warnedAt,
+ ]);
+
+ // Old warning is stale enough to re-arm the row, but this time the
+ // account verifies fine — the user reconnected in the meantime.
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andReturn(true);
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ // The row was re-evaluated (not skipped — verify() was called), but
+ // since it came back healthy, nothing about it changes: no new
+ // warning, no notification, no touch to the account's status.
+ expect($postPlatform->fresh()->connection_warning_sent_at->format('Y-m-d H:i:s'))
+ ->toBe($warnedAt->format('Y-m-d H:i:s'));
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::Connected);
+ Mail::assertNothingQueued();
+});
+
+test('does not crash the run on a post_platform with a null social_account_id', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create();
+
+ $orphanedPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ PostPlatform::factory()->create([
+ 'post_id' => $orphanedPost->id,
+ 'social_account_id' => null,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $account = SocialAccount::factory()->facebook()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(20),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Facebook access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->not->toBeNull();
+ expect($account->fresh()->status)->toBe(SocialAccountStatus::TokenExpired);
+
+ Mail::assertQueued(PostAtRisk::class, function ($mail) use ($postPlatform) {
+ return count($mail->postPlatformIds) === 1
+ && in_array($postPlatform->id, $mail->postPlatformIds, true);
+ });
+});
+
+test('leaves posts unwarned and does not send an email when the workspace has no owner', function () {
+ Mail::fake();
+
+ $workspace = Workspace::factory()->create(['user_id' => null]);
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'status' => SocialAccountStatus::Connected,
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->addMinutes(30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ 'status' => PostPlatformStatus::Pending,
+ ]);
+
+ $verifier = mock(ConnectionVerifier::class);
+ $verifier->shouldReceive('verify')->once()->andThrow(new TokenExpiredException('Threads access token is invalid or expired'));
+ app()->instance(ConnectionVerifier::class, $verifier);
+
+ VerifyUpcomingPostConnections::dispatchSync($workspace->id);
+
+ expect($postPlatform->fresh()->connection_warning_sent_at)->toBeNull();
+ Mail::assertNothingQueued();
+});
+
+test('job is unique per workspace with a window covering its timeout', function () {
+ $job = new VerifyUpcomingPostConnections('workspace-uuid');
+
+ expect($job)->toBeInstanceOf(ShouldBeUnique::class)
+ ->and($job->uniqueId())->toBe('workspace-uuid')
+ ->and($job->uniqueFor)->toBeGreaterThanOrEqual($job->timeout);
+});
diff --git a/tests/Feature/Mail/PostAtRiskTest.php b/tests/Feature/Mail/PostAtRiskTest.php
new file mode 100644
index 000000000..d67d06d50
--- /dev/null
+++ b/tests/Feature/Mail/PostAtRiskTest.php
@@ -0,0 +1,194 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Mail\PostAtRisk;
+use App\Models\Post;
+use App\Models\PostPlatform;
+use App\Models\SocialAccount;
+use App\Models\Workspace;
+
+test('renders subject and body listing the at-risk account and its post times', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(14, 30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$postPlatform->id], 1);
+
+ $mailable->assertHasSubject('1 post is at risk in Acme Co');
+ $mailable->assertSeeInHtml('Posts May Fail to Publish');
+ $mailable->assertSeeInHtml('Acme Co');
+ $mailable->assertSeeInHtml('1 post scheduled: 14:30 UTC');
+});
+
+test('renders plural subject and postsLabel when multiple posts are at risk', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+
+ $postPlatformIds = collect([
+ ['time' => [14, 30]],
+ ['time' => [15, 0]],
+ ])->map(function (array $data) use ($workspace, $account) {
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(...$data['time']),
+ ]);
+
+ return PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ])->id;
+ })->all();
+
+ $mailable = new PostAtRisk($workspace, $postPlatformIds, 2);
+
+ $mailable->assertHasSubject('2 posts are at risk in Acme Co');
+ $mailable->assertSeeInHtml('2 posts scheduled: 14:30, 15:00 UTC');
+});
+
+test('groups post_platforms by account when rehydrating for send', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $threadsAccount = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $facebookAccount = SocialAccount::factory()->facebook()->create(['workspace_id' => $workspace->id]);
+
+ $threadsPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(9, 0),
+ ]);
+ $threadsPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $threadsPost->id,
+ 'social_account_id' => $threadsAccount->id,
+ 'platform' => $threadsAccount->platform,
+ ]);
+
+ $facebookPost = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(10, 0),
+ ]);
+ $facebookPostPlatform = PostPlatform::factory()->create([
+ 'post_id' => $facebookPost->id,
+ 'social_account_id' => $facebookAccount->id,
+ 'platform' => $facebookAccount->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$threadsPostPlatform->id, $facebookPostPlatform->id], 2);
+
+ $mailable->assertHasSubject('2 posts are at risk in Acme Co');
+ $mailable->assertSeeInHtml('1 post scheduled: 09:00 UTC');
+ $mailable->assertSeeInHtml('1 post scheduled: 10:00 UTC');
+});
+
+test('only carries the workspace, post_platform IDs, and count on the queue payload, not full model graphs', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create([
+ 'workspace_id' => $workspace->id,
+ 'access_token' => 'super-secret-token-value',
+ ]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(14, 30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$postPlatform->id], 1);
+
+ $serialized = serialize($mailable);
+
+ expect($serialized)->not->toContain('super-secret-token-value')
+ ->and($serialized)->not->toContain(SocialAccount::class)
+ ->and($serialized)->not->toContain(PostPlatform::class)
+ ->and(strlen($serialized))->toBeLessThan(2000);
+});
+
+test('footer links to notification preferences instead of an unsubscribe link', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(14, 30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$postPlatform->id], 1);
+
+ $mailable->assertSeeInHtml('Manage notifications');
+ $mailable->assertSeeInHtml(route('app.notifications.preferences'));
+ $mailable->assertDontSeeInHtml('Unsubscribe');
+});
+
+test('subject and previewText stay locked to the dispatch-time count even if a row disappears before send', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(14, 30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$postPlatform->id], 1);
+
+ // Simulate the row disappearing between when this mailable was
+ // dispatched and when it's actually rendered for send — the count
+ // passed at construction (matching the in-app notification's title)
+ // must not be recomputed from the now-stale rehydrated rows.
+ $postPlatform->delete();
+
+ $mailable->assertHasSubject('1 post is at risk in Acme Co');
+ $content = $mailable->content();
+ expect($content->with['previewText'])->toBe('1 post is at risk in Acme Co');
+});
+
+test('renders without crashing when none of the post_platform ids resolve', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+
+ $mailable = new PostAtRisk($workspace, ['00000000-0000-0000-0000-000000000000'], 0);
+
+ $mailable->assertHasSubject('0 posts are at risk in Acme Co');
+});
+
+test('renders without crashing when the account is deleted before send', function () {
+ $workspace = Workspace::factory()->create(['name' => 'Acme Co']);
+ $account = SocialAccount::factory()->threads()->create(['workspace_id' => $workspace->id]);
+ $post = Post::factory()->scheduled()->create([
+ 'workspace_id' => $workspace->id,
+ 'scheduled_at' => now()->setTime(14, 30),
+ ]);
+ $postPlatform = PostPlatform::factory()->create([
+ 'post_id' => $post->id,
+ 'social_account_id' => $account->id,
+ 'platform' => $account->platform,
+ ]);
+
+ $mailable = new PostAtRisk($workspace, [$postPlatform->id], 1);
+
+ // Deleting the account (not the post_platform) between dispatch and
+ // send: the FK's nullOnDelete sets post_platforms.social_account_id to
+ // null, so the rehydrated group's account resolves to null. There's
+ // nothing meaningful to render for it (no platform, no handle), so it
+ // must be dropped from the body rather than crash the render.
+ $account->delete();
+
+ $mailable->assertHasSubject('1 post is at risk in Acme Co');
+ $mailable->assertDontSeeInHtml('scheduled: 14:30 UTC');
+});
diff --git a/tests/Feature/Services/Social/ConnectionVerifierTest.php b/tests/Feature/Services/Social/ConnectionVerifierTest.php
index d70734e28..68e7f4133 100644
--- a/tests/Feature/Services/Social/ConnectionVerifierTest.php
+++ b/tests/Feature/Services/Social/ConnectionVerifierTest.php
@@ -141,12 +141,12 @@ test('refreshes youtube token before verifying when expired', function () {
test('refreshes tiktok token before verifying when expired', function () {
Http::fake([
- 'open.tiktokapis.com/v2/oauth/token/' => Http::response([
+ config('trypost.platforms.tiktok.api').'/oauth/token/' => Http::response([
'access_token' => 'new_token',
'refresh_token' => 'new_refresh_token',
'expires_in' => 86400,
], 200),
- 'open.tiktokapis.com/v2/user/info/*' => Http::response(['data' => ['user' => []]], 200),
+ config('trypost.platforms.tiktok.api').'/user/info/*' => Http::response(['data' => ['user' => []]], 200),
]);
$account = SocialAccount::factory()->tiktok()->create([
@@ -159,7 +159,7 @@ test('refreshes tiktok token before verifying when expired', function () {
expect($result)->toBeTrue();
- Http::assertSent(fn ($request) => str_contains($request->url(), 'tiktokapis.com/v2/oauth/token'));
+ Http::assertSent(fn ($request) => str_contains($request->url(), config('trypost.platforms.tiktok.api').'/oauth/token'));
});
test('refreshes pinterest token before verifying when expired', function () {
@@ -575,7 +575,7 @@ test('verifies discord by checking the bot is still in the guild', function () {
expect((new ConnectionVerifier)->verify($account))->toBeTrue();
});
-test('reports discord disconnected when the bot was removed from the guild', function () {
+test('throws TokenExpiredException when the discord bot was removed from the guild', function () {
config(['trypost.platforms.discord.bot_token' => 'BOTTOKEN']);
Http::fake([
@@ -586,7 +586,48 @@ test('reports discord disconnected when the bot was removed from the guild', fun
'platform_user_id' => '999000111',
]);
- expect((new ConnectionVerifier)->verify($account))->toBeFalse();
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ // Discord has no per-account refresh flow (one bot token shared across
+ // every connected account) — a confirmed rejection must not trigger a
+ // second, identical getGuild call against that shared budget.
+ Http::assertSentCount(1);
+});
+
+test('throws TokenExpiredException when the discord bot is no longer in the guild (403)', function () {
+ config(['trypost.platforms.discord.bot_token' => 'BOTTOKEN']);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/*' => Http::response(['message' => 'Missing Access', 'code' => 50001], 403),
+ ]);
+
+ $account = SocialAccount::factory()->discord()->create([
+ 'platform_user_id' => '999000111',
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ Http::assertSentCount(1);
+});
+
+test('throws PlatformUnavailableException, not TokenExpiredException, when the shared discord bot token is rejected', function () {
+ config(['trypost.platforms.discord.bot_token' => 'BOTTOKEN']);
+
+ // 401 means the app-wide DISCORD_BOT_TOKEN is misconfigured — every
+ // Discord-connected account would fail identically. It is not evidence
+ // that THIS account's connection is broken, so it must not disconnect it.
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/*' => Http::response(['message' => '401: Unauthorized'], 401),
+ ]);
+
+ $account = SocialAccount::factory()->discord()->create([
+ 'platform_user_id' => '999000111',
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
});
test('instagram refresh treats a Meta rate-limit (400 OAuthException code 4) as transient, not a dead token', function () {
@@ -698,6 +739,10 @@ test('facebook verify treats a dead token reported under a non-190 code as genui
expect(fn () => (new ConnectionVerifier)->verify($account))
->toThrow(TokenExpiredException::class);
+
+ // Facebook Page tokens don't expire — no per-account refresh flow — so a
+ // confirmed rejection must not trigger a second, identical /me call.
+ Http::assertSentCount(1);
});
test('facebook verify treats a Meta rate-limit as transient, not a disconnect', function () {
@@ -876,3 +921,282 @@ test('instagram refresh treats a non-JSON failure body as platform unavailable,
expect(fn () => (new ConnectionVerifier)->refreshToken($account))
->toThrow(PlatformUnavailableException::class);
});
+
+test('throws PlatformUnavailableException when the discord guild lookup fails transiently', function () {
+ config(['trypost.platforms.discord.bot_token' => 'BOTTOKEN']);
+
+ Http::fake([
+ config('trypost.platforms.discord.api').'/guilds/*' => Http::response(['message' => 'Internal Server Error'], 500),
+ ]);
+
+ $account = SocialAccount::factory()->discord()->create([
+ 'platform_user_id' => '999000111',
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('linkedin verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.linkedin.api').'/rest/userinfo' => Http::response(['message' => 'Internal Server Error'], 500),
+ ]);
+
+ $account = SocialAccount::factory()->linkedin()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('linkedin verify throws TokenExpiredException on a bare 401', function () {
+ Http::fake([
+ 'www.linkedin.com/oauth/v2/accessToken' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.linkedin.api').'/rest/userinfo' => Http::response(['message' => 'Unauthorized'], 401),
+ ]);
+
+ $account = SocialAccount::factory()->linkedin()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('linkedin page verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.linkedin-page.api').'/rest/organizationAcls*' => Http::response(['message' => 'Internal Server Error'], 500),
+ ]);
+
+ $account = SocialAccount::factory()->linkedinPage()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('linkedin page verify throws TokenExpiredException on a bare 401', function () {
+ Http::fake([
+ 'www.linkedin.com/oauth/v2/accessToken' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.linkedin-page.api').'/rest/organizationAcls*' => Http::response(['message' => 'Unauthorized'], 401),
+ ]);
+
+ $account = SocialAccount::factory()->linkedinPage()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('x verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.x.api').'/users/me' => Http::response(['title' => 'Internal Server Error'], 503),
+ ]);
+
+ $account = SocialAccount::factory()->x()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('x verify throws TokenExpiredException on a bare 401', function () {
+ Http::fake([
+ 'api.x.com/2/oauth2/token' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.x.api').'/users/me' => Http::response(['title' => 'Unauthorized'], 401),
+ ]);
+
+ $account = SocialAccount::factory()->x()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('x verify throws TokenExpiredException on an unsupported-authentication error type', function () {
+ Http::fake([
+ 'api.x.com/2/oauth2/token' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.x.api').'/users/me' => Http::response([
+ 'type' => 'https://api.twitter.com/2/problems/unsupported-authentication',
+ 'title' => 'Unsupported Authentication',
+ ], 403),
+ ]);
+
+ $account = SocialAccount::factory()->x()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('youtube verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.youtube.data_api').'/channels*' => Http::response(['error' => ['message' => 'Backend Error']], 500),
+ ]);
+
+ $account = SocialAccount::factory()->youtube()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('youtube verify throws TokenExpiredException on a bare 401', function () {
+ Http::fake([
+ 'oauth2.googleapis.com/token' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.youtube.data_api').'/channels*' => Http::response(['error' => ['message' => 'Unauthorized']], 401),
+ ]);
+
+ $account = SocialAccount::factory()->youtube()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('pinterest verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.pinterest.api').'/user_account' => Http::response(['message' => 'Internal Server Error'], 500),
+ ]);
+
+ $account = SocialAccount::factory()->pinterest()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('pinterest verify throws TokenExpiredException on a bare 401', function () {
+ Http::fake([
+ 'api.pinterest.com/v5/oauth/token' => Http::response(['error' => 'invalid_grant'], 400),
+ config('trypost.platforms.pinterest.api').'/user_account' => Http::response(['message' => 'Unauthorized'], 401),
+ ]);
+
+ $account = SocialAccount::factory()->pinterest()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('tiktok verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.tiktok.api').'/user/info/*' => Http::response(['error' => ['code' => 'internal_error']], 500),
+ ]);
+
+ $account = SocialAccount::factory()->tiktok()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('tiktok verify throws TokenExpiredException on a bare 401 from user/info', function () {
+ // /v2/user/info/ only needs the always-granted user.info.basic scope, so
+ // unlike a publish-time 401 (which can be a video.publish scope gap), a
+ // 401 here is unambiguous — the token itself is dead. A 401 also triggers
+ // verify()'s built-in refresh-and-retry, so the refresh endpoint needs a
+ // response too, even though the retried verify call fails identically.
+ Http::fake([
+ config('trypost.platforms.tiktok.api').'/oauth/token/' => Http::response([
+ 'access_token' => 'new_token',
+ 'refresh_token' => 'new_refresh_token',
+ 'expires_in' => 86400,
+ ], 200),
+ config('trypost.platforms.tiktok.api').'/user/info/*' => Http::response(['error' => ['code' => 'access_token_invalid']], 401),
+ ]);
+
+ $account = SocialAccount::factory()->tiktok()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('tiktok verify throws TokenExpiredException on a bare 401 with no recognized error code', function () {
+ // Isolates ConnectionVerifier's own status-based check from
+ // TikTokPublishException::isConfirmedDeadToken()'s error-code check:
+ // 'access_token_revoked' IS present as error.code, but it's not one of
+ // the codes that check recognizes (access_token_invalid,
+ // access_token_expired, 10001, 10002) — so only the bare
+ // `$response->status() === 401` clause in verifyTikTok() can catch it.
+ Http::fake([
+ config('trypost.platforms.tiktok.api').'/oauth/token/' => Http::response([
+ 'access_token' => 'new_token',
+ 'refresh_token' => 'new_refresh_token',
+ 'expires_in' => 86400,
+ ], 200),
+ config('trypost.platforms.tiktok.api').'/user/info/*' => Http::response(['error' => ['code' => 'access_token_revoked']], 401),
+ ]);
+
+ $account = SocialAccount::factory()->tiktok()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ // 1 refresh call (hits the faked 200) + verify called before, after, and
+ // once more when the refresh rotated the token (refreshThenVerify's own
+ // retry) — those three all hit the same faked 401, since the fake
+ // ignores the token used.
+ Http::assertSentCount(4);
+});
+
+test('bluesky verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ Http::fake([
+ config('trypost.platforms.bluesky.default_service').'/xrpc/*' => Http::response(['message' => 'Internal Server Error'], 500),
+ ]);
+
+ $account = SocialAccount::factory()->bluesky()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('bluesky verify throws TokenExpiredException when getProfile reports ExpiredToken', function () {
+ Http::fake([
+ // refreshSession and createSession (password re-auth fallback) both
+ // rejected, so refreshThenVerify exhausts every recovery path.
+ 'bsky.social/xrpc/com.atproto.server.refreshSession' => Http::response(['error' => 'ExpiredToken'], 400),
+ 'bsky.social/xrpc/com.atproto.server.createSession' => Http::response(['error' => 'InvalidRequest'], 400),
+ 'bsky.social/xrpc/app.bsky.actor.getProfile*' => Http::response(['error' => 'ExpiredToken'], 400),
+ ]);
+
+ $account = SocialAccount::factory()->bluesky()->create();
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+});
+
+test('mastodon verify treats a 5xx as platform unavailable, not a disconnect', function () {
+ $account = SocialAccount::factory()->mastodon()->create();
+ $instance = $account->meta['instance'] ?? config('trypost.platforms.mastodon.default_instance');
+
+ Http::fake([
+ "{$instance}/api/v1/accounts/verify_credentials" => Http::response(['error' => 'Internal Server Error'], 503),
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+test('mastodon verify throws TokenExpiredException on a bare 401, with no refresh attempt (mastodon tokens do not expire)', function () {
+ $account = SocialAccount::factory()->mastodon()->create();
+ $instance = $account->meta['instance'] ?? config('trypost.platforms.mastodon.default_instance');
+
+ Http::fake([
+ "{$instance}/api/v1/accounts/verify_credentials" => Http::response(['error' => 'The access token was revoked'], 401),
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ // Mastodon has no per-account refresh flow — a confirmed rejection must
+ // not trigger a second, identical verify_credentials call.
+ Http::assertSentCount(1);
+});
+
+test('mastodon verify throws TokenExpiredException on a bare 403 from verify_credentials', function () {
+ // verify_credentials is the lowest-privilege read endpoint every
+ // authorized app token can reach, so unlike a publish-time 403 on the
+ // write-scoped /statuses endpoint (which stays a Permission-category
+ // publish failure), a 403 here means the app's authorization itself was
+ // revoked. MastodonPublishException::isConfirmedDeadToken() is 401-only
+ // by design — this is ConnectionVerifier's own additional check.
+ $account = SocialAccount::factory()->mastodon()->create();
+ $instance = $account->meta['instance'] ?? config('trypost.platforms.mastodon.default_instance');
+
+ Http::fake([
+ "{$instance}/api/v1/accounts/verify_credentials" => Http::response(['error' => 'This action is not allowed'], 403),
+ ]);
+
+ expect(fn () => (new ConnectionVerifier)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ Http::assertSentCount(1);
+});
diff --git a/tests/Feature/Social/TelegramConnectionTest.php b/tests/Feature/Social/TelegramConnectionTest.php
index f30e90f9c..393338e5c 100644
--- a/tests/Feature/Social/TelegramConnectionTest.php
+++ b/tests/Feature/Social/TelegramConnectionTest.php
@@ -6,6 +6,8 @@ use App\Enums\SocialAccount\Platform;
use App\Enums\UserWorkspace\Role;
use App\Events\TelegramChannelConnected;
use App\Events\TelegramConnectFailed;
+use App\Exceptions\PlatformUnavailableException;
+use App\Exceptions\TokenExpiredException;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\SocialAccount;
@@ -370,7 +372,7 @@ it('verifies a connected telegram account via getChat', function () {
expect(app(ConnectionVerifier::class)->verify($account))->toBeTrue();
});
-it('reports a telegram account as invalid when getChat fails', function () {
+it('throws TokenExpiredException when getChat reports the chat is no longer reachable', function () {
config(['trypost.platforms.telegram.bot_token' => 'TESTTOKEN']);
$account = SocialAccount::factory()->telegram()->create(['workspace_id' => $this->workspace->id]);
@@ -379,7 +381,42 @@ it('reports a telegram account as invalid when getChat fails', function () {
'*/botTESTTOKEN/getChat*' => Http::response(['ok' => false, 'description' => 'chat not found'], 400),
]);
- expect(app(ConnectionVerifier::class)->verify($account))->toBeFalse();
+ expect(fn () => app(ConnectionVerifier::class)->verify($account))
+ ->toThrow(TokenExpiredException::class);
+
+ // Telegram has no per-account refresh flow (one bot token shared across
+ // every connected account) — a confirmed rejection must not trigger a
+ // second, identical getChat call against that shared budget.
+ Http::assertSentCount(1);
+});
+
+it('throws PlatformUnavailableException when getChat fails transiently', function () {
+ config(['trypost.platforms.telegram.bot_token' => 'TESTTOKEN']);
+
+ $account = SocialAccount::factory()->telegram()->create(['workspace_id' => $this->workspace->id]);
+
+ Http::fake([
+ '*/botTESTTOKEN/getChat*' => Http::response(['ok' => false, 'description' => 'Internal Server Error'], 500),
+ ]);
+
+ expect(fn () => app(ConnectionVerifier::class)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
+});
+
+it('throws PlatformUnavailableException, not TokenExpiredException, when the shared bot token is rejected', function () {
+ config(['trypost.platforms.telegram.bot_token' => 'TESTTOKEN']);
+
+ $account = SocialAccount::factory()->telegram()->create(['workspace_id' => $this->workspace->id]);
+
+ // 401 means the app-wide TELEGRAM_BOT_TOKEN is misconfigured — every
+ // Telegram-connected account would fail identically. It is not evidence
+ // that THIS account's connection is broken, so it must not disconnect it.
+ Http::fake([
+ '*/botTESTTOKEN/getChat*' => Http::response(['ok' => false, 'description' => 'Unauthorized'], 401),
+ ]);
+
+ expect(fn () => app(ConnectionVerifier::class)->verify($account))
+ ->toThrow(PlatformUnavailableException::class);
});
it('registers the webhook via the artisan command', function () {
diff --git a/tests/Feature/YouTubeAnalyticsTest.php b/tests/Feature/YouTubeAnalyticsTest.php
index c7c30ed97..57231a368 100644
--- a/tests/Feature/YouTubeAnalyticsTest.php
+++ b/tests/Feature/YouTubeAnalyticsTest.php
@@ -208,7 +208,8 @@ test('youtube is in supported analytics platforms', function () {
$youtubeAccount = collect($accounts)->firstWhere('platform', Platform::YouTube->value);
expect($youtubeAccount)->not->toBeNull()
- ->and($youtubeAccount['id'])->toBe($this->youtubeAccount->id);
+ ->and($youtubeAccount['id'])->toBe($this->youtubeAccount->id)
+ ->and($youtubeAccount)->toHaveKeys(['display_label']);
});
test('youtube analytics show endpoint returns metrics', function () {
diff --git a/tests/Unit/Enums/PostAtRiskNotificationPreferenceTest.php b/tests/Unit/Enums/PostAtRiskNotificationPreferenceTest.php
new file mode 100644
index 000000000..894134d2c
--- /dev/null
+++ b/tests/Unit/Enums/PostAtRiskNotificationPreferenceTest.php
@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Enums\Notification\Type;
+use App\Models\NotificationPreference;
+use App\Models\User;
+
+test('PostAtRisk emails follow the account_disconnected preference', function () {
+ $user = User::factory()->create();
+ $user->setRelation('notificationPreference', NotificationPreference::factory()->make([
+ 'account_disconnected' => false,
+ ]));
+
+ expect($user->wantsEmailFor(Type::PostAtRisk))->toBeFalse();
+
+ $user->setRelation('notificationPreference', NotificationPreference::factory()->make([
+ 'account_disconnected' => true,
+ ]));
+
+ expect($user->wantsEmailFor(Type::PostAtRisk))->toBeTrue();
+});
diff --git a/tests/Unit/Exceptions/Social/TikTokPublishExceptionTest.php b/tests/Unit/Exceptions/Social/TikTokPublishExceptionTest.php
index c05d81356..038469611 100644
--- a/tests/Unit/Exceptions/Social/TikTokPublishExceptionTest.php
+++ b/tests/Unit/Exceptions/Social/TikTokPublishExceptionTest.php
@@ -41,6 +41,26 @@ test('HTTP error access_token_invalid throws TokenExpiredException', function ()
TikTokPublishException::fromApiResponse($fakeResponse);
})->throws(TokenExpiredException::class);
+test('HTTP error scope_not_authorized (also a 401) maps to Permission category, not TokenExpiredException', function () {
+ // TikTok reports a missing video.publish grant as a 401, the same status
+ // it uses for a genuinely dead token — https://developers.tiktok.com/doc/content-posting-api-reference-direct-post.
+ // A scope gap must not disconnect the account.
+ $response = Http::response([
+ 'error' => [
+ 'code' => 'scope_not_authorized',
+ 'message' => "The access_token does not bear user's grant on video.publish scope",
+ 'log_id' => 'scope123',
+ ],
+ ], 401);
+
+ $fakeResponse = Http::fake(['*' => $response])->post(config('trypost.platforms.tiktok.api').'/test');
+
+ $exception = TikTokPublishException::fromApiResponse($fakeResponse);
+
+ expect($exception->category)->toBe(ErrorCategory::Permission)
+ ->and($exception->userMessage)->toBe('Missing required permissions. Please reconnect with all scopes.');
+});
+
test('HTTP error invalid_file_upload maps to MediaFormat category', function () {
$response = Http::response([
'error' => [
diff --git a/tests/Unit/Mail/AccountDisconnectedTest.php b/tests/Unit/Mail/AccountDisconnectedTest.php
index 2b273aaf3..d43eb8323 100644
--- a/tests/Unit/Mail/AccountDisconnectedTest.php
+++ b/tests/Unit/Mail/AccountDisconnectedTest.php
@@ -69,3 +69,13 @@ test('account disconnected mail is queueable', function () {
expect($mail)->toBeInstanceOf(ShouldQueue::class);
});
+
+test('footer links to notification preferences instead of an unsubscribe link', function () {
+ $account = SocialAccount::factory()->create();
+
+ $mail = new AccountDisconnected($account);
+
+ $mail->assertSeeInHtml('Manage notifications');
+ $mail->assertSeeInHtml(route('app.notifications.preferences'));
+ $mail->assertDontSeeInHtml('Unsubscribe');
+});
diff --git a/tests/Unit/Mail/MentionedInCommentTest.php b/tests/Unit/Mail/MentionedInCommentTest.php
index f52e893aa..15491cfc1 100644
--- a/tests/Unit/Mail/MentionedInCommentTest.php
+++ b/tests/Unit/Mail/MentionedInCommentTest.php
@@ -65,3 +65,12 @@ test('blade view renders without error', function () {
expect($rendered)->toContain('Alice Author');
expect($rendered)->toContain('short excerpt');
});
+
+test('footer links to notification preferences instead of an unsubscribe link', function () {
+ $mail = new MentionedInComment($this->comment, $this->author, 'short excerpt');
+ $rendered = $mail->render();
+
+ expect($rendered)->toContain('Manage notifications');
+ expect($rendered)->toContain(route('app.notifications.preferences'));
+ expect($rendered)->not->toContain('Unsubscribe');
+});
diff --git a/tests/Unit/Mail/WorkspaceInviteTest.php b/tests/Unit/Mail/WorkspaceInviteTest.php
index 2b3e002a7..e6611f747 100644
--- a/tests/Unit/Mail/WorkspaceInviteTest.php
+++ b/tests/Unit/Mail/WorkspaceInviteTest.php
@@ -50,3 +50,12 @@ test('workspace invite mail is queueable', function () {
expect($mail)->toBeInstanceOf(ShouldQueue::class);
});
+
+test('footer has no manage-notifications or unsubscribe link — this is a transactional email, not preference-driven', function () {
+ $invite = Invite::factory()->create();
+
+ $mail = new WorkspaceInvite($invite);
+
+ $mail->assertDontSeeInHtml('Manage notifications');
+ $mail->assertDontSeeInHtml('Unsubscribe');
+});
diff --git a/tests/Unit/PostPlatformTest.php b/tests/Unit/PostPlatformTest.php
index e49ad0102..1daddc0a0 100644
--- a/tests/Unit/PostPlatformTest.php
+++ b/tests/Unit/PostPlatformTest.php
@@ -45,6 +45,25 @@ test('markAsPublished clears stale error_message and error_context', function ()
->and($this->postPlatform->error_context)->toBeNull();
});
+test('display_name falls back to the account username when display_name is not set', function () {
+ $this->socialAccount->update(['display_name' => null, 'username' => 'acme_handle']);
+
+ expect($this->postPlatform->fresh()->display_name)->toBe('acme_handle');
+});
+
+test('display_name falls back to the platform label when the live account has neither name set', function () {
+ $this->socialAccount->update(['display_name' => null, 'username' => null]);
+
+ expect($this->postPlatform->fresh()->display_name)->toBe($this->socialAccount->platform->label());
+});
+
+test('display_name falls back to the platform_name snapshot when the account has been deleted', function () {
+ $this->postPlatform->update(['platform_name' => 'Snapshot Name']);
+ $this->socialAccount->delete();
+
+ expect($this->postPlatform->fresh()->display_name)->toBe('Snapshot Name');
+});
+
test('markAsFailed clears stale platform_post_id and platform_url', function () {
$this->postPlatform->update([
'status' => Status::Published,