<commit_before><?php

use Movim\Widget\Base;

use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\GetItem;
use Moxl\Xec\Action\Microblog\CommentsGet;
use Moxl\Xec\Action\Microblog\CommentPublish;

use Respect\Validation\Validator;

class Post extends Base
{
    public function load()
    {
        $this->addjs('post.js');
        $this->addcss('post.css');
        $this->registerEvent('microblog_commentsget_handle', 'onComments', 'post');
        $this->registerEvent('microblog_commentpublish_handle', 'onCommentPublished');
        $this->registerEvent('microblog_commentpublish_error', 'onCommentPublishError');
        $this->registerEvent('microblog_commentsget_error', 'onCommentsError');
        $this->registerEvent('pubsub_getitem_handle', 'onHandle', 'post');
        $this->registerEvent('pubsub_postdelete_handle', 'onDelete', 'post');
    }

    public function onHandle($packet)
    {
        $post = $packet->content;

        if ($post->isComment()) {
            $parent = $post->getParent();

            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($parent->nodeid).' #comments',
                $this->prepareComments($post->getParent())
            );
        } else {
            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($post->nodeid),
                $this->preparePost($post)
            );
            $this->rpc('MovimUtils.enhanceArticlesContent');
        }
    }

    public function onCommentPublished($packet)
    {
        $isLike = $packet->content;
        Notification::toast($isLike
            ? $this->__('post.comment_like_published')
            : $this->__('post.comment_published'));
    }

    public function onCommentPublishError($packet)
    {
        Notification::toast($this->__('post.comment_publish_error'));
    }

    public function onComments($packet)
    {
        $post = \App\Post::find($packet->content);

        if ($post) {
            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($post->nodeid).' #comments',
                $this->prepareComments($post)
            );
        }
    }

    public function onCommentsError($packet)
    {
        $view = $this->tpl();
        $html = $view->draw('_post_comments_error');
        $this->rpc('MovimTpl.fill', '#comments', $html);
    }

    public function onDelete($packet)
    {
        $this->rpc('Post.refreshComments');
    }

    public function ajaxGetContact($jid)
    {
        $c = new ContactActions;
        $c->ajaxGetDrawer($jid);
    }

    public function ajaxGetPost($server, $node, $nodeid)
    {
        $p = \App\Post::where('server', $server)
                      ->where('node', $node)
                      ->where('nodeid', $nodeid)
                      ->first();

        if ($p) {
            $html = $this->preparePost($p);

            $this->rpc('MovimTpl.fill', '#post_widget.'.cleanupId($p->nodeid), $html);
            $this->rpc('MovimUtils.enhanceArticlesContent');

            // If the post is a reply but we don't have the original
            if ($p->isReply() && !$p->getReply()) {
                $gi = new GetItem;
                $gi->setTo($p->replyserver)
                   ->setNode($p->replynode)
                   ->setId($p->replynodeid)
                   ->setAskReply($p->id)
                   ->request();
            }

            $gi = new GetItem;
            $gi->setTo($p->server)
               ->setNode($p->node)
               ->setId($p->nodeid)
               ->request();
        } else {
            $this->rpc('MovimTpl.fill', '#post_widget', $this->prepareNotFound());<commit_msg>Force the refresh of the article if we go directly on the URL<commit_after><?php

use Movim\Widget\Base;

use Moxl\Xec\Action\Pubsub\PostPublish;
use Moxl\Xec\Action\Pubsub\GetItem;
use Moxl\Xec\Action\Microblog\CommentsGet;
use Moxl\Xec\Action\Microblog\CommentPublish;

use Respect\Validation\Validator;

class Post extends Base
{
    public function load()
    {
        $this->addjs('post.js');
        $this->addcss('post.css');
        $this->registerEvent('microblog_commentsget_handle', 'onComments', 'post');
        $this->registerEvent('microblog_commentpublish_handle', 'onCommentPublished');
        $this->registerEvent('microblog_commentpublish_error', 'onCommentPublishError');
        $this->registerEvent('microblog_commentsget_error', 'onCommentsError');
        $this->registerEvent('pubsub_getitem_handle', 'onHandle', 'post');
        $this->registerEvent('pubsub_postdelete_handle', 'onDelete', 'post');
    }

    public function onHandle($packet)
    {
        $post = $packet->content;

        if ($post->isComment()) {
            $parent = $post->getParent();

            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($parent->nodeid).' #comments',
                $this->prepareComments($post->getParent())
            );
        } else {
            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($post->nodeid),
                $this->preparePost($post)
            );
            $this->rpc('MovimUtils.enhanceArticlesContent');
        }
    }

    public function onCommentPublished($packet)
    {
        $isLike = $packet->content;
        Notification::toast($isLike
            ? $this->__('post.comment_like_published')
            : $this->__('post.comment_published'));
    }

    public function onCommentPublishError($packet)
    {
        Notification::toast($this->__('post.comment_publish_error'));
    }

    public function onComments($packet)
    {
        $post = \App\Post::find($packet->content);

        if ($post) {
            $this->rpc(
                'MovimTpl.fill',
                '#post_widget.'.cleanupId($post->nodeid).' #comments',
                $this->prepareComments($post)
            );
        }
    }

    public function onCommentsError($packet)
    {
        $view = $this->tpl();
        $html = $view->draw('_post_comments_error');
        $this->rpc('MovimTpl.fill', '#comments', $html);
    }

    public function onDelete($packet)
    {
        $this->rpc('Post.refreshComments');
    }

    public function ajaxGetContact($jid)
    {
        $c = new ContactActions;
        $c->ajaxGetDrawer($jid);
    }

    public function ajaxGetPost($server, $node, $nodeid)
    {
        $p = \App\Post::where('server', $server)
                      ->where('node', $node)
                      ->where('nodeid', $nodeid)
                      ->first();

        $gi = new GetItem;
        $gi->setTo($server)
            ->setNode($node)
            ->setId($nodeid)
            ->request();

        if ($p) {
            $html = $this->preparePost($p);

            $this->rpc('MovimTpl.fill', '#post_widget.'.cleanupId($p->nodeid), $html);
            $this->rpc('MovimUtils.enhanceArticlesContent');

            // If the post is a reply but we don't have the original
            if ($p->isReply() && !$p->getReply()) {
                $gi = new GetItem;
                $gi->setTo($p->replyserver)
                   ->setNode($p->replynode)
                   ->setId($p->replynodeid)
                   ->setAskReply($p->id)
                   ->request();
            }
        } else {

            $this->rpc('MovimTpl.fill', '#post_widget', $this->prepareNotFound());
{'fraction_non_alphanumeric': 0.1590878604963112, 'fraction_numerical': 0.0, 'mean_word_length': 2.008878127522195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 118, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4859783', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2172, 'n_words': 325}