From dd72c153d9b5cb3170a5f25dfb3c1cc856b7c355 Mon Sep 17 00:00:00 2001 From: mruac Date: Fri, 18 Aug 2023 23:53:56 +0930 Subject: [PATCH] made findParentComment more robust --- bridges/FurAffinityNotificationsBridge.php | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/bridges/FurAffinityNotificationsBridge.php b/bridges/FurAffinityNotificationsBridge.php index 18264f550a9..c48981fabaa 100644 --- a/bridges/FurAffinityNotificationsBridge.php +++ b/bridges/FurAffinityNotificationsBridge.php @@ -296,13 +296,13 @@ private function parseFavourites($record) $submission = $record->find('a', 1); $uid = $record->find('input', 0)->getAttribute('value'); $item = []; - $item['categories'] = ['favorites']; - $item['title'] = "{$user->plaintext} has favourited: {$submission->plaintext}"; - $item['uri'] = $user->getAttribute('href'); - $item['uid'] = "{$user->getAttribute('href')}#favorites-{$uid}"; - $item['timestamp'] = $record->find('.popup_date', 0)->getAttribute('title'); - $item['content'] = "getAttribute('href')}\">{$user->plaintext}"; - $item['content'] .= " has favourited your submission: getAttribute('href')}\">{$submission->plaintext}"; + $item['categories'] = ['favorites']; + $item['title'] = "{$user->plaintext} has favourited: {$submission->plaintext}"; + $item['uri'] = $user->getAttribute('href'); + $item['uid'] = "{$user->getAttribute('href')}#favorites-{$uid}"; + $item['timestamp'] = $record->find('.popup_date', 0)->getAttribute('title'); + $item['content'] = "getAttribute('href')}\">{$user->plaintext}"; + $item['content'] .= " has favourited your submission: getAttribute('href')}\">{$submission->plaintext}"; return $item; } @@ -411,6 +411,7 @@ private function parseCommentNotif($record, $oldUI, $current_user = null) return [ 'categories' => ["{$type}_comment"], + 'author' => $who, 'title' => $title, 'uri' => $url, 'uid' => $url, @@ -583,23 +584,26 @@ private function checkRequireMature($html) private function findParentComment($comment, $oldUI) { - //take $comment's width and crawl through each prev_sibling until a width is found greater than $comment's width - $getWidth = function ($elem) use ($oldUI) { + //get parent comment's CID of the current comment + if ($oldUI) { + preg_match('/cid:\d+/', $comment->find('.comment-parent', 0)->href, $res); + $parent_cid = $res[0]; + } else { + preg_match('/cid:\d+/', $comment->find('comment', 0), $res); + $parent_cid = $res[0]; + } + + //get CID of provided comment + $getCID = function ($elem) use ($oldUI) { if ($oldUI) { - return floatval($elem->getAttribute('width')); + return $elem->getAttribute('id'); } else { - preg_match( - '/( *|;|^)width( *):( *)(?P\d+)\%/', - $elem->getAttribute('style'), - $res - ); - return floatval($res['width']); + return $elem->find('a', 0)->getAttribute('id'); } }; - $depth = $getWidth($comment); $comment_sibling = $comment->prev_sibling(); - while ($depth >= $getWidth($comment_sibling)) { + while ($parent_cid !== $getCID($comment_sibling)) { $comment_sibling = $comment_sibling->prev_sibling(); } return $comment_sibling;