case "comment":
return self::receive_comment($importer, $sender, $fields, $msg["message"]);
+ case "contact":
+ return self::receive_contact_request($importer, $fields);
+
case "conversation":
return self::receive_conversation($importer, $msg, $fields);
case "profile":
return self::receive_profile($importer, $fields);
- case "request":
- return self::receive_request($importer, $fields);
-
case "reshare":
return self::receive_reshare($importer, $fields, $msg["message"]);
if (in_array($type, array("signed_retraction", "relayable_retraction")))
$type = "retraction";
+ if ($type == "request")
+ $type = "contact";
+
$fields = new SimpleXMLElement("<".$type."/>");
$signed_data = "";
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
// We would accept this anyhow.
- if ($positive === "true")
+ if ($positive == "true")
$verb = ACTIVITY_LIKE;
else
$verb = ACTIVITY_DISLIKE;
*
* @return bool Success
*/
- private function receive_request($importer, $data) {
+ private function receive_contact_request($importer, $data) {
$author = unxmlify($data->author);
$recipient = unxmlify($data->recipient);
if (!$author || !$recipient)
return false;
- $contact = self::contact_by_handle($importer["uid"],$author);
+ // 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($contact) {
+ if (isset($data->sharing))
+ $sharing = (unxmlify($data->sharing) == "true");
+ else
+ $sharing = true;
- // perhaps we were already sharing with this person. Now they're sharing with us.
- // That makes us friends.
+ $contact = self::contact_by_handle($importer["uid"],$author);
- self::receive_request_make_friend($importer, $contact);
- return true;
+ // 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;
+ }
+
+ if (!$following AND $sharing AND in_array($importer["page-flags"], array(PAGE_SOAPBOX, PAGE_NORMAL))) {
+ logger("Author ".$author." wants to share with us - but doesn't want to listen. Request is ignored.", LOGGER_DEBUG);
+ return false;
+ } elseif (!$following AND !$sharing) {
+ 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);
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
// 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;
+ elseif (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing)
+ $new_relation = CONTACT_IS_SHARING;
else
$new_relation = CONTACT_IS_FOLLOWER;