Browse Source

Allow comments to be disabled during the publication flow

pull/1281/head
Timothée Jaussoin 2 years ago
parent
commit
9039716478
  1. 4
      CHANGELOG.md
  2. 8
      app/widgets/Post/locales.ini
  3. 23
      app/widgets/Publish/Publish.php
  4. 53
      app/widgets/Publish/_publish_toggles.tpl
  5. 17
      app/widgets/Publish/publish.css
  6. 28
      app/widgets/Publish/publish.tpl
  7. 6
      app/widgets/PublishHelp/PublishHelp.php
  8. 21
      database/migrations/20240204122606_add_comments_disabled_to_drafs_table.php
  9. 12
      src/Moxl/Stanza/PubsubAtom.php

4
CHANGELOG.md

@ -1,6 +1,10 @@
Movim Changelog Movim Changelog
================ ================
v0.23.1
---------------------------
* Allow comments to be disabled during the publication flow
v0.23 v0.23
--------------------------- ---------------------------
* Add the message menu in the Picture preview * Add the message menu in the Picture preview

8
app/widgets/Post/locales.ini

@ -16,11 +16,17 @@ unknown_contact= Unknown contact
read_time_singular = %s minute read_time_singular = %s minute
read_time_plural = %s minutes read_time_plural = %s minutes
public = Publish this post publicly?
public_title = Publish this article publicly
public_text = This will allow anyone outside Movim to have access to your publication
public_yes = This post is public public_yes = This post is public
public_no = This post is private public_no = This post is private
public_url = Public URL of this post public_url = Public URL of this post
comments_disabled_title = Disable the comments
comments_disabled_text = Nobody will be able to like or comment
comments_disabled_yes = Comments disabled for this article
comments_disabled_no = Comments enabled for this article
delete_title = Delete this post delete_title = Delete this post
delete_text = You are going to delete this post, please confirm your action delete_text = You are going to delete this post, please confirm your action
delete_comment = Are you sure that you want to delete this comment? delete_comment = Are you sure that you want to delete this comment?

23
app/widgets/Publish/Publish.php

