From 99a54df8d8afac3d3987b5b467512a332eea0345 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 May 2017 19:48:11 +0000 Subject: [PATCH 1/3] Follow up for PR 3421 - some improvements --- include/diaspora.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index d5c83d7f5b..c250e2252b 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -344,13 +344,13 @@ class Diaspora { if (dbm::is_result($r)) { foreach ($r as $rr) { logger("delivering to: ".$rr["username"]); - self::dispatch($rr,$msg); + self::dispatch($rr, $msg); } } else { // Use a dummy importer to import the data for the public copy // or for comments from unknown people $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE); - $message_id = self::dispatch($importer,$msg); + $message_id = self::dispatch($importer, $msg); } return $message_id; @@ -378,7 +378,7 @@ class Diaspora { $type = $fields->getName(); $social_relay = Config::get('system', 'relay_subscribe', false); - if (!$social_relay AND ($type == 'message')) { + if (!$social_relay AND (in_array($type, array('status_message', 'reshare')))) { logger("Unwanted message from ".$sender." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG); } @@ -828,17 +828,17 @@ class Diaspora { logger("defining user ".$contact["nick"]." as friend"); } - if (($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"])) + if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) { return false; - if ($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND) + } elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) { return true; - if ($contact["rel"] == CONTACT_IS_FOLLOWER) - if (($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment) - return true; - - // Messages for the global users are always accepted - if ($importer["uid"] == 0) + } elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) { return true; + } + // Messages for the global users and comments are always accepted + if (($importer["uid"] == 0) || $is_comment) { + return true; + } return false; } @@ -1240,7 +1240,7 @@ class Diaspora { if (dbm::is_result($item)) { logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG); - $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']); + $contact = dba::fetch_first("SELECT `uid`, `page-flags` FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']); if (dbm::is_result($contact)) { $importer = $contact; } @@ -1626,6 +1626,11 @@ class Diaspora { if (!in_array($parent_type, array("Post", "Comment"))) return false; + // Find the best importer when there was no importer found + if ($importer["uid"] == 0) { + $importer = self::importer_for_comment($importer, $parent_guid); + } + $contact = self::allowed_contact_by_handle($importer, $sender, true); if (!$contact) return false; From 83e50385a8f69cc1185298ba02db9c738a1af2f8 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 May 2017 21:06:56 +0000 Subject: [PATCH 2/3] Hopefully this fixes the workflow --- include/diaspora.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index c250e2252b..520aa8caa4 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -856,7 +856,12 @@ class Diaspora { $contact = self::contact_by_handle($importer["uid"], $handle); if (!$contact) { logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found"); - return false; + // If a contact isn't found, we accept it anyway if it is a comment + if ($is_comment) { + return $importer; + } else { + return true; + } } if (!self::post_allow($importer, $contact, $is_comment)) { @@ -1111,9 +1116,9 @@ class Diaspora { $cid = $r[0]["id"]; $network = $r[0]["network"]; - // We are receiving content from a user that is about to be terminated + // We are receiving content from a user that possibly is about to be terminated // This means the user is vital, so we remove a possible termination date. - unmark_for_death($contact); + unmark_for_death($r[0]); } else { $cid = $contact["id"]; $network = NETWORK_DIASPORA; @@ -1240,7 +1245,7 @@ class Diaspora { if (dbm::is_result($item)) { logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG); - $contact = dba::fetch_first("SELECT `uid`, `page-flags` FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']); + $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']); if (dbm::is_result($contact)) { $importer = $contact; } From e1ab0c947546baefaafc98f45f71aefe47b2ba0c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 May 2017 05:22:39 +0000 Subject: [PATCH 3/3] Now comments are really working --- include/diaspora.php | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 520aa8caa4..8640e2d6a7 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -333,6 +333,23 @@ class Diaspora { return false; } + if (!self::valid_posting($msg, $fields)) { + logger("Invalid posting"); + return false; + } + + // Is it a an action (comment, like, ...) for our own post? + if (isset($fields->parent_guid)) { + $guid = notags(unxmlify($fields->parent_guid)); + + $importer = self::importer_for_guid($guid); + if (is_array($importer)) { + logger("delivering to origin: ".$importer["name"]); + $message_id = self::dispatch($importer, $msg); + return $message_id; + } + } + // Now distribute it to the followers $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN (SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s') @@ -346,9 +363,10 @@ class Diaspora { logger("delivering to: ".$rr["username"]); self::dispatch($rr, $msg); } + } elseif (!Config::get('system', 'relay_subscribe', false)) { + logger("Unwanted message from ".$sender." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG); } else { // Use a dummy importer to import the data for the public copy - // or for comments from unknown people $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE); $message_id = self::dispatch($importer, $msg); } @@ -377,11 +395,6 @@ class Diaspora { $type = $fields->getName(); - $social_relay = Config::get('system', 'relay_subscribe', false); - if (!$social_relay AND (in_array($type, array('status_message', 'reshare')))) { - logger("Unwanted message from ".$sender." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG); - } - logger("Received message type ".$type." from ".$sender." for user ".$importer["uid"], LOGGER_DEBUG); switch ($type) { @@ -828,10 +841,13 @@ class Diaspora { logger("defining user ".$contact["nick"]." as friend"); } + // We don't seem to like that person if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) { return false; + // We are following this person? Then it is okay } elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) { return true; + // Is it a post to a community? That's good } elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) { return true; } @@ -860,7 +876,7 @@ class Diaspora { if ($is_comment) { return $importer; } else { - return true; + return false; } } @@ -1233,24 +1249,23 @@ class Diaspora { } /** - * @brief Find the best importer for a comment + * @brief Find the best importer for a comment, like, ... * - * @param array $importer Array of the importer user * @param string $guid The guid of the item * - * @return array the importer that fits the best + * @return array|boolean the origin owner of that post - or false */ - private static function importer_for_comment($importer, $guid) { + private static function importer_for_guid($guid) { $item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid); if (dbm::is_result($item)) { logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG); $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']); if (dbm::is_result($contact)) { - $importer = $contact; + return $contact; } } - return $importer; + return false; } /** @@ -1282,11 +1297,6 @@ class Diaspora { $thr_uri = ""; } - // Find the best importer when there was no importer found - if ($importer["uid"] == 0) { - $importer = self::importer_for_comment($importer, $parent_guid); - } - $contact = self::allowed_contact_by_handle($importer, $sender, true); if (!$contact) { return false; @@ -1631,11 +1641,6 @@ class Diaspora { if (!in_array($parent_type, array("Post", "Comment"))) return false; - // Find the best importer when there was no importer found - if ($importer["uid"] == 0) { - $importer = self::importer_for_comment($importer, $parent_guid); - } - $contact = self::allowed_contact_by_handle($importer, $sender, true); if (!$contact) return false;