Merge pull request #4981 from annando/remote-self

"remote-self" is now working for Diaspora and Twitter as well
This commit is contained in:
Hypolite Petovan 2018-05-04 17:50:17 -04:00 committed by GitHub
commit 4e1441bb3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View file

@ -121,7 +121,7 @@ function crepair_content(App $a)
// Disable remote self for everything except feeds. // Disable remote self for everything except feeds.
// There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
// Problem is, you couldn't reply to both networks. // Problem is, you couldn't reply to both networks.
if (!in_array($contact['network'], [NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA])) { if (!in_array($contact['network'], [NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_TWITTER])) {
$allow_remote_self = false; $allow_remote_self = false;
} }

View file

@ -925,7 +925,15 @@ class Item extends BaseObject
/// @todo Handling of "event-id" /// @todo Handling of "event-id"
$distributed = self::insert($item, false, false, true); $notify = false;
if ($item['uri'] == $item['parent-uri']) {
$contact = dba::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
if (DBM::is_result($contact)) {
$notify = self::isRemoteSelf($contact, $item);
}
}
$distributed = self::insert($item, false, $notify, true);
if (!$distributed) { if (!$distributed) {
logger("Distributed public item " . $itemid . " for user " . $uid . " wasn't stored", LOGGER_DEBUG); logger("Distributed public item " . $itemid . " for user " . $uid . " wasn't stored", LOGGER_DEBUG);
@ -1406,20 +1414,24 @@ class Item extends BaseObject
// Prevent the forwarding of posts that are forwarded // Prevent the forwarding of posts that are forwarded
if ($datarray["extid"] == NETWORK_DFRN) { if ($datarray["extid"] == NETWORK_DFRN) {
logger('Already forwarded', LOGGER_DEBUG);
return false; return false;
} }
// Prevent to forward already forwarded posts // Prevent to forward already forwarded posts
if ($datarray["app"] == $a->get_hostname()) { if ($datarray["app"] == $a->get_hostname()) {
logger('Already forwarded (second test)', LOGGER_DEBUG);
return false; return false;
} }
// Only forward posts // Only forward posts
if ($datarray["verb"] != ACTIVITY_POST) { if ($datarray["verb"] != ACTIVITY_POST) {
logger('No post', LOGGER_DEBUG);
return false; return false;
} }
if (($contact['network'] != NETWORK_FEED) && $datarray['private']) { if (($contact['network'] != NETWORK_FEED) && $datarray['private']) {
logger('Not public', LOGGER_DEBUG);
return false; return false;
} }
@ -1441,6 +1453,10 @@ class Item extends BaseObject
unset($datarray['created']); unset($datarray['created']);
unset($datarray['edited']); unset($datarray['edited']);
unset($datarray['network']);
unset($datarray['owner-id']);
unset($datarray['author-id']);
} }
if ($contact['network'] != NETWORK_FEED) { if ($contact['network'] != NETWORK_FEED) {
@ -1448,7 +1464,8 @@ class Item extends BaseObject
unset($datarray["plink"]); unset($datarray["plink"]);
$datarray["uri"] = item_new_uri($a->get_hostname(), $contact['uid'], $datarray["guid"]); $datarray["uri"] = item_new_uri($a->get_hostname(), $contact['uid'], $datarray["guid"]);
$datarray["parent-uri"] = $datarray["uri"]; $datarray["parent-uri"] = $datarray["uri"];
$datarray["extid"] = $contact['network']; $datarray["thr-parent"] = $datarray["uri"];
$datarray["extid"] = NETWORK_DFRN;
$urlpart = parse_url($datarray2['author-link']); $urlpart = parse_url($datarray2['author-link']);
$datarray["app"] = $urlpart["host"]; $datarray["app"] = $urlpart["host"];
} else { } else {
@ -1458,10 +1475,11 @@ class Item extends BaseObject
if ($contact['network'] != NETWORK_FEED) { if ($contact['network'] != NETWORK_FEED) {
// Store the original post // Store the original post
$r = self::insert($datarray2, false, false); $result = self::insert($datarray2, false, false);
logger('remote-self post original item - Contact '.$contact['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); logger('remote-self post original item - Contact '.$contact['url'].' return '.$result.' Item '.print_r($datarray2, true), LOGGER_DEBUG);
} else { } else {
$datarray["app"] = "Feed"; $datarray["app"] = "Feed";
$result = true;
} }
// Trigger automatic reactions for addons // Trigger automatic reactions for addons
@ -1471,7 +1489,7 @@ class Item extends BaseObject
$_SESSION["authenticated"] = true; $_SESSION["authenticated"] = true;
$_SESSION["uid"] = $contact['uid']; $_SESSION["uid"] = $contact['uid'];
return true; return $result;
} }
/** /**

View file

@ -2767,6 +2767,10 @@ class DFRN
$posted_id = Item::insert($item, false, $notify); $posted_id = Item::insert($item, false, $notify);
if ($notify) {
$posted_id = $notify;
}
logger("Item was stored with id ".$posted_id, LOGGER_DEBUG); logger("Item was stored with id ".$posted_id, LOGGER_DEBUG);
if ($item['uid'] == 0) { if ($item['uid'] == 0) {