[COMPONENTS][Conversation] Route 'conversation_mute' now has the

corresponding conversation view embedded, user is also redirected
properly
[PLUGINS][Favourite] Fixed typo
This commit is contained in:
Eliseu Amaro 2022-01-13 17:47:47 +00:00
parent 859bf0c0bf
commit fa9df9962e
No known key found for this signature in database
GPG Key ID: 96DA09D4B97BC2D5
6 changed files with 63 additions and 7 deletions

View File

@ -31,6 +31,8 @@ use App\Core\Cache;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\ClientException; use App\Util\Exception\ClientException;
@ -101,7 +103,7 @@ class Conversation extends FeedController
$user = Common::ensureLoggedIn(); $user = Common::ensureLoggedIn();
$is_muted = ConversationMute::isMuted($conversation_id, $user); $is_muted = ConversationMute::isMuted($conversation_id, $user);
$form = Form::create([ $form = Form::create([
['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Unmute conversation') : _m('Mute conversation')]], ['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Unmute') : _m('Mute'), 'attr' => ['class' => '']]],
]); ]);
$form->handleRequest($request); $form->handleRequest($request);
@ -113,11 +115,27 @@ class Conversation extends FeedController
} }
DB::flush(); DB::flush();
Cache::delete(ConversationMute::cacheKeys($conversation_id, $user->getId())['mute']); Cache::delete(ConversationMute::cacheKeys($conversation_id, $user->getId())['mute']);
throw new RedirectException();
// Redirect user to where they came from
// Prevent open redirect
if (!\is_null($from = $this->string('from'))) {
if (Router::isAbsolute($from)) {
Log::warning("Actor {$user->getId()} attempted to mute conversation {$conversation_id} and then get redirected to another host, or the URL was invalid ({$from})");
throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive)
} else {
// TODO anchor on element id
throw new RedirectException(url: $from);
}
} else {
// If we don't have a URL to return to, go to the instance root
throw new RedirectException('root');
}
} }
return [ return [
'_template' => 'conversation/mute.html.twig', '_template' => 'conversation/mute.html.twig',
'notes' => $this->query(query: "note-conversation:{$conversation_id}")['notes'] ?? [],
'is_muted' => $is_muted,
'form' => $form->createView(), 'form' => $form->createView(),
]; ];
} }

View File

@ -226,10 +226,23 @@ class Conversation extends Component
return Event::next; return Event::next;
} }
$from = $request->query->has('from')
? $request->query->get('from')
: $request->getPathInfo();
$mute_extra_action_url = Router::url(
'conversation_mute',
[
'conversation_id' => $note->getConversationId(),
'from' => $from . '#note-anchor-' . $note->getId(),
],
Router::ABSOLUTE_PATH,
);
$actions[] = [ $actions[] = [
'title' => ConversationMute::isMuted($note, $user) ? _m('Unmute conversation') : _m('Mute conversation'), 'title' => ConversationMute::isMuted($note, $user) ? _m('Unmute conversation') : _m('Mute conversation'),
'classes' => '', 'classes' => '',
'url' => Router::url('conversation_mute', ['conversation_id' => $note->getConversationId()]), 'url' => $mute_extra_action_url,
]; ];
return Event::next; return Event::next;

View File

@ -1,5 +1,21 @@
{% extends 'base.html.twig' %} {% extends 'collection/notes.html.twig' %}
{% block body %} {% block body %}
{{ form(form) }} <div class="section-widget section-padding">
{% if is_muted %}
<span class="section-padding alert">
<label>Do you wish to <b>unmute</b> this conversation?</label>
{{ form(form) }}
</span>
{% else %}
<span class="section-padding alert">
<label>Do you wish to <b>mute</b> this conversation?</label>
{{ form(form) }}
</span>
{% endif %}
<hr>
{{ parent() }}
</div>
{% endblock body %} {% endblock body %}

View File

@ -82,7 +82,7 @@ class Favourite extends FeedController
// Prevent open redirect // Prevent open redirect
if (!\is_null($from = $this->string('from'))) { if (!\is_null($from = $this->string('from'))) {
if (Router::isAbsolute($from)) { if (Router::isAbsolute($from)) {
Log::warning("Actor {$actor_id} attempted to reply to a note and then get redirected to another host, or the URL was invalid ({$from})"); Log::warning("Actor {$actor_id} attempted to favourite a note and then get redirected to another host, or the URL was invalid ({$from})");
throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive) throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive)
} else { } else {
// TODO anchor on element id // TODO anchor on element id

View File

@ -30,6 +30,7 @@ input[type=radio] {
input[type=radio]:checked { input[type=radio]:checked {
background: var(--background-hard); background: var(--background-hard);
box-shadow: inset 0 0 0 2px var(--accent) !important;
} }
input[type=file] { input[type=file] {
@ -99,6 +100,12 @@ button {
margin-top: var(--s); margin-top: var(--s);
} }
.alert button {
cursor: pointer !important;
margin-top: unset !important;
border-color: tomato !important;
}
button, button,
label { label {
font-family: 'Poppins', sans-serif; font-family: 'Poppins', sans-serif;

View File

@ -276,7 +276,9 @@ textarea.form-row-widget {
.alert-danger, .alert-danger,
.form-error, .form-error,
.form-row-widget-error { .form-row-widget-error {
display: inline-block; display: inline-flex;
align-items: center;
justify-content: space-between;
font-style: italic; font-style: italic;
border: solid 2px #ff6347; border: solid 2px #ff6347;
background-color: #FF634733; background-color: #FF634733;