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;
use Friendica\Protocol\ActivityPub;
/**
- * ActivityPub Protocol class
- *
- * To-Do:
- * - Store Diaspora signature
+ * ActivityPub Processor Protocol class
*/
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
*
$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);
}
$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);
$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)) {