From 1230ff146ae6224ba50a1c17a9f0471823054ba1 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 4 May 2018 21:12:13 +0000 Subject: [PATCH 1/2] "remote-self" is now working for Diaspora and Twitter as well --- mod/crepair.php | 2 +- src/Model/Item.php | 28 +++++++++++++++++++++++----- src/Protocol/DFRN.php | 4 ++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mod/crepair.php b/mod/crepair.php index 29aa015726..29b00b4e3a 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -121,7 +121,7 @@ function crepair_content(App $a) // 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 // 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; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 54abc49d60..425f71822a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -925,7 +925,15 @@ class Item extends BaseObject /// @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) { 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 if ($datarray["extid"] == NETWORK_DFRN) { + logger('Already forwarded', LOGGER_DEBUG); return false; } // Prevent to forward already forwarded posts if ($datarray["app"] == $a->get_hostname()) { + logger('Already forwarded (second test)', LOGGER_DEBUG); return false; } // Only forward posts if ($datarray["verb"] != ACTIVITY_POST) { + logger('No post', LOGGER_DEBUG); return false; } if (($contact['network'] != NETWORK_FEED) && $datarray['private']) { + logger('Not public', LOGGER_DEBUG); return false; } @@ -1441,6 +1453,10 @@ class Item extends BaseObject unset($datarray['created']); unset($datarray['edited']); + + unset($datarray['network']); + unset($datarray['owner-id']); + unset($datarray['author-id']); } if ($contact['network'] != NETWORK_FEED) { @@ -1448,7 +1464,8 @@ class Item extends BaseObject unset($datarray["plink"]); $datarray["uri"] = item_new_uri($a->get_hostname(), $contact['uid'], $datarray["guid"]); $datarray["parent-uri"] = $datarray["uri"]; - $datarray["extid"] = $contact['network']; + $datarray["thr-parent"] = $datarray["uri"]; + $datarray["extid"] = NETWORK_DFRN; $urlpart = parse_url($datarray2['author-link']); $datarray["app"] = $urlpart["host"]; } else { @@ -1458,10 +1475,11 @@ class Item extends BaseObject if ($contact['network'] != NETWORK_FEED) { // Store the original post - $r = self::insert($datarray2, false, false); - logger('remote-self post original item - Contact '.$contact['url'].' return '.$r.' Item '.print_r($datarray2, true), LOGGER_DEBUG); + $result = self::insert($datarray2, false, false); + logger('remote-self post original item - Contact '.$contact['url'].' return '.$result.' Item '.print_r($datarray2, true), LOGGER_DEBUG); } else { $datarray["app"] = "Feed"; + $result = true; } // Trigger automatic reactions for addons @@ -1471,7 +1489,7 @@ class Item extends BaseObject $_SESSION["authenticated"] = true; $_SESSION["uid"] = $contact['uid']; - return true; + return $result; } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 5af1ddc5d8..92a01d2537 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2767,6 +2767,10 @@ class DFRN $posted_id = Item::insert($item, false, $notify); + if ($notify) { + $notify = $notify; + } + logger("Item was stored with id ".$posted_id, LOGGER_DEBUG); if ($item['uid'] == 0) { From dfa0dbf33f2381f4e29a0142ee80b838af0c2b9e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 4 May 2018 21:33:15 +0000 Subject: [PATCH 2/2] Ups --- src/Protocol/DFRN.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 92a01d2537..b66e1d5bfa 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2768,7 +2768,7 @@ class DFRN $posted_id = Item::insert($item, false, $notify); if ($notify) { - $notify = $notify; + $posted_id = $notify; } logger("Item was stored with id ".$posted_id, LOGGER_DEBUG);