Filter thread replies to original author only
All checks were successful
CI / test (push) Successful in 45s
All checks were successful
CI / test (push) Successful in 45s
Only replies from the root post's author are rendered; replies from other users are skipped. Adds fixture and test for a real-world post with an other-author reply (3mhypinzezo2l). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -123,7 +123,8 @@ final class BlueskyThreadsExtension extends Minz_Extension {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
$html = $this->renderThread($data['thread'], true);
|
||||
$rootAuthorDid = $data['thread']['post']['author']['did'] ?? null;
|
||||
$html = $this->renderThread($data['thread'], true, $rootAuthorDid);
|
||||
$this->writeCache($url, $html);
|
||||
return $html;
|
||||
}
|
||||
@@ -221,7 +222,7 @@ final class BlueskyThreadsExtension extends Minz_Extension {
|
||||
// Thread rendering
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private function renderThread(array $node, bool $isRoot): string {
|
||||
private function renderThread(array $node, bool $isRoot, ?string $rootAuthorDid = null): string {
|
||||
if (!isset($node['post'])) {
|
||||
return '';
|
||||
}
|
||||
@@ -229,13 +230,21 @@ final class BlueskyThreadsExtension extends Minz_Extension {
|
||||
$html = $this->renderPost($node['post'], $isRoot);
|
||||
|
||||
if (!empty($node['replies'])) {
|
||||
$html .= '<div class="bsky-replies" style="border-left:2px solid #e1e8ed;margin-left:24px;padding-left:0;">';
|
||||
$repliesHtml = '';
|
||||
foreach ($node['replies'] as $reply) {
|
||||
if (isset($reply['post'])) {
|
||||
$html .= $this->renderThread($reply, false);
|
||||
if (!isset($reply['post'])) {
|
||||
continue;
|
||||
}
|
||||
if ($rootAuthorDid !== null && ($reply['post']['author']['did'] ?? null) !== $rootAuthorDid) {
|
||||
continue;
|
||||
}
|
||||
$repliesHtml .= $this->renderThread($reply, false, $rootAuthorDid);
|
||||
}
|
||||
if ($repliesHtml !== '') {
|
||||
$html .= '<div class="bsky-replies" style="border-left:2px solid #e1e8ed;margin-left:24px;padding-left:0;">';
|
||||
$html .= $repliesHtml;
|
||||
$html .= '</div>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
|
||||
Reference in New Issue
Block a user