@ -187,11 +187,13 @@ class Publish extends Base
} }
} }
if (!$draft->comments_disabled) {
if ($comments) { if ($comments) {
$p->enableComments($comments->server); $p->enableComments($comments->server);
} else { } else {
$p->enableComments(); $p->enableComments();
} }
}
if ($draft->open) { if ($draft->open) {
$p->isOpen(); $p->isOpen();
@ -345,6 +347,20 @@ class Publish extends Base
} }
} }
public function ajaxToggleCommentsDisabled($id, bool $commentsDisabled)
{
$draft = $this->user->drafts()->find($id);
if ($draft) {
$draft->comments_disabled = $commentsDisabled;
$draft->save();
Toast::send(($commentsDisabled)
? $this->__('post.comments_disabled_yes')
: $this->__('post.comments_disabled_no'));
}
}
public function ajaxClearReply($id) public function ajaxClearReply($id)
{ {
$draft = $this->user->drafts()->find($id); $draft = $this->user->drafts()->find($id);
@ -358,6 +374,13 @@ class Publish extends Base
} }
public function prepareToggles(Draft $draft)
{
$view = $this->tpl();
$view->assign('draft', $draft);
return $view->draw('_publish_toggles');
}
public function prepareEmbed(DraftEmbed $embed) public function prepareEmbed(DraftEmbed $embed)
{ {
$view = $this->tpl(); $view = $this->tpl();

53
app/widgets/Publish/_publish_toggles.tpl

@ -0,0 +1,53 @@
<li>
<span class="primary privacy"
title="{$c->__('post.public_title')}">
<form>
<div>
<div class="checkbox">
<input
id="public"
name="public"
onchange="Publish_ajaxTogglePrivacy({$draft->id}, this.checked)"
{if="$draft && $draft->open"}
checked
{/if}
type="checkbox">
<label for="public">
<i class="material-symbols"></i>
</label>
</div>
</div>
</form>
</span>
<div>
<p>{$c->__('post.public_title')}</p>
<p>{$c->__('post.public_text')}</p>
</div>
</li>
<li>
<span class="primary comments_disabled"
title="{$c->__('post.comments_disabled_title')}">
<form>
<div>
<div class="checkbox">
<input
id="comments_disabled"
name="comments_disabled"
onchange="Publish_ajaxToggleCommentsDisabled({$draft->id}, this.checked)"
{if="$draft && $draft->comments_disabled"}
checked
{/if}
type="checkbox">
<label for="comments_disabled">
<i class="material-symbols"></i>
</label>
</div>
</div>
</form>
</span>
<div>
<p>{$c->__('post.comments_disabled_title')}</p>
<p>{$c->__('post.comments_disabled_text')}</p>
</div>
</li>

17
app/widgets/Publish/publish.css

@ -18,22 +18,21 @@
#publish label span.save.saved { #publish label span.save.saved {
display: initial; display: initial;
} }
#publish span.privacy {
margin-right: 1.75rem;
}
#publish textarea[name=content] { #publish textarea[name=content] {
min-height: 25rem; min-height: 25rem;
} }
#publish span.privacy form > div .checkbox > input[type="checkbox"] + label {
#publish span.privacy form > div .checkbox > input[type="checkbox"] + label,
#publish span.comments_disabled form > div .checkbox > input[type="checkbox"] + label {
top: 0.5rem; top: 0.5rem;
left: 0.5rem; left: 0.5rem;
height: 3rem; height: 3rem;
width: 3rem; width: 3rem;
} }
#publish span.privacy form > div .checkbox > input[type="checkbox"]:checked + label {
#publish span.privacy form > div .checkbox > input[type="checkbox"]:checked + label,
#publish span.comments_disabled form > div .checkbox > input[type="checkbox"]:checked + label {
left: 2.5rem; left: 2.5rem;
} }
@ -45,6 +44,14 @@
content: 'wifi_tethering'; content: 'wifi_tethering';
} }
#publish span.comments_disabled form > div .checkbox > input[type="checkbox"] + label i:before {
content: 'insert_comment';
}
#publish span.comments_disabled form > div .checkbox > input[type="checkbox"]:checked + label i:before {
content: 'comments_disabled';
}
#publishreply { #publishreply {
margin-bottom: -1rem; margin-bottom: -1rem;
} }

28
app/widgets/Publish/publish.tpl

@ -2,26 +2,6 @@
<header> <header>
<ul class="list thick"> <ul class="list thick">
<li> <li>
<span class="control privacy"
title="{$c->__('post.public')}">
<form>
<div>
<div class="checkbox">
<input
id="public"
name="public"
onchange="Publish_ajaxTogglePrivacy({$draft->id}, this.checked)"
{if="$draft && $draft->open"}
checked
{/if}
type="checkbox">
<label for="public">
<i class="material-symbols"></i>
</label>
</div>
</div>
</form>
</span>
<span <span
class="primary icon active" class="primary icon active"
{if="$draft->node == 'urn:xmpp:microblog:0'"} {if="$draft->node == 'urn:xmpp:microblog:0'"}
@ -113,7 +93,15 @@
{/loop} {/loop}
</ul> </ul>
</li> </li>
</ul>
<ul class="list">
{autoescape="off"}
{$c->prepareToggles($draft)}
{/autoescape}
</ul>
<ul class="list">
<li> <li>
<div> <div>
<a <a

6
app/widgets/PublishHelp/PublishHelp.php

