[twitter] Add expected field to parent item select in twitter_post_hook()

- Address https://github.com/friendica/friendica/issues/9250#issuecomment-751445732
pull/1063/head
Hypolite Petovan 2020-12-27 21:21:51 -05:00
parent 6439a51a19
commit 79b49cbaee
1 changed files with 13 additions and 15 deletions

View File

@ -545,6 +545,8 @@ function twitter_post_hook(App $a, array &$b)
return; return;
} }
$thr_parent = null;
if ($b['parent'] != $b['id']) { if ($b['parent'] != $b['id']) {
Logger::debug('Got comment', ['item' => $b]); Logger::debug('Got comment', ['item' => $b]);
@ -557,17 +559,15 @@ function twitter_post_hook(App $a, array &$b)
} }
$condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]];
$orig_post = Item::selectFirst(['author-nick', 'author-network'], $condition); $thr_parent = Item::selectFirst(['uri', 'extid', 'author-nick', 'author-network'], $condition);
if (!DBA::isResult($orig_post)) { if (!DBA::isResult($thr_parent)) {
Logger::warning('No parent found', ['thr-parent' => $b["thr-parent"]]); Logger::warning('No parent found', ['thr-parent' => $b["thr-parent"]]);
return; return;
} else {
$iscomment = true;
} }
if ($orig_post['author-network'] == Protocol::TWITTER) { if ($thr_parent['author-network'] == Protocol::TWITTER) {
$nickname = "@[url=" . $orig_post["author-link"] . "]" . $orig_post["author-nick"] . "[/url]"; $nickname = '@[url=' . $thr_parent['author-link'] . ']' . $thr_parent['author-nick'] . '[/url]';
$nicknameplain = "@" . $orig_post["author-nick"]; $nicknameplain = '@' . $thr_parent['author-nick'];
Logger::info('Comparing', ['nickname' => $nickname, 'nicknameplain' => $nicknameplain, 'body' => $b["body"]]); Logger::info('Comparing', ['nickname' => $nickname, 'nicknameplain' => $nicknameplain, 'body' => $b["body"]]);
if ((strpos($b["body"], $nickname) === false) && (strpos($b["body"], $nicknameplain) === false)) { if ((strpos($b["body"], $nickname) === false) && (strpos($b["body"], $nicknameplain) === false)) {
@ -575,10 +575,8 @@ function twitter_post_hook(App $a, array &$b)
} }
} }
Logger::debug('Parent found', ['parent' => $orig_post]); Logger::debug('Parent found', ['parent' => $thr_parent]);
} else { } else {
$iscomment = false;
if ($b['private'] || !strstr($b['postopts'], 'twitter')) { if ($b['private'] || !strstr($b['postopts'], 'twitter')) {
return; return;
} }
@ -592,7 +590,7 @@ function twitter_post_hook(App $a, array &$b)
} }
if (($b['verb'] == Activity::POST) && $b['deleted']) { if (($b['verb'] == Activity::POST) && $b['deleted']) {
twitter_action($a, $b["uid"], twitter_get_id($orig_post["uri"]), "delete"); twitter_action($a, $b['uid'], twitter_get_id($thr_parent['uri']), 'delete');
} }
if ($b['verb'] == Activity::LIKE) { if ($b['verb'] == Activity::LIKE) {
@ -609,7 +607,7 @@ function twitter_post_hook(App $a, array &$b)
if ($b['verb'] == Activity::ANNOUNCE) { if ($b['verb'] == Activity::ANNOUNCE) {
Logger::info('Retweet', ['uid' => $b['uid'], 'id' => twitter_get_id($b["thr-parent"])]); Logger::info('Retweet', ['uid' => $b['uid'], 'id' => twitter_get_id($b["thr-parent"])]);
if ($b['deleted']) { if ($b['deleted']) {
twitter_action($a, $b["uid"], twitter_get_id($orig_post["extid"]), "delete"); twitter_action($a, $b['uid'], twitter_get_id($thr_parent['extid']), 'delete');
} else { } else {
twitter_retweet($b["uid"], twitter_get_id($b["thr-parent"])); twitter_retweet($b["uid"], twitter_get_id($b["thr-parent"]));
} }
@ -733,8 +731,8 @@ function twitter_post_hook(App $a, array &$b)
$post['status'] = $msg; $post['status'] = $msg;
if ($iscomment) { if ($thr_parent) {
$post["in_reply_to_status_id"] = twitter_get_id($orig_post["uri"]); $post['in_reply_to_status_id'] = twitter_get_id($thr_parent['uri']);
} }
$url = 'statuses/update'; $url = 'statuses/update';
@ -748,7 +746,7 @@ function twitter_post_hook(App $a, array &$b)
if (!empty($result->errors)) { if (!empty($result->errors)) {
Logger::error('Send to Twitter failed', ['id' => $b['id'], 'error' => $result->errors]); Logger::error('Send to Twitter failed', ['id' => $b['id'], 'error' => $result->errors]);
Worker::defer(); Worker::defer();
} elseif ($iscomment) { } elseif ($thr_parent) {
Logger::notice('Post send, updating extid', ['id' => $b['id'], 'extid' => $result->id_str]); Logger::notice('Post send, updating extid', ['id' => $b['id'], 'extid' => $result->id_str]);
Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]); Item::update(['extid' => "twitter::" . $result->id_str], ['id' => $b['id']]);
} }