From bbf81d81419e5d2839ed3e980e4df6e389145d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Sun, 28 Sep 2025 15:01:58 +0200 Subject: [PATCH] Fix and simplify the Comments publication flow, fix the comments list refresh on publish with the Templater --- app/Post.php | 8 ++++---- app/Widgets/Menu/Menu.php | 7 ++++--- app/Widgets/Notifications/Notifications.php | 2 +- app/Widgets/Post/Post.php | 3 +-- app/Widgets/Post/_post.tpl | 2 +- app/Widgets/Post/_post_card.tpl | 2 +- app/Widgets/Post/_post_comments.tpl | 6 +++--- app/Widgets/StoriesViewer/_storiesviewer.tpl | 4 ++-- src/Moxl/Xec/Action/Microblog/CommentPublish.php | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/Post.php b/app/Post.php index 94cbfa933..00003add0 100644 --- a/app/Post.php +++ b/app/Post.php @@ -824,14 +824,14 @@ class Post extends Model return \App\Post::find($this->parent_id); } - public function isMine($force = false): bool + public function isMine(User $me, ?bool $force = false): bool { if ($force) { - return ($this->aid == me()->id); + return ($this->aid == $me->id); } - return ($this->aid == me()->id - || $this->server == me()->id); + return ($this->aid == $me->id + || $this->server == $me->id); } public function isMicroblog(): bool diff --git a/app/Widgets/Menu/Menu.php b/app/Widgets/Menu/Menu.php index 7b7e78cbb..260027b1f 100644 --- a/app/Widgets/Menu/Menu.php +++ b/app/Widgets/Menu/Menu.php @@ -80,7 +80,7 @@ class Menu extends Base return; } - if ($post->isComment() && !$post->isMine()) { + if ($post->isComment() && !$post->isMine($this->me)) { $contact = \App\Contact::where('id', $post->aid)->first(); $parent = $post->parent; @@ -94,13 +94,14 @@ class Menu extends Base ); } } elseif ( - $count > 0 + !$post->isComment() + && $count > 0 && (strtotime($post->published) > strtotime($since)) ) { if ($post->isMicroblog() || $post->isStory()) { $contact = \App\Contact::firstOrNew(['id' => $post->server]); - if (!$post->isMine()) { + if (!$post->isMine($this->me)) { Notif::append( 'news', '📝 ' . ($post->isStory() ? __('stories.new_story', $contact->truename) : $contact->truename), diff --git a/app/Widgets/Notifications/Notifications.php b/app/Widgets/Notifications/Notifications.php index cf5af1e41..37ee5f277 100644 --- a/app/Widgets/Notifications/Notifications.php +++ b/app/Widgets/Notifications/Notifications.php @@ -38,7 +38,7 @@ class Notifications extends Base { $post = Post::find($packet->content); - if ($post && $post->isComment() && !$post->isMine()) { + if ($post && $post->isComment() && !$post->isMine($this->me)) { $this->ajaxSetCounter(); } } diff --git a/app/Widgets/Post/Post.php b/app/Widgets/Post/Post.php index 288b87a86..c906a797a 100644 --- a/app/Widgets/Post/Post.php +++ b/app/Widgets/Post/Post.php @@ -36,11 +36,10 @@ class Post extends Base if ($post) { if ($post->isComment()) { $parent = $post->getParent(); - $this->rpc( 'MovimTpl.fill', '#post_widget.' . cleanupId($parent->nodeid) . ' #comments', - $this->prepareComments($post->getParent()) + $this->prepareComments($parent) ); $this->rpc('MovimUtils.applyAutoheight'); } else { diff --git a/app/Widgets/Post/_post.tpl b/app/Widgets/Post/_post.tpl index 8eef552b9..b8a7c176a 100644 --- a/app/Widgets/Post/_post.tpl +++ b/app/Widgets/Post/_post.tpl @@ -7,7 +7,7 @@ arrow_back - {if="$post->isMine() || ($post->userAffiliation && $post->userAffiliation->affiliation == 'owner')"} + {if="$post->isMine($c->me) || ($post->userAffiliation && $post->userAffiliation->affiliation == 'owner')"} {if="$post->isEditable()"} truename}{if="$key + 1 < $post->likes->count()"},{/if} {else} - {if="$value->isMine()"} + {if="$value->isMine($c->me)"} {$liked = [$value->server, $value->node, $value->nodeid]} {/if} - {if="!$public && ($value->isMine() || $post->isMine())"} + {if="!$public && $value->isMine($c->me, true) && $value->isLike()"}class="mine"{/if}> + {if="!$public && ($value->isMine($c->me) || $post->isMine($c->me))"} delete diff --git a/app/Widgets/StoriesViewer/_storiesviewer.tpl b/app/Widgets/StoriesViewer/_storiesviewer.tpl index d581d4823..55fbcd26d 100644 --- a/app/Widgets/StoriesViewer/_storiesviewer.tpl +++ b/app/Widgets/StoriesViewer/_storiesviewer.tpl @@ -15,7 +15,7 @@ {/if} - {if="$story->isMine()"} + {if="$story->isMine($c->me)"} delete @@ -52,7 +52,7 @@

{autoescape="off"}{$story->title|addHashtagsLinks}{/autoescape}

- {if="!$story->isMine()"} + {if="!$story->isMine()$c->me"}
  • send diff --git a/src/Moxl/Xec/Action/Microblog/CommentPublish.php b/src/Moxl/Xec/Action/Microblog/CommentPublish.php index 767dd35df..34104ddbf 100644 --- a/src/Moxl/Xec/Action/Microblog/CommentPublish.php +++ b/src/Moxl/Xec/Action/Microblog/CommentPublish.php @@ -68,12 +68,12 @@ class CommentPublish extends Action public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null) { - $g = new GetItem; + /*$g = new GetItem; $g->setTo($this->_to) ->setNode($this->_node) ->setId($this->_atom->id) ->setParentId($this->_parentid) - ->request(); + ->request();*/ $this->pack(($this->_atom->title === '♥')); $this->deliver();