Now comments are really working

This commit is contained in:
Michael 2017-05-03 05:22:39 +00:00
parent 83e50385a8
commit e1ab0c9475

View File

@ -333,6 +333,23 @@ class Diaspora {
return false; 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 // Now distribute it to the followers
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s') (SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
@ -346,9 +363,10 @@ class Diaspora {
logger("delivering to: ".$rr["username"]); logger("delivering to: ".$rr["username"]);
self::dispatch($rr, $msg); 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 { } else {
// Use a dummy importer to import the data for the public copy // 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); $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
$message_id = self::dispatch($importer, $msg); $message_id = self::dispatch($importer, $msg);
} }
@ -377,11 +395,6 @@ class Diaspora {
$type = $fields->getName(); $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); logger("Received message type ".$type." from ".$sender." for user ".$importer["uid"], LOGGER_DEBUG);
switch ($type) { switch ($type) {
@ -828,10 +841,13 @@ class Diaspora {
logger("defining user ".$contact["nick"]." as friend"); logger("defining user ".$contact["nick"]." as friend");
} }
// We don't seem to like that person
if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) { if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) {
return false; return false;
// We are following this person? Then it is okay
} elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) { } elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) {
return true; return true;
// Is it a post to a community? That's good
} elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) { } elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) {
return true; return true;
} }
@ -860,7 +876,7 @@ class Diaspora {
if ($is_comment) { if ($is_comment) {
return $importer; return $importer;
} else { } 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 * @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); $item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid);
if (dbm::is_result($item)) { if (dbm::is_result($item)) {
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG); 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 * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']);
if (dbm::is_result($contact)) { if (dbm::is_result($contact)) {
$importer = $contact; return $contact;
} }
} }
return $importer; return false;
} }
/** /**
@ -1282,11 +1297,6 @@ class Diaspora {
$thr_uri = ""; $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); $contact = self::allowed_contact_by_handle($importer, $sender, true);
if (!$contact) { if (!$contact) {
return false; return false;
@ -1631,11 +1641,6 @@ class Diaspora {
if (!in_array($parent_type, array("Post", "Comment"))) if (!in_array($parent_type, array("Post", "Comment")))
return false; 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); $contact = self::allowed_contact_by_handle($importer, $sender, true);
if (!$contact) if (!$contact)
return false; return false;