Support for the new contact request data type

This commit is contained in:
Michael Vogel 2016-03-25 00:49:18 +01:00
parent 7e7cac19f6
commit 16ef9f4940

View file

@ -339,6 +339,9 @@ class diaspora {
case "comment": case "comment":
return self::receive_comment($importer, $sender, $fields, $msg["message"]); return self::receive_comment($importer, $sender, $fields, $msg["message"]);
case "contact":
return self::receive_contact_request($importer, $fields);
case "conversation": case "conversation":
return self::receive_conversation($importer, $msg, $fields); return self::receive_conversation($importer, $msg, $fields);
@ -360,9 +363,6 @@ class diaspora {
case "profile": case "profile":
return self::receive_profile($importer, $fields); return self::receive_profile($importer, $fields);
case "request":
return self::receive_request($importer, $fields);
case "reshare": case "reshare":
return self::receive_reshare($importer, $fields, $msg["message"]); return self::receive_reshare($importer, $fields, $msg["message"]);
@ -418,6 +418,9 @@ class diaspora {
if (in_array($type, array("signed_retraction", "relayable_retraction"))) if (in_array($type, array("signed_retraction", "relayable_retraction")))
$type = "retraction"; $type = "retraction";
if ($type == "request")
$type = "contact";
$fields = new SimpleXMLElement("<".$type."/>"); $fields = new SimpleXMLElement("<".$type."/>");
$signed_data = ""; $signed_data = "";
@ -1377,7 +1380,7 @@ class diaspora {
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora // "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
// We would accept this anyhow. // We would accept this anyhow.
if ($positive === "true") if ($positive == "true")
$verb = ACTIVITY_LIKE; $verb = ACTIVITY_LIKE;
else else
$verb = ACTIVITY_DISLIKE; $verb = ACTIVITY_DISLIKE;
@ -1738,22 +1741,43 @@ class diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_request($importer, $data) { private function receive_contact_request($importer, $data) {
$author = unxmlify($data->author); $author = unxmlify($data->author);
$recipient = unxmlify($data->recipient); $recipient = unxmlify($data->recipient);
if (!$author || !$recipient) if (!$author || !$recipient)
return false; return false;
// the current protocol version doesn't know these fields
// That means that we will assume their existance
if (isset($data->following))
$following = (unxmlify($data->following) == "true");
else
$following = true;
if (isset($data->sharing))
$sharing = (unxmlify($data->sharing) == "true");
else
$sharing = true;
$contact = self::contact_by_handle($importer["uid"],$author); $contact = self::contact_by_handle($importer["uid"],$author);
if($contact) { // perhaps we were already sharing with this person. Now they're sharing with us.
// That makes us friends.
if ($contact) {
if ($following AND $sharing) {
self::receive_request_make_friend($importer, $contact);
return true;
} else /// @todo Handle all possible variations of adding and retracting of permissions
return false;
}
// perhaps we were already sharing with this person. Now they're sharing with us. if (!$following AND $sharing AND in_array($importer["page-flags"], array(PAGE_SOAPBOX, PAGE_NORMAL))) {
// That makes us friends. logger("Author ".$author." wants to share with us - but doesn't want to listen. Request is ignored.", LOGGER_DEBUG);
return false;
self::receive_request_make_friend($importer, $contact); } elseif (!$following AND !$sharing) {
return true; logger("Author ".$author." doesn't want anything - and we don't know the author. Request is ignored.", LOGGER_DEBUG);
return false;
} }
$ret = self::person_by_handle($author); $ret = self::person_by_handle($author);
@ -1824,8 +1848,10 @@ class diaspora {
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
// we are going to change the relationship and make them a follower. // we are going to change the relationship and make them a follower.
if($importer["page-flags"] == PAGE_FREELOVE) if (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing AND $following)
$new_relation = CONTACT_IS_FRIEND; $new_relation = CONTACT_IS_FRIEND;
elseif (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing)
$new_relation = CONTACT_IS_SHARING;
else else
$new_relation = CONTACT_IS_FOLLOWER; $new_relation = CONTACT_IS_FOLLOWER;