From 6822079a0376786d601426953cfc6b1160080fe9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Jul 2022 11:40:59 -0400 Subject: [PATCH 1/2] [twitter] Add logging for error conditions in twitter_fetchtimeline() --- twitter/twitter.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index 5e3a4b9c..dd3f8986 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1257,22 +1257,26 @@ function twitter_fetchtimeline(App $a, int $uid) } if ($first_time) { + Logger::warning('First time, continue'); continue; } - if (!stristr($post->source, $application_name)) { - Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]); - - $mirrorpost = twitter_do_mirrorpost($a, $uid, $post); - - if (empty($mirrorpost['body'])) { - continue; - } - - Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]); - - Post\Delayed::add($mirrorpost['extid'], $mirrorpost, PRIORITY_MEDIUM, Post\Delayed::UNPREPARED); + if (stristr($post->source, $application_name)) { + Logger::warning('Source is application name', ['source' => $post->source, 'application_name' => $application_name]); + continue; } + Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]); + + $mirrorpost = twitter_do_mirrorpost($a, $uid, $post); + + if (empty($mirrorpost['body'])) { + Logger::warning('Body is empty', ['post' => $post, 'mirrorpost' => $mirrorpost]); + continue; + } + + Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]); + + Post\Delayed::add($mirrorpost['extid'], $mirrorpost, PRIORITY_MEDIUM, Post\Delayed::UNPREPARED); } } DI::pConfig()->set($uid, 'twitter', 'lastid', $lastid); From f813183fcf97720b57735a4f8ad1da33a1a91fa3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 9 Jul 2022 15:50:51 -0400 Subject: [PATCH 2/2] [twitter] Valid post body can be empty --- twitter/twitter.php | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index dd3f8986..2350eb99 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1094,6 +1094,9 @@ function twitter_parse_link(App $a, array &$b) } $item = twitter_createpost($a, 0, $status, [], true, false, true); + if (empty($item)) { + return; + } if ($b['format'] == 'json') { $images = []; @@ -1157,7 +1160,7 @@ function twitter_do_mirrorpost(App $a, int $uid, $post) // We don't support nested shares, so we mustn't show quotes as shares on retweets $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true, -1); - if (empty($item['body'])) { + if (empty($item)) { return []; } @@ -1173,7 +1176,7 @@ function twitter_do_mirrorpost(App $a, int $uid, $post) } else { $item = twitter_createpost($a, $uid, $post, ['id' => 0], false, false, false, -1); - if (empty($item['body'])) { + if (empty($item)) { return []; } @@ -1194,7 +1197,15 @@ function twitter_do_mirrorpost(App $a, int $uid, $post) return $datarray; } -function twitter_fetchtimeline(App $a, int $uid) +/** + * Fetches the Twitter user's own posts + * + * @param App $a + * @param int $uid + * @return void + * @throws Exception + */ +function twitter_fetchtimeline(App $a, int $uid): void { $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -1880,7 +1891,7 @@ function twitter_createpost(App $a, int $uid, $post, array $self, $create_user, if (!empty($post->retweeted_status)) { $retweet = twitter_createpost($a, $uid, $post->retweeted_status, $self, false, false, $noquote); - if (empty($retweet['body'])) { + if (empty($retweet)) { return []; } @@ -1915,7 +1926,7 @@ function twitter_createpost(App $a, int $uid, $post, array $self, $create_user, $postarray['body'] .= "\n\nhttps://twitter.com/" . $post->quoted_status->user->screen_name . "/status/" . $post->quoted_status->id_str; } else { $quoted = twitter_createpost($a, 0, $post->quoted_status, $self, false, false, true); - if (!empty($quoted['body'])) { + if (!empty($quoted)) { Item::insert($quoted); $post = Post::selectFirst(['guid', 'uri-id'], ['uri' => $quoted['uri'], 'uid' => 0]); Logger::info('Stored quoted post', ['uid' => $uid, 'uri-id' => $uriId, 'post' => $post]); @@ -1993,7 +2004,7 @@ function twitter_fetchparentposts(App $a, int $uid, $post, TwitterOAuth $connect foreach ($posts as $post) { $postarray = twitter_createpost($a, $uid, $post, $self, false, !DI::pConfig()->get($uid, 'twitter', 'create_user'), false); - if (empty($postarray['body'])) { + if (empty($postarray)) { continue; } @@ -2006,7 +2017,15 @@ function twitter_fetchparentposts(App $a, int $uid, $post, TwitterOAuth $connect } } -function twitter_fetchhometimeline(App $a, int $uid) +/** + * Fetches the posts received by the Twitter user + * + * @param App $a + * @param int $uid + * @return void + * @throws Exception + */ +function twitter_fetchhometimeline(App $a, int $uid): void { $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -2115,8 +2134,8 @@ function twitter_fetchhometimeline(App $a, int $uid) $postarray = twitter_createpost($a, $uid, $post, $self, $create_user, true, false); - if (empty($postarray['body']) || trim($postarray['body']) == '') { - Logger::info('Empty body for post ' . $post->id_str . ' and user ' . $uid); + if (empty($postarray)) { + Logger::info('Empty post ' . $post->id_str . ' and user ' . $uid); continue; } @@ -2180,7 +2199,7 @@ function twitter_fetchhometimeline(App $a, int $uid) $postarray = twitter_createpost($a, $uid, $post, $self, false, !$create_user, false); - if (empty($postarray['body'])) { + if (empty($postarray)) { continue; }