]> git.mxchange.org Git - friendica.git/commitdiff
Added AP to many network conditions / enabling inbox processing
authorMichael <heluecht@pirati.ca>
Fri, 14 Sep 2018 16:51:32 +0000 (16:51 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 14 Sep 2018 16:51:32 +0000 (16:51 +0000)
14 files changed:
include/conversation.php
mod/contacts.php
mod/dirfind.php
src/Content/ContactSelector.php
src/Content/Widget.php
src/Model/Contact.php
src/Model/Conversation.php
src/Model/Item.php
src/Module/Inbox.php
src/Network/Probe.php
src/Protocol/ActivityPub.php
src/Protocol/PortableContact.php
src/Worker/Notifier.php
src/Worker/UpdateGContact.php

index 45e5d1caa3832ad98e04544a4ca71f2283afab3d..835d2274775f27be7dbd0f6949790f8dab3b6342 100644 (file)
@@ -556,7 +556,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                if (in_array($mode, ['community', 'contacts'])) {
                        $writable = true;
                } else {
-                       $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
+                       $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
                }
 
                if (!local_user()) {
@@ -807,7 +807,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
 
        foreach ($items as $index => $item) {
                if ($item['uid'] == 0) {
-                       $items[$index]['writable'] = in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
+                       $items[$index]['writable'] = in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
                }
        }
 
@@ -877,7 +877,7 @@ function item_photo_menu($item) {
                }
 
                if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
-                       in_array($item['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+                       in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
                        $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
                }
        } else {
index 68f68fec3b94f10f97096bd524544acd9d0554d1..031f6964c3be9cd91c827489d8b52439af869299 100644 (file)
@@ -537,7 +537,7 @@ function contacts_content(App $a, $update = 0)
                        $relation_text = '';
                }
 
-               if (!in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+               if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
                        $relation_text = "";
                }
 
@@ -559,7 +559,7 @@ function contacts_content(App $a, $update = 0)
                }
                $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : '');
 
-               $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
+               $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
 
                $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
 
@@ -968,7 +968,7 @@ function contact_conversations(App $a, $contact_id, $update)
                $profiledata = Contact::getDetailsByURL($contact["url"]);
 
                if (local_user()) {
-                       if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+                       if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                                $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
                        }
                }
@@ -992,7 +992,7 @@ function contact_posts(App $a, $contact_id)
                $profiledata = Contact::getDetailsByURL($contact["url"]);
 
                if (local_user()) {
-                       if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+                       if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                                $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]);
                        }
                }
