From: Michael Date: Sun, 11 Oct 2020 12:19:58 +0000 (+0000) Subject: Twitter: Support for real reshares added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c0892ce69606e4793d9483aa283e4fd763c9dc27;p=friendica-addons.git Twitter: Support for real reshares added --- diff --git a/twitter/twitter.php b/twitter/twitter.php index 6f3978f2..da1ea4c6 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -587,6 +587,17 @@ function twitter_post_hook(App $a, array &$b) return; } + if ($b['verb'] == Activity::ANNOUNCE) { + Logger::info('Retweet', ['uid' => $b['uid'], 'id' => substr($b['thr-parent'], 9)]); + if ($b['deleted']) { + twitter_action($a, $b["uid"], substr($orig_post["extid"], 9), "delete"); + } else { + twitter_retweet($b["uid"], substr($b["thr-parent"], 9)); + } + + return; + } + if ($b['deleted'] || ($b['created'] !== $b['edited'])) { return; } @@ -1982,8 +1993,12 @@ function twitter_is_retweet(App $a, $uid, $body) if ($id == $link) { return false; } + return twitter_retweet($uid, $id); +} - Logger::log('twitter_is_retweet: Retweeting id ' . $id . ' for user ' . $uid, Logger::DEBUG); +function twitter_retweet(int $uid, int $id, int $item_id = 0) +{ + Logger::info('Retweeting', ['user' => $uid, 'id' => $id]); $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -1993,7 +2008,12 @@ function twitter_is_retweet(App $a, $uid, $body) $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret); $result = $connection->post('statuses/retweet/' . $id); - Logger::log('twitter_is_retweet: result ' . print_r($result, true), Logger::DEBUG); + Logger::info('Retweeted', ['user' => $uid, 'id' => $id, 'result' => $result]); + + if (!empty($item_id) && !empty($result->id_str)) { + Logger::info('Update extid', ['id' => $item_id, 'extid' => $result->id_str]); + Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $item_id]); + } return !isset($result->errors); }