AP: We now transmit and process events

This commit is contained in:
Michael 2018-10-26 04:13:26 +00:00
parent dbfe5c9d2a
commit cbc417114d
3 changed files with 84 additions and 12 deletions

View 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;
@ -172,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
*
@ -238,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);
}