@ -1,5 +1,6 @@
<?php <?php
use App\Draft;
use Movim\Widget\Base; use Movim\Widget\Base;
class PublishHelp extends Base class PublishHelp extends Base
@ -14,6 +15,11 @@ class PublishHelp extends Base
Drawer::fill($view->draw('_publishhelp'), true); Drawer::fill($view->draw('_publishhelp'), true);
} }
public function prepareToggles(Draft $draft)
{
return (new Publish)->prepareToggles($draft);
}
public function prepareHelp() public function prepareHelp()
{ {
$view = $this->tpl(); $view = $this->tpl();

21
database/migrations/20240204122606_add_comments_disabled_to_drafs_table.php

@ -0,0 +1,21 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddCommentsDisabledToDrafsTable extends Migration
{
public function up()
{
$this->schema->table('drafts', function (Blueprint $table) {
$table->boolean('comments_disabled')->default(false);
});
}
public function down()
{
$this->schema->table('drafts', function (Blueprint $table) {
$table->dropColumn('comments_disabled');
});
}
}

12
src/Moxl/Stanza/PubsubAtom.php

@ -59,7 +59,7 @@ class PubsubAtom
if ($this->name) { if ($this->name) {
$author->appendChild($dom->createElement('name', $this->name)); $author->appendChild($dom->createElement('name', $this->name));
} }
$author->appendChild($dom->createElement('uri', 'xmpp:'.$this->jid));
$author->appendChild($dom->createElement('uri', 'xmpp:' . $this->jid));
$entry->appendChild($author); $entry->appendChild($author);
/*$link = $dom->createElement('link'); /*$link = $dom->createElement('link');
@ -70,7 +70,7 @@ class PubsubAtom
$link = $dom->createElement('link'); $link = $dom->createElement('link');
$link->setAttribute('rel', 'alternate'); $link->setAttribute('rel', 'alternate');
$link->setAttribute('href', 'xmpp:'.$this->to.'?;node='.$this->node.';item='.$this->id);
$link->setAttribute('href', 'xmpp:' . $this->to . '?;node=' . $this->node . ';item=' . $this->id);
$entry->appendChild($link); $entry->appendChild($link);
if ($this->comments) { if ($this->comments) {
@ -79,11 +79,11 @@ class PubsubAtom
$link->setAttribute('title', 'comments'); $link->setAttribute('title', 'comments');
if ($this->repost) { if ($this->repost) {
$link->setAttribute('href', 'xmpp:'.$this->repost[0].'?;node=urn:xmpp:microblog:0:comments/'.$this->repost[2]);
$link->setAttribute('href', 'xmpp:' . $this->repost[0] . '?;node=urn:xmpp:microblog:0:comments/' . $this->repost[2]);
} elseif ($this->comments === true) { } elseif ($this->comments === true) {
$link->setAttribute('href', 'xmpp:'.$this->to.'?;node=urn:xmpp:microblog:0:comments/'.$this->id);
$link->setAttribute('href', 'xmpp:' . $this->to . '?;node=urn:xmpp:microblog:0:comments/' . $this->id);
} else { } else {
$link->setAttribute('href', 'xmpp:'.$this->comments.'?;node=urn:xmpp:microblog:0:comments/'.$this->id);
$link->setAttribute('href', 'xmpp:' . $this->comments . '?;node=urn:xmpp:microblog:0:comments/' . $this->id);
} }
$entry->appendChild($link); $entry->appendChild($link);
@ -129,7 +129,7 @@ class PubsubAtom
if ($this->repost) { if ($this->repost) {
$link = $dom->createElement('link'); $link = $dom->createElement('link');
$link->setAttribute('rel', 'via'); $link->setAttribute('rel', 'via');
$link->setAttribute('href', 'xmpp:'.$this->repost[0].'?;node='.$this->repost[1].';item='.$this->repost[2]);
$link->setAttribute('href', 'xmpp:' . $this->repost[0] . '?;node=' . $this->repost[1] . ';item=' . $this->repost[2]);
$entry->appendChild($link); $entry->appendChild($link);
} }

Loading…
Cancel
Save