]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
AP: We now transmit and process events
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index 69b70249ccbee0966804c7362630367beae01b63..e7073ab8786be716bc8245a3da02a003bb388edd 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Model\Conversation;
 use Friendica\Model\Contact;
 use Friendica\Model\APContact;
 use Friendica\Model\Item;
+use Friendica\Model\Event;
 use Friendica\Model\User;
 use Friendica\Content\Text\HTML;
 use Friendica\Util\JsonLD;
@@ -17,10 +18,7 @@ use Friendica\Core\Config;
 use Friendica\Protocol\ActivityPub;
 
 /**
- * ActivityPub Protocol class
- *
- * To-Do:
- * - Store Diaspora signature
+ * ActivityPub Processor Protocol class
  */
 class Processor
 {
@@ -175,6 +173,38 @@ class Processor
                self::postItem($activity, $item);
        }
 
+       /**
+        * Create an event
+        *
+        * @param array  $activity Activity array
+        */
+       public static function createEvent($activity, $item)
+       {
+               $event['summary'] = $activity['name'];
+               $event['desc'] = $activity['content'];
+               $event['start'] = $activity['start-time'];
+               $event['finish'] = $activity['end-time'];
+               $event['nofinish'] = empty($event['finish']);
+               $event['location'] = $activity['location'];
+               $event['adjust'] = true;
+               $event['cid'] = $item['contact-id'];
+               $event['uid'] = $item['uid'];
+               $event['uri'] = $item['uri'];
+               $event['edited'] = $item['edited'];
+               $event['private'] = $item['private'];
+               $event['guid'] = $item['guid'];
+               $event['plink'] = $item['plink'];
+
+               $condition = ['uri' => $item['uri'], 'uid' => $item['uid']];
+               $ev = DBA::selectFirst('event', ['id'], $condition);
+               if (DBA::isResult($ev)) {
+                       $event['id'] = $ev['id'];
+               }
+
+               $event_id = Event::store($event);
+               logger('Event '.$event_id.' was stored', LOGGER_DEBUG);
+       }
+
        /**
         * Creates an item post
         *
@@ -241,6 +271,10 @@ class Processor
                                $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true);
                        }
 
+                       if ($activity['object_type'] == 'as:Event') {
+                               self::createEvent($activity, $item);
+                       }
+
                        $item_id = Item::insert($item);
                        logger('Storing for user ' . $item['uid'] . ': ' . $item_id);
                }
@@ -272,7 +306,7 @@ class Processor
                $activity['cc'] = defaults($object, 'cc', []);
                $activity['actor'] = $child['author'];
                $activity['object'] = $object;
-               $activity['published'] = $object['published'];
+               $activity['published'] = defaults($object, 'published', $child['published']);
                $activity['type'] = 'Create';
 
                $ldactivity = JsonLD::compact($activity);
@@ -308,6 +342,9 @@ class Processor
                $item = ['author-id' => Contact::getIdForURL($activity['actor']),
                        'author-link' => $activity['actor']];
 
+               // Ensure that the contact has got the right network type
+               self::switchContact($item['author-id']);
+
                Contact::addRelationship($owner, $contact, $item);
                $cid = Contact::getIdForURL($activity['actor'], $uid);
                if (empty($cid)) {