fix: remove cache from remote follow form to display error messages

This commit is contained in:
Yassine Doghri 2022-03-15 14:05:19 +00:00
parent 4a009de531
commit 90e44437bd
6 changed files with 44 additions and 24 deletions

View File

@ -30,21 +30,13 @@ class ActorController extends FediverseActorController
$this->registerPodcastWebpageHit($this->actor->podcast->id);
}
$cacheName = "page_podcast-{$this->actor->username}_follow";
if (! ($cachedView = cache($cacheName))) {
helper(['form', 'components', 'svg']);
$data = [
// @phpstan-ignore-next-line
'metatags' => get_follow_metatags($this->actor),
'actor' => $this->actor,
];
helper(['form', 'components', 'svg']);
$data = [
// @phpstan-ignore-next-line
'metatags' => get_follow_metatags($this->actor),
'actor' => $this->actor,
];
return view('podcast/follow', $data, [
'cache' => DECADE,
'cache_name' => $cacheName,
]);
}
return $cachedView;
return view('podcast/follow', $data);
}
}

View File

@ -16,6 +16,7 @@ return [
'title' => 'Follow {actorDisplayName}',
'subtitle' => 'You are going to follow:',
'accountNotFound' => 'The account could not be found.',
'remoteFollowNotAllowed' => 'Seems like the account server does not allow remote follows…',
'submit' => 'Proceed to follow',
],
'favourite' => [

View File

@ -15,23 +15,24 @@ return [
'follow' => [
'label' => 'Suivre',
'title' => 'Suivre {actorDisplayName}',
'subtitle' => 'Vous allez suivre :',
'subtitle' => 'Vous allez suivre:',
'accountNotFound' => 'Le compte na pas pu être trouvé.',
'remoteFollowNotAllowed' => 'Il semble que le serveur du compte ne permet pas le suivi dun compte externe…',
'submit' => 'Poursuivre',
],
'favourite' => [
'title' => 'Mettez la publication de {actorDisplayName} en favori',
'subtitle' => 'Vous allez mettre en favori :',
'subtitle' => 'Vous allez mettre en favori:',
'submit' => 'Poursuivre',
],
'reblog' => [
'title' => 'Partagez la publication de {actorDisplayName}',
'subtitle' => 'Vous allez partager :',
'subtitle' => 'Vous allez partager:',
'submit' => 'Poursuivre',
],
'reply' => [
'title' => 'Répondre à la publication de {actorDisplayName}',
'subtitle' => 'Vous allez répondre à :',
'subtitle' => 'Vous allez répondre à:',
'submit' => 'Poursuivre',
],
];

View File

@ -16,6 +16,7 @@ return [
'title' => 'Obserwuj {actorDisplayName}',
'subtitle' => 'Zamierzasz obserwować:',
'accountNotFound' => 'Nie można znaleźć konta.',
'remoteFollowNotAllowed' => 'Seems like the account server does not allow remote follows…',
'submit' => 'Przejdź do obserwowania',
],
'favourite' => [

View File

@ -15,6 +15,7 @@ use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\I18n\Time;
use Exception;
use Modules\Fediverse\Config\Fediverse;
use Modules\Fediverse\Entities\Actor;
use Modules\Fediverse\Entities\Post;
@ -353,10 +354,12 @@ class ActorController extends Controller
// parse actor id to get actor and domain
// check if actor and domain exist
if (
! ($parts = split_handle($this->request->getPost('handle'))) ||
! ($data = get_webfinger_data($parts['username'], $parts['domain']))
) {
$handle = $this->request->getPost('handle');
$parts = split_handle($handle);
try {
$data = get_webfinger_data($parts['username'], $parts['domain']);
} catch (Exception) {
return redirect()
->back()
->withInput()
@ -372,7 +375,10 @@ class ActorController extends Controller
if (! $ostatusKey) {
// TODO: error, couldn't subscribe to activitypub account
// The instance doesn't allow its users to follow others
return $this->response->setJSON([]);
return redirect()
->back()
->withInput()
->with('error', lang('Fediverse.follow.remoteFollowNotAllowed'));
}
return redirect()->to(

View File

@ -0,0 +1,19 @@
<?php declare(strict_types=1);
if (session()->has('message')): ?>
<Alert variant="success" class="mb-4"><?= esc(session('message')) ?></Alert>
<?php endif; ?>
<?php if (session()->has('error')): ?>
<Alert variant="danger" class="mb-4"><?= esc(session('error')) ?></Alert>
<?php endif; ?>
<?php if (session()->has('errors')): ?>
<Alert variant="danger" class="mb-4">
<ul>
<?php foreach (session('errors') as $error): ?>
<li><?= esc($error) ?></li>
<?php endforeach; ?>
</ul>
</Alert>
<?php endif; ?>