]> git.mxchange.org Git - friendica.git/blobdiff - include/ostatus.php
Merge pull request #2394 from annando/1603-federation
[friendica.git] / include / ostatus.php
index caaeec84f7dd974db3a9b5c079064f7f60e9cbf4..5c5016d0fce9ab8044c1d22c6dd560fdf108c3ff 100644 (file)
@@ -164,8 +164,6 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
                        update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
                }
 
-
-               /// @todo Add the "addr" field
                $contact["generation"] = 2;
                $contact["photo"] = $author["author-avatar"];
                update_gcontact($contact);
@@ -626,6 +624,59 @@ function check_conversations($mentions = false, $override = false) {
        set_config('system','ostatus_last_poll', time());
 }
 
+/**
+ * @brief Updates the gcontact table with actor data from the conversation
+ *
+ * @param object $actor The actor object that contains the contact data
+ */
+function ostatus_conv_fetch_actor($actor) {
+
+       // We set the generation to "3" since the data here is not as reliable as the data we get on other occasions
+       $contact = array("network" => NETWORK_OSTATUS, "generation" => 3);
+
+       if (isset($actor->url))
+               $contact["url"] = $actor->url;
+
+       if (isset($actor->displayName))
+               $contact["name"] = $actor->displayName;
+
+       if (isset($actor->portablecontacts_net->displayName))
+               $contact["name"] = $actor->portablecontacts_net->displayName;
+
+       if (isset($actor->portablecontacts_net->preferredUsername))
+               $contact["nick"] = $actor->portablecontacts_net->preferredUsername;
+
+       if (isset($actor->id))
+               $contact["alias"] = $actor->id;
+
+       if (isset($actor->summary))
+               $contact["about"] = $actor->summary;
+
+       if (isset($actor->portablecontacts_net->note))
+               $contact["about"] = $actor->portablecontacts_net->note;
+
+       if (isset($actor->portablecontacts_net->addresses->formatted))
+               $contact["location"] = $actor->portablecontacts_net->addresses->formatted;
+
+
+       if (isset($actor->image->url))
+               $contact["photo"] = $actor->image->url;
+
+       if (isset($actor->image->width))
+               $avatarwidth = $actor->image->width;
+
+       if (is_array($actor->status_net->avatarLinks))
+               foreach ($actor->status_net->avatarLinks AS $avatar) {
+                       if ($avatarsize < $avatar->width) {
+                               $contact["photo"] = $avatar->url;
+                               $avatarsize = $avatar->width;
+                       }
+               }
+
+       update_gcontact($contact);
+}
+
+
 function ostatus_completion($conversation_url, $uid, $item = array()) {
 
        $a = get_app();
@@ -729,6 +780,9 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
 
        foreach ($items as $single_conv) {
 
+               // Update the gcontact table
+               ostatus_conv_fetch_actor($single_conv->actor);
+
                // Test - remove before flight
                //$tempfile = tempnam(get_temppath(), "conversation");
                //file_put_contents($tempfile, json_encode($single_conv));
@@ -1312,6 +1366,10 @@ function ostatus_add_author($doc, $owner) {
 function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) {
        $a = get_app();
 
+       if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
+               logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
+       }
+
        $is_repeat = false;
 
 /*     if (!$repeat) {