2026-01-15 17:24:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
2026-01-15 17:24:39 +00:00
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
2026-04-01 15:19:24 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2026-01-15 17:24:39 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2026-01-17 02:46:30 +00:00
|
|
|
use Illuminate\View\View;
|
2026-01-15 17:24:39 +00:00
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
|
|
class FacebookController extends SocialController
|
|
|
|
|
{
|
|
|
|
|
protected string $driver = 'facebook';
|
|
|
|
|
|
|
|
|
|
protected SocialPlatform $platform = SocialPlatform::Facebook;
|
|
|
|
|
|
|
|
|
|
protected array $scopes = [
|
2026-01-17 02:46:30 +00:00
|
|
|
'public_profile',
|
2026-01-15 17:24:39 +00:00
|
|
|
'pages_show_list',
|
|
|
|
|
'pages_read_engagement',
|
|
|
|
|
'pages_manage_posts',
|
2026-04-02 20:57:06 +00:00
|
|
|
'read_insights',
|
2026-01-15 17:24:39 +00:00
|
|
|
];
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
public function connect(Request $request): Response|RedirectResponse
|
2026-01-15 17:24:39 +00:00
|
|
|
{
|
2026-01-16 15:36:52 +00:00
|
|
|
$this->ensurePlatformEnabled();
|
2026-01-17 02:46:30 +00:00
|
|
|
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.workspaces.create');
|
2026-01-17 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
$this->authorize('manageAccounts', $workspace);
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $workspace->id,
|
2026-04-14 22:48:35 +00:00
|
|
|
'social_reconnect_id' => null,
|
2026-01-17 02:46:30 +00:00
|
|
|
'social_connect_onboarding' => $request->boolean('onboarding'),
|
|
|
|
|
]);
|
2026-01-15 17:24:39 +00:00
|
|
|
|
|
|
|
|
return Inertia::location(
|
|
|
|
|
Socialite::driver($this->driver)
|
2026-05-02 16:49:20 +00:00
|
|
|
->usingGraphVersion($this->graphVersion())
|
2026-03-29 14:51:00 +00:00
|
|
|
->setScopes($this->scopes)
|
2026-01-15 17:24:39 +00:00
|
|
|
->redirect()
|
|
|
|
|
->getTargetUrl()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
public function callback(Request $request): View|RedirectResponse
|
2026-01-15 17:24:39 +00:00
|
|
|
{
|
|
|
|
|
$workspaceId = session('social_connect_workspace');
|
|
|
|
|
|
|
|
|
|
if (! $workspaceId) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.session_expired'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::find($workspaceId);
|
|
|
|
|
|
|
|
|
|
if (! $workspace || ! $request->user()->can('manageAccounts', $workspace)) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.workspace_not_found'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-02 16:49:20 +00:00
|
|
|
$socialUser = Socialite::driver($this->driver)->usingGraphVersion($this->graphVersion())->user();
|
2026-01-15 17:24:39 +00:00
|
|
|
|
2026-04-04 00:21:53 +00:00
|
|
|
// Trigger public_profile and pages_show_list API calls
|
|
|
|
|
// These calls are needed for Meta app review permission verification
|
2026-05-02 16:49:20 +00:00
|
|
|
Http::get(config('trypost.platforms.facebook.graph_api').'/me', [
|
2026-04-04 00:21:53 +00:00
|
|
|
'fields' => 'id,name',
|
|
|
|
|
'access_token' => $socialUser->token,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
// Fetch pages the user manages
|
|
|
|
|
$pages = $this->fetchPages($socialUser->token);
|
|
|
|
|
|
|
|
|
|
if (empty($pages)) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.no_facebook_pages'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If only one page, connect directly
|
|
|
|
|
if (count($pages) === 1) {
|
|
|
|
|
$page = $pages[0];
|
2026-03-31 03:40:18 +00:00
|
|
|
$avatarPath = uploadFromUrl(data_get($page, 'picture'));
|
2026-01-15 17:24:39 +00:00
|
|
|
|
2026-04-15 12:46:18 +00:00
|
|
|
$workspace->socialAccounts()->updateOrCreate(
|
|
|
|
|
[
|
|
|
|
|
'platform' => $this->platform->value,
|
|
|
|
|
'platform_user_id' => data_get($page, 'id'),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'username' => data_get($page, 'username', null),
|
|
|
|
|
'display_name' => data_get($page, 'name'),
|
|
|
|
|
'avatar_url' => $avatarPath,
|
|
|
|
|
'access_token' => data_get($page, 'access_token'),
|
|
|
|
|
'refresh_token' => null,
|
|
|
|
|
'token_expires_at' => null,
|
|
|
|
|
'scopes' => $this->scopes,
|
|
|
|
|
'status' => Status::Connected,
|
|
|
|
|
'error_message' => null,
|
|
|
|
|
'disconnected_at' => null,
|
|
|
|
|
'meta' => [
|
|
|
|
|
'page_id' => data_get($page, 'id'),
|
|
|
|
|
'user_id' => $socialUser->getId(),
|
|
|
|
|
'user_token' => $socialUser->token,
|
|
|
|
|
],
|
2026-01-15 17:24:39 +00:00
|
|
|
],
|
2026-04-15 12:46:18 +00:00
|
|
|
);
|
2026-01-15 17:24:39 +00:00
|
|
|
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(true, __('accounts.popup_callback.connected'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Multiple pages - store data and show selection
|
|
|
|
|
session([
|
|
|
|
|
'facebook_oauth' => [
|
|
|
|
|
'user_token' => $socialUser->token,
|
|
|
|
|
'user_id' => $socialUser->getId(),
|
|
|
|
|
'pages' => $pages,
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.social.facebook.select-page');
|
2026-01-15 17:24:39 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Facebook OAuth Error', [
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
'trace' => $e->getTraceAsString(),
|
|
|
|
|
]);
|
|
|
|
|
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.error_connecting'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function selectPage(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$oauthData = session('facebook_oauth');
|
|
|
|
|
$workspaceId = session('social_connect_workspace');
|
|
|
|
|
|
|
|
|
|
if (! $oauthData || ! $workspaceId) {
|
2026-01-26 15:01:53 +00:00
|
|
|
session()->flash('flash.banner', __('accounts.flash.session_expired'));
|
|
|
|
|
session()->flash('flash.bannerStyle', 'danger');
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.accounts');
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::find($workspaceId);
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
2026-01-26 15:01:53 +00:00
|
|
|
session()->flash('flash.banner', __('accounts.flash.workspace_not_found'));
|
|
|
|
|
session()->flash('flash.bannerStyle', 'danger');
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.accounts');
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 15:19:24 +00:00
|
|
|
$pages = collect(data_get($oauthData, 'pages'))
|
|
|
|
|
->map(fn ($page) => Arr::except($page, ['access_token']))
|
|
|
|
|
->toArray();
|
|
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
return Inertia::render('accounts/FacebookPageSelect', [
|
|
|
|
|
'workspace' => $workspace,
|
2026-04-01 15:19:24 +00:00
|
|
|
'pages' => $pages,
|
2026-01-15 17:24:39 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
public function select(Request $request): View
|
2026-01-15 17:24:39 +00:00
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'page_id' => 'required|string',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$oauthData = session('facebook_oauth');
|
|
|
|
|
$workspaceId = session('social_connect_workspace');
|
|
|
|
|
|
|
|
|
|
if (! $oauthData || ! $workspaceId) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.session_expired'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::find($workspaceId);
|
|
|
|
|
|
|
|
|
|
if (! $workspace || ! $request->user()->can('manageAccounts', $workspace)) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.workspace_not_found'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-03-31 03:40:18 +00:00
|
|
|
$selectedPage = collect(data_get($oauthData, 'pages'))->firstWhere('id', $request->page_id);
|
2026-01-15 17:24:39 +00:00
|
|
|
|
|
|
|
|
if (! $selectedPage) {
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.page_not_found'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-31 03:40:18 +00:00
|
|
|
$avatarPath = uploadFromUrl(data_get($selectedPage, 'picture'));
|
|
|
|
|
$reconnectId = data_get($oauthData, 'reconnect_id');
|
2026-01-17 02:46:30 +00:00
|
|
|
|
|
|
|
|
if ($reconnectId) {
|
|
|
|
|
// Reconnect existing account
|
|
|
|
|
$existingAccount = $workspace->socialAccounts()->find($reconnectId);
|
|
|
|
|
|
|
|
|
|
if ($existingAccount) {
|
|
|
|
|
$existingAccount->update([
|
2026-03-31 03:40:18 +00:00
|
|
|
'platform_user_id' => data_get($selectedPage, 'id'),
|
|
|
|
|
'username' => data_get($selectedPage, 'username') ?? null,
|
|
|
|
|
'display_name' => data_get($selectedPage, 'name'),
|
2026-01-17 02:46:30 +00:00
|
|
|
'avatar_url' => $avatarPath,
|
2026-03-31 03:40:18 +00:00
|
|
|
'access_token' => data_get($selectedPage, 'access_token'),
|
2026-01-17 02:46:30 +00:00
|
|
|
'refresh_token' => null,
|
|
|
|
|
'token_expires_at' => null,
|
|
|
|
|
'scopes' => $this->scopes,
|
|
|
|
|
'meta' => [
|
2026-03-31 03:40:18 +00:00
|
|
|
'page_id' => data_get($selectedPage, 'id'),
|
|
|
|
|
'user_id' => data_get($oauthData, 'user_id'),
|
|
|
|
|
'user_token' => data_get($oauthData, 'user_token'),
|
2026-01-17 02:46:30 +00:00
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
$existingAccount->markAsConnected();
|
|
|
|
|
|
|
|
|
|
session()->forget(['facebook_oauth', 'social_reconnect_id']);
|
|
|
|
|
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(true, __('accounts.popup_callback.reconnected'), $this->platform->value);
|
2026-01-17 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-15 17:24:39 +00:00
|
|
|
|
2026-04-15 12:46:18 +00:00
|
|
|
$workspace->socialAccounts()->updateOrCreate(
|
|
|
|
|
[
|
|
|
|
|
'platform' => $this->platform->value,
|
|
|
|
|
'platform_user_id' => data_get($selectedPage, 'id'),
|
2026-01-15 17:24:39 +00:00
|
|
|
],
|
2026-04-15 12:46:18 +00:00
|
|
|
[
|
|
|
|
|
'username' => data_get($selectedPage, 'username') ?? null,
|
|
|
|
|
'display_name' => data_get($selectedPage, 'name'),
|
|
|
|
|
'avatar_url' => $avatarPath,
|
|
|
|
|
'access_token' => data_get($selectedPage, 'access_token'),
|
|
|
|
|
'refresh_token' => null,
|
|
|
|
|
'token_expires_at' => null,
|
|
|
|
|
'scopes' => $this->scopes,
|
|
|
|
|
'status' => Status::Connected,
|
|
|
|
|
'error_message' => null,
|
|
|
|
|
'disconnected_at' => null,
|
|
|
|
|
'meta' => [
|
|
|
|
|
'page_id' => data_get($selectedPage, 'id'),
|
|
|
|
|
'user_id' => data_get($oauthData, 'user_id'),
|
|
|
|
|
'user_token' => data_get($oauthData, 'user_token'),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
);
|
2026-01-15 17:24:39 +00:00
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
session()->forget(['facebook_oauth', 'social_reconnect_id']);
|
2026-01-15 17:24:39 +00:00
|
|
|
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(true, __('accounts.popup_callback.connected'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Facebook page selection error', [
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
|
feat: localize OAuth popup callback messages across 12 controllers
User reported the social-account OAuth callback popup ('Threads account
connected!') stayed in English regardless of the active locale. The
hardcoded message was wired through SocialController and 11 platform
controllers (Bluesky, Facebook, Instagram, InstagramFacebook, LinkedIn,
LinkedInPage, Mastodon, Pinterest, Threads, TikTok, YouTube), plus the
Blade view that the popup renders.
Adds an accounts.popup_callback i18n block (en/pt-BR/es) covering:
- The popup chrome (title, closing/close-now status text).
- Generic success/reconnect messages (one shared 'Account connected!'
/ 'Account reconnected!' line — the popup already shows a checkmark
and lives for ~2s so platform-specific wording wasn't pulling weight).
- Error variants (account/page/channel) and contextual edge cases
(page not found, no Facebook pages, no YouTube channels, etc.).
Updates every popupCallback() callsite to read from these keys, plus
the Blade view's title and submessage. Regenerates the JSON locale
bundle so laravel-vue-i18n stays in sync.
2026-05-07 17:03:52 +00:00
|
|
|
return $this->popupCallback(false, __('accounts.popup_callback.error_connecting_page'), $this->platform->value);
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function fetchPages(string $userToken): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
2026-05-02 16:49:20 +00:00
|
|
|
$response = Http::get(config('trypost.platforms.facebook.graph_api').'/me/accounts', [
|
2026-01-15 17:24:39 +00:00
|
|
|
'access_token' => $userToken,
|
|
|
|
|
'fields' => 'id,name,username,picture{url},access_token',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($response->failed()) {
|
|
|
|
|
Log::error('Facebook pages fetch failed', [
|
|
|
|
|
'status' => $response->status(),
|
|
|
|
|
'body' => $response->body(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $response->json();
|
|
|
|
|
|
2026-03-31 03:40:18 +00:00
|
|
|
return collect(data_get($data, 'data', []))->map(fn ($page) => [
|
|
|
|
|
'id' => data_get($page, 'id'),
|
|
|
|
|
'name' => data_get($page, 'name'),
|
|
|
|
|
'username' => data_get($page, 'username', null),
|
|
|
|
|
'picture' => data_get($page, 'picture.data.url'),
|
|
|
|
|
'access_token' => data_get($page, 'access_token'),
|
2026-01-15 17:24:39 +00:00
|
|
|
])->toArray();
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('Facebook pages fetch error', [
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-02 16:49:20 +00:00
|
|
|
|
|
|
|
|
private function graphVersion(): string
|
|
|
|
|
{
|
|
|
|
|
return basename((string) parse_url((string) config('trypost.platforms.facebook.graph_api'), PHP_URL_PATH));
|
|
|
|
|
}
|
2026-01-15 17:24:39 +00:00
|
|
|
}
|