Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FB v20, expanded compatibility post keyword filter #102

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/js/Components/Account/AddFacebookGroup.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup>
// @deprecated
// We will remove this feature soon
import { Link, usePage } from '@inertiajs/vue3'
import FacebookIcon from "@/Icons/Facebook.vue";
import Badge from "../DataDisplay/Badge.vue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const save = () => {
<Select v-model="form.api_version"
:error="errors.hasOwnProperty('api_version')"
id="version">
<option value="v20.0">v20.0</option>
<option value="v19.0">v19.0</option>
<option value="v18.0">v18.0</option>
<option value="v17.0">v17.0</option>
Expand Down
2 changes: 0 additions & 2 deletions resources/js/Pages/Accounts/Accounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ConfirmationModal from "@/Components/Modal/ConfirmationModal.vue"
import Account from "@/Components/Account/Account.vue"
import AddTwitterAccount from "@/Components/Account/AddTwitterAccount.vue"
import AddFacebookPage from "@/Components/Account/AddFacebookPage.vue"
import AddFacebookGroup from "@/Components/Account/AddFacebookGroup.vue"
import AddMastodonAccount from "@/Components/Account/AddMastodonAccount.vue"
import SecondaryButton from "@/Components/Button/SecondaryButton.vue"
import DangerButton from "@/Components/Button/DangerButton.vue"
Expand Down Expand Up @@ -155,7 +154,6 @@ const closeConfirmationAccountDeletion = () => {
@close="addAccountModal = false">
<div class="flex flex-col">
<AddFacebookPage v-if="$page.props.is_configured_service.facebook"/>
<AddFacebookGroup v-if="$page.props.is_configured_service.facebook"/>
<AddMastodonAccount/>
<AddTwitterAccount v-if="$page.props.is_configured_service.twitter"/>
</div>
Expand Down
84 changes: 43 additions & 41 deletions src/Actions/StoreProviderEntitiesAsAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,47 @@ private function storeFacebookPages(array $items): void
}
}

private function storeFacebookGroups(array $items): void
{
$provider = SocialProviderManager::connect('facebook_group');

/**
* Get entities with access token
*
* @var SocialProviderResponse $entities
*/
$entities = $provider->getEntities();

$filterEntities = Arr::where($entities->context(), function ($entity) use ($items) {
return in_array($entity['id'], $items);
});

/**
* @var SocialProviderResponse $userAccount
*/
$userAccount = $provider->getUserAccount();

$entities = Arr::map($filterEntities, function ($entity) use ($userAccount) {
return array_merge($entity, [
'data' => [
'user' => [
'id' => $userAccount->context()['id'],
'name' => $userAccount->context()['name']
]
],
]);
});

$accessToken = $provider->getAccessToken();

foreach ($entities as $account) {
(new UpdateOrCreateAccount())(
providerName: 'facebook_group',
account: $account,
accessToken: $accessToken
);
}
}
// @deprecated
// We will remove this feature soon
// private function storeFacebookGroups(array $items): void
// {
// $provider = SocialProviderManager::connect('facebook_group');
//
// /**
// * Get entities with access token
// *
// * @var SocialProviderResponse $entities
// */
// $entities = $provider->getEntities();
//
// $filterEntities = Arr::where($entities->context(), function ($entity) use ($items) {
// return in_array($entity['id'], $items);
// });
//
// /**
// * @var SocialProviderResponse $userAccount
// */
// $userAccount = $provider->getUserAccount();
//
// $entities = Arr::map($filterEntities, function ($entity) use ($userAccount) {
// return array_merge($entity, [
// 'data' => [
// 'user' => [
// 'id' => $userAccount->context()['id'],
// 'name' => $userAccount->context()['name']
// ]
// ],
// ]);
// });
//
// $accessToken = $provider->getAccessToken();
//
// foreach ($entities as $account) {
// (new UpdateOrCreateAccount())(
// providerName: 'facebook_group',
// account: $account,
// accessToken: $accessToken
// );
// }
// }
}
2 changes: 1 addition & 1 deletion src/Builders/Filters/PostKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostKeyword implements Filter
public static function apply(Builder $builder, $value): Builder
{
return $builder->whereHas('versions', function ($query) use ($value) {
$query->whereRaw('LOWER(content->>"$[*].body") LIKE "%' . Str::lower($value) . '%"');
$query->whereRaw('LOWER(JSON_EXTRACT(content, "$[*].body")) LIKE ?', ['%' . Str::lower($value) . '%']);
});
}
}
2 changes: 0 additions & 2 deletions src/Commands/ImportAccountAudience.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Console\Command;
use Inovector\Mixpost\Concerns\AccountsOption;
use Inovector\Mixpost\SocialProviders\Mastodon\Jobs\ImportMastodonFollowersJob;
use Inovector\Mixpost\SocialProviders\Meta\Jobs\ImportFacebookGroupMembersJob;
use Inovector\Mixpost\SocialProviders\Meta\Jobs\ImportFacebookPageFollowersJob;
use Inovector\Mixpost\SocialProviders\Twitter\Jobs\ImportTwitterFollowersJob;