@@ -1073,7 +1073,7 @@ function _contact_detail_for_template(array $rr)
  */
 function contact_actions($contact)
 {
-       $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
+       $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
        $contact_actions = [];
 
        // Provide friend suggestion only for Friendica contacts
index 332fe90f6c48cf5af9b0a170fb8e6783b2b2581a..4223bb6ecd34bb3e196f9c1a62acbee7ab536810 100644 (file)
@@ -54,7 +54,7 @@ function dirfind_content(App $a, $prefix = "") {
                if ((valid_email($search) && Network::isEmailDomainValid($search)) ||
                        (substr(normalise_link($search), 0, 7) == "http://")) {
                        $user_data = Probe::uri($search);
-                       $discover_user = (in_array($user_data["network"], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
+                       $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
                }
        }
 
index d5efecb8060d420564ea2020417fd70cb5432ed8..dc158cfa5f7b5429fb4d8f4766407eb8e981e0e6 100644 (file)
@@ -75,21 +75,22 @@ class ContactSelector
        public static function networkToName($s, $profile = "")
        {
                $nets = [
-                       Protocol::DFRN      => L10n::t('Friendica'),
-                       Protocol::OSTATUS   => L10n::t('OStatus'),
-                       Protocol::FEED      => L10n::t('RSS/Atom'),
-                       Protocol::MAIL      => L10n::t('Email'),
-                       Protocol::DIASPORA  => L10n::t('Diaspora'),
-                       Protocol::ZOT       => L10n::t('Zot!'),
-                       Protocol::LINKEDIN  => L10n::t('LinkedIn'),
-                       Protocol::XMPP      => L10n::t('XMPP/IM'),
-                       Protocol::MYSPACE   => L10n::t('MySpace'),
-                       Protocol::GPLUS     => L10n::t('Google+'),
-                       Protocol::PUMPIO    => L10n::t('pump.io'),
-                       Protocol::TWITTER   => L10n::t('Twitter'),
-                       Protocol::DIASPORA2 => L10n::t('Diaspora Connector'),
-                       Protocol::STATUSNET => L10n::t('GNU Social Connector'),
-                       Protocol::PNUT      => L10n::t('pnut'),
+                       Protocol::DFRN      =>   L10n::t('Friendica'),
+                       Protocol::OSTATUS   =>   L10n::t('OStatus'),
+                       Protocol::FEED      =>   L10n::t('RSS/Atom'),
+                       Protocol::MAIL      =>   L10n::t('Email'),
+                       Protocol::DIASPORA  =>   L10n::t('Diaspora'),
+                       Protocol::ZOT       =>   L10n::t('Zot!'),
+                       Protocol::LINKEDIN  =>   L10n::t('LinkedIn'),
+                       Protocol::XMPP      =>   L10n::t('XMPP/IM'),
+                       Protocol::MYSPACE   =>   L10n::t('MySpace'),
+                       Protocol::GPLUS     =>   L10n::t('Google+'),
+                       Protocol::PUMPIO    =>   L10n::t('pump.io'),
+                       Protocol::TWITTER   =>   L10n::t('Twitter'),
+                       Protocol::DIASPORA2 =>   L10n::t('Diaspora Connector'),
+                       Protocol::STATUSNET =>   L10n::t('GNU Social Connector'),
+                       Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
+                       Protocol::PNUT      =>   L10n::t('pnut'),
                ];
 
                Addon::callHooks('network_to_name', $nets);
@@ -99,7 +100,7 @@ class ContactSelector
 
                $networkname = str_replace($search, $replace, $s);
 
-               if ((in_array($s, [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
+               if ((in_array($s, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
                        $r = DBA::fetchFirst("SELECT `gserver`.`platform` FROM `gcontact`
                                        INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
                                        WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile));
index f245f0d95e064819b1b6d4ae4a37cc4540f07a72..faba55b7a860b483e28022e98909d85eaa2cb899 100644 (file)
@@ -142,10 +142,7 @@ class Widget
 
                $nets = array();
                while ($rr = DBA::fetch($r)) {
-                       /// @TODO If 'network' is not there, this triggers an E_NOTICE
-                       if ($rr['network']) {
-                               $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
-                       }
+                       $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
                }
                DBA::close($r);
 
index 1bbc0228a806a46dc7729ef1a852e7d12d53cb81..ab804ab7f103093cc440d19f795f19d4a602311d 100644 (file)
@@ -775,7 +775,7 @@ class Contact extends BaseObject
                }
 
                if ((empty($profile["addr"]) || empty($profile["name"])) && (defaults($profile, "gid", 0) != 0)
-                       && in_array($profile["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])
+                       && in_array($profile["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])
                ) {
                        Worker::add(PRIORITY_LOW, "UpdateGContact", $profile["gid"]);
                }
@@ -1088,7 +1088,7 @@ class Contact extends BaseObject
                }
 
                // Last try in gcontact for unsupported networks
-               if (!in_array($data["network"], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) {
+               if (!in_array($data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) {
                        if ($uid != 0) {
                                return 0;
                        }
@@ -1327,7 +1327,7 @@ class Contact extends BaseObject
                        return '';
                }
 
-               if (in_array($r[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
+               if (in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
                        $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))";
                } else {
                        $sql = "`item`.`uid` = ?";
index 0692a7341234f66f81530474270af6e4a64f85e8..ba50dc25e4345d0aff29e720b8b82ee81d67be5c 100644 (file)
@@ -22,6 +22,7 @@ class Conversation
        const PARCEL_DIASPORA           = 2;
        const PARCEL_SALMON             = 3;
        const PARCEL_FEED               = 4; // Deprecated
+       const PARCEL_ACTIVITYPUB        = 5;
        const PARCEL_SPLIT_CONVERSATION = 6;
        const PARCEL_TWITTER            = 67;
 
@@ -34,7 +35,7 @@ class Conversation
        public static function insert(array $arr)
        {
                if (in_array(defaults($arr, 'network', Protocol::PHANTOM),
-                               [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) {
+                       [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) {
                        $conversation = ['item-uri' => $arr['uri'], 'received' => DateTimeFormat::utcNow()];
 
                        if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
@@ -70,7 +71,8 @@ class Conversation
                                        unset($old_conv['source']);
                                }
                                // Update structure data all the time but the source only when its from a better protocol.
-                               if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
+                               if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol'])
+                                       && ($old_conv['protocol'] != 0) && ($old_conv['protocol'] != self::PARCEL_ACTIVITYPUB)) {
                                        unset($conversation['protocol']);
                                        unset($conversation['source']);
                                }
index d10a211a59511d98b579583d748c2ff004471a4f..9406df2ac86896d9e9cb2709f3d15c739e23f8c6 100644 (file)
@@ -176,7 +176,7 @@ class Item extends BaseObject
 
                // We can always comment on posts from these networks
                if (array_key_exists('writable', $row) &&
-                       in_array($row['internal-network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+                       in_array($row['internal-network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                        $row['writable'] = true;
                }
 
@@ -1352,7 +1352,7 @@ class Item extends BaseObject
                 * We have to check several networks since Friendica posts could be repeated
                 * via OStatus (maybe Diasporsa as well)
                 */
-               if (in_array($item['network'], [Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) {
+               if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) {
                        $condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?)",
                                trim($item['uri']), $item['uid'],
                                Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS];
@@ -2053,7 +2053,7 @@ class Item extends BaseObject
 
                // Only distribute public items from native networks
                $condition = ['id' => $itemid, 'uid' => 0,
-                       'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""],
+                       'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""],
                        'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false];
                $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]);
                if (!DBA::isResult($item)) {
@@ -2175,7 +2175,7 @@ class Item extends BaseObject
                }
 
                // is it an entry from a connector? Only add an entry for natively connected networks
-               if (!in_array($item["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
+               if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
                        return;
                }
 
index bb0d9ef0404d40bf3735314053465fb8bc0ee5d2..dafc418f69ef7eb39f3a044cc19fba477b9bbdcc 100644 (file)
@@ -32,6 +32,10 @@ class Inbox extends BaseModule
                $tempfile = tempnam(get_temppath(), $filename);
                file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata]));
 
-               System::httpExit(200);
+               logger('Incoming message stored under ' . $tempfile);
+
+               ActivityPub::processInbox($postdata, $_SERVER);
+
+               System::httpExit(202);
        }
 }
index d48617f43bbe5818032fa0db76eed24c382024a4..2cf91486bbdd8428ac51f07c1a8061163c478198 100644 (file)
@@ -331,6 +331,8 @@ class Probe
 
                if ($network != Protocol::ACTIVITYPUB) {
                        $data = self::detect($uri, $network, $uid);
+               } else {
+                       $data = null;
                }
 
                if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) {
index 12c849d5b4c64d5ebccd5d33a1155c9ff91b836c..71e554d8e5fc4303564305a7fd047e9225cc8eec 100644 (file)
@@ -10,11 +10,14 @@ use Friendica\BaseObject;
 use Friendica\Util\Network;
 use Friendica\Util\HTTPSignature;
 use Friendica\Core\Protocol;
+use Friendica\Model\Conversation;
+use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Crypto;
 use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
 use Friendica\Network\Probe;
 
 /**
@@ -474,6 +477,25 @@ class ActivityPub
                return $profile;
        }
 
+       public static function processInbox($body, $header)
+       {
+               logger('Incoming message', LOGGER_DEBUG);
+
+               if (!self::verifySignature($body, $header)) {
+                       logger('Invalid signature, message will be discarded.', LOGGER_DEBUG);
+                       return;
+               }
+
+               $activity = json_decode($body, true);
+
+               if (!is_array($activity)) {
+                       logger('Invalid body.', LOGGER_DEBUG);
+                       return;
+               }
+
+               self::processActivity($activity, $body);
+       }
+
        public static function fetchOutbox($url)
        {
                $data = self::fetchContent($url);
@@ -493,26 +515,31 @@ class ActivityPub
                }
 
                foreach ($items as $activity) {
-                       self::processActivity($activity, $url);
+                       self::processActivity($activity);
                }
        }
 
-       function processActivity($activity, $url)
+       function processActivity($activity, $body = '')
        {
                if (empty($activity['type'])) {
+                       logger('Empty type', LOGGER_DEBUG);
                        return;
                }
 
                if (empty($activity['object'])) {
+                       logger('Empty object', LOGGER_DEBUG);
                        return;
                }
 
                if (empty($activity['actor'])) {
+                       logger('Empty actor', LOGGER_DEBUG);
                        return;
+
                }
 
                $actor = self::processElement($activity, 'actor', 'id');
                if (empty($actor)) {
+                       logger('Empty actor - 2', LOGGER_DEBUG);
                        return;
                }
 
@@ -521,11 +548,13 @@ class ActivityPub
                } elseif (!empty($activity['object']['id'])) {
                        $object_url = $activity['object']['id'];
                } else {
+                       logger('No object found', LOGGER_DEBUG);
                        return;
                }
 
                $receivers = self::getReceivers($activity);
                if (empty($receivers)) {
+                       logger('No receivers found', LOGGER_DEBUG);
                        return;
                }
 
@@ -545,6 +574,7 @@ class ActivityPub
                // To-Do?
                unset($activity['context']);
                unset($activity['location']);
+               unset($activity['signature']);
 
                // handled
                unset($activity['to']);
@@ -559,17 +589,19 @@ class ActivityPub
                unset($activity['instrument']);
                unset($activity['inReplyTo']);
 
+/*
                if (!empty($activity)) {
                        echo "Activity\n";
                        print_r($activity);
                        die($url."\n");
                }
-
+*/
                $activity = $structure;
                // ----------------------------------
 
-               $item = self::fetchObject($object_url, $url);
+               $item = self::fetchObject($object_url, $activity['object']);
                if (empty($item)) {
+                       logger("Object data couldn't be processed", LOGGER_DEBUG);
                        return;
                }
 
@@ -579,28 +611,32 @@ class ActivityPub
 
                $item['receiver'] = array_merge($item['receiver'], $receivers);
 
+               logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG);
+
                switch ($activity['type']) {
                        case 'Create':
                        case 'Update':
-                               self::createItem($item);
+                               self::createItem($item, $body);
                                break;
 
                        case 'Announce':
-                               self::announceItem($item);
+                               self::announceItem($item, $body);
                                break;
 
                        case 'Like':
                        case 'Dislike':
-                               self::activityItem($item);
+                               self::activityItem($item, $body);
                                break;
 
                        case 'Follow':
                                break;
 
                        default:
-                               echo "Unknown activity: ".$activity['type']."\n";
+                               logger('Unknown activity: ' . $activity['type'], LOGGER_DEBUG);
+/*                             echo "Unknown activity: ".$activity['type']."\n";
                                print_r($item);
                                die();
+*/
                                break;
                }
        }
@@ -626,11 +662,11 @@ class ActivityPub
                                }
 
                                $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
-                               $contact = DBA::selectFirst('contact', ['id'], $condition);
+                               $contact = DBA::selectFirst('contact', ['uid'], $condition);
                                if (!DBA::isResult($contact)) {
                                        continue;
                                }
-                               $receivers[$receiver] = $contact['id'];
+                               $receivers[$receiver] = $contact['uid'];
                        }
                }
                return $receivers;
@@ -653,67 +689,78 @@ class ActivityPub
                if (!empty($activity['instrument'])) {
                        $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service');
                }
-
+/*
                // Remove all "null" fields
                foreach ($item as $field => $content) {
                        if (is_null($content)) {
                                unset($item[$field]);
                        }
                }
-
+*/
                return $item;
        }
 
-       private static function fetchObject($object_url, $url)
+       private static function fetchObject($object_url, $object = [])
        {
                $data = self::fetchContent($object_url);
                if (empty($data)) {
-                       return false;
+                       $data = $object;
+                       if (empty($data)) {
+                               logger('Empty content');
+                               return false;
+                       } else {
+                               logger('Using provided object');
+                       }
                }
 
                if (empty($data['type'])) {
+                       logger('Empty type');
                        return false;
                } else {
                        $type = $data['type'];
+                       logger('Type ' . $type);
                }
 
                if (in_array($type, ['Note', 'Article', 'Video'])) {
-                       $common = self::processCommonData($data, $url);
+                       $common = self::processCommonData($data);
                }
 
                switch ($type) {
                        case 'Note':
-                               return array_merge($common, self::processNote($data, $url));
+                               return array_merge($common, self::processNote($data));
                        case 'Article':
-                               return array_merge($common, self::processArticle($data, $url));
+                               return array_merge($common, self::processArticle($data));
                        case 'Video':
-                               return array_merge($common, self::processVideo($data, $url));
+                               return array_merge($common, self::processVideo($data));
 
                        case 'Announce':
                                if (empty($data['object'])) {
                                        return false;
                                }
-                               return self::fetchObject($data['object'], $url);
+                               return self::fetchObject($data['object']);
 
                        case 'Person':
                        case 'Tombstone':
                                break;
 
                        default:
-                               echo "Unknown object type: ".$data['type']."\n";
+                               logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG);
+/*                             echo "Unknown object type: ".$data['type']."\n";
                                print_r($data);
                                die($url."\n");
+*/
                                break;
                }
        }
 
-       private static function processCommonData(&$object, $url)
+       private static function processCommonData(&$object)
        {
                if (empty($object['id']) || empty($object['attributedTo'])) {
                        return false;
                }
 
                $item = [];
+               $item['type'] = $object['type'];
                $item['uri'] = $object['id'];
 
                if (!empty($object['inReplyTo'])) {
@@ -789,7 +836,7 @@ class ActivityPub
                return $item;
        }
 
-       private static function processNote($object, $url)
+       private static function processNote($object)
        {
                $item = [];
 
@@ -810,33 +857,33 @@ class ActivityPub
                unset($object['quoteUrl']);
                unset($object['statusnetConversationId']);
 
-               if (empty($object))
+//             if (empty($object))
                        return $item;
-
+/*
                echo "Unknown Note\n";
                print_r($object);
                print_r($item);
                die($url."\n");
-
+*/
                return [];
        }
 
-       private static function processArticle($object, $url)
+       private static function processArticle($object)
        {
                $item = [];
 
-               if (empty($object))
+//             if (empty($object))
                        return $item;
-
+/*
                echo "Unknown Article\n";
                print_r($object);
                print_r($item);
                die($url."\n");
-
+*/
                return [];
        }
 
-       private static function processVideo($object, $url)
+       private static function processVideo($object)
        {
                $item = [];
 
@@ -857,14 +904,14 @@ class ActivityPub
                unset($object['shares']);
                unset($object['comments']);
 
-               if (empty($object))
+//             if (empty($object))
                        return $item;
-
+/*
                echo "Unknown Video\n";
                print_r($object);
                print_r($item);
                die($url."\n");
-
+*/
                return [];
        }
 
@@ -903,9 +950,55 @@ class ActivityPub
                return false;
        }
 
-       private static function createItem($item)
+       private static function createItem($activity, $body)
        {
-//             print_r($item);
+//             print_r($activity);
+
+               $item = [];
+               $item['network'] = Protocol::ACTIVITYPUB;
+               $item['wall'] = 0;
+               $item['origin'] = 0;
+//             $item['private'] = 0;
+               $item['gravity'] = GRAVITY_COMMENT;
+               $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true);
+               $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true);
+               $item['uri'] = $activity['uri'];
+               $item['parent-uri'] = $activity['reply-to-uri'];
+               $item['verb'] = ACTIVITY_POST; // Todo
+               $item['object-type'] = ACTIVITY_OBJ_NOTE; // Todo
+               $item['created'] = $activity['published'];
+               $item['edited'] = $activity['updated'];
+               $item['guid'] = $activity['uuid'];
+               $item['title'] = HTML::toBBCode($activity['name']);
+               $item['content-warning'] = HTML::toBBCode($activity['summary']);
+               $item['body'] = HTML::toBBCode($activity['content']);
+               $item['location'] = $activity['location'];
+//             $item['attach'] = $activity['attachments'];
+//             $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
+               $item['app'] = $activity['service'];
+               $item['plink'] = $activity['alternate-url'];
+
+               $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
+               $item['source'] = $body;
+//             $item[''] = $activity['context'];
+               $item['conversation-uri'] = $activity['conversation'];
+
+               foreach ($activity['receiver'] as $receiver) {
+                       $item['uid'] = $receiver;
+                       $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
+
+                       if (($receiver != 0) && empty($item['contact-id'])) {
+                               $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true);
+                       }
+
+                       $item_id = Item::insert($item);
+                       logger('Storing for user ' . $item['uid'] . ': ' . $item_id);
+                       if (!empty($item_id) && ($item['uid'] == 0)) {
+                               Item::distribute($item_id);
+                       }
+//print_r($item);
+               }
+//             $item[''] = $activity['receiver'];
        }
 
        private static function announceItem($item)
index 20ee77a07cbdf5a0ec11d8081897c2801f2ac23c..61274dc2be86a1e24951b21d9799f6e1b36e7a4a 100644 (file)
@@ -333,7 +333,7 @@ class PortableContact
                        $server_url = normalise_link(self::detectServer($profile));
                }
 
-               if (!in_array($gcontacts[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
+               if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
                        logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
                        return false;
                }
index 61eaba388b2d365a58829bcf4abddcb1bda54874..55f80c94d77359dec401efbe75ec0be67b78e517 100644 (file)
@@ -363,9 +363,9 @@ class Notifier
                                }
 
                                // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora
-                               $networks = [Protocol::OSTATUS, Protocol::DFRN];
+                               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN];
                        } else {
-                               $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL];
+                               $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL];
                        }
                } else {
                        $public_message = false;
index f2919e4a750e148e0e8531171d9b786e8a1dc3c5..67362917c379418ed2d98652e332e99b351ffd58 100644 (file)
@@ -29,13 +29,13 @@ class UpdateGContact
                        return;
                }
 
-               if (!in_array($r[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+               if (!in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                        return;
                }
 
                $data = Probe::uri($r[0]["url"]);
 
-               if (!in_array($data["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+               if (!in_array($data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                        if ($r[0]["server_url"] != "") {
                                PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
                        }