Expand All @@ -23,7 +22,6 @@ public function handle(): int
$job = match ($account->provider) {
'twitter' => ImportTwitterFollowersJob::class,
'facebook_page' => ImportFacebookPageFollowersJob::class,
'facebook_group' => ImportFacebookGroupMembersJob::class,
'mastodon' => ImportMastodonFollowersJob::class,
default => null,
};
Expand Down
6 changes: 1 addition & 5 deletions src/Http/Controllers/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Inovector\Mixpost\Facades\Services;
use Inovector\Mixpost\Http\Resources\AccountResource;
use Inovector\Mixpost\Models\Account;
use Inovector\Mixpost\SocialProviders\Meta\MetaProvider;

class AccountsController extends Controller
{
Expand All @@ -22,10 +21,7 @@ public function index(): Response
{
return Inertia::render('Accounts/Accounts', [
'accounts' => AccountResource::collection(Account::latest()->get())->resolve(),
'is_configured_service' => Arr::except(Services::isConfigured(), ['unsplash', 'tenor']),
'additionally' => [
'meta_app_version'=> MetaProvider::getApiVersionConfig()
]
'is_configured_service' => Arr::except(Services::isConfigured(), ['unsplash', 'tenor'])
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceForm/FacebookServiceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FacebookServiceForm extends ServiceForm
{
public static function versions(): array
{
return ['v19.0', 'v18.0', 'v17.0', 'v16.0'];
return ['v20', 'v19.0', 'v18.0', 'v17.0', 'v16.0'];
}

static function form(): array
Expand Down
18 changes: 10 additions & 8 deletions src/SocialProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ protected function connectFacebookPageProvider()
return $this->buildConnectionProvider(FacebookPageProvider::class, $config);
}

protected function connectFacebookGroupProvider()
{
$config = Services::get('facebook');

$config['redirect'] = route('mixpost.callbackSocialProvider', ['provider' => 'facebook_group']);

return $this->buildConnectionProvider(FacebookGroupProvider::class, $config);
}
// @deprecated
// We will remove this feature soon
// protected function connectFacebookGroupProvider()
// {
// $config = Services::get('facebook');
//
// $config['redirect'] = route('mixpost.callbackSocialProvider', ['provider' => 'facebook_group']);
//
// return $this->buildConnectionProvider(FacebookGroupProvider::class, $config);
// }

protected function connectMastodonProvider()
{
Expand Down
2 changes: 2 additions & 0 deletions src/SocialProviders/Meta/FacebookGroupProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Inovector\Mixpost\SocialProviders\Meta\Concerns\ManagesFacebookGroupResources;
use Inovector\Mixpost\SocialProviders\Meta\Concerns\ManagesFacebookOAuth;

// @deprecated
// We will remove this feature soon
class FacebookGroupProvider extends MetaProvider
{
use ManagesFacebookOAuth;
Expand Down
1 change: 0 additions & 1 deletion src/SocialProviders/Meta/FacebookPageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Inovector\Mixpost\SocialProviders\Meta;

use Illuminate\Support\Str;
use Inovector\Mixpost\Http\Resources\AccountResource;
use Inovector\Mixpost\SocialProviders\Meta\Concerns\ManagesFacebookOAuth;
use Inovector\Mixpost\SocialProviders\Meta\Concerns\ManagesFacebookPageResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Inovector\Mixpost\SocialProviders\Meta\FacebookGroupProvider;
use Inovector\Mixpost\Support\SocialProviderResponse;

// @deprecated
// We will remove this feature soon
class ImportFacebookGroupMembersJob implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
Expand Down
14 changes: 6 additions & 8 deletions src/SocialProviders/Meta/MetaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ public function getSupportedScopeList(): array
'pages_show_list',
'read_insights',
'pages_manage_posts',
'publish_to_groups',
],
'v17.0', 'v18.0' => [
'business_management',
'pages_show_list',
'read_insights',
'pages_manage_posts',
'publish_to_groups',
'instagram_basic',
'instagram_content_publish',
'instagram_manage_insights'
],
default => [
'business_management',
'pages_show_list',
'read_insights',
'pages_manage_posts',
'instagram_basic',
'instagram_content_publish',
'instagram_manage_insights'
]
};
}
Expand Down
Loading