aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/Activity.php13
-rw-r--r--include/event.php124
2 files changed, 93 insertions, 44 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 190777b5f..227739fea 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2344,7 +2344,7 @@ class Activity {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']);
}
- if ($act->type === 'Invite' && $act->objprop('type') === 'Event') {
+ if (in_array($act->type, ['Invite', 'Create']) && $act->objprop('type') === 'Event') {
$s['mid'] = $s['parent_mid'] = $act->id;
}
@@ -2899,6 +2899,10 @@ class Activity {
set_iconfig($s, 'activitypub', 'recips', $act->raw_recips);
}
+ if ($act->objprop('type') === 'Event' && $act->objprop('timezone')) {
+ set_iconfig($s, 'event', 'timezone', $act->objprop('timezone'), true);
+ }
+
$hookinfo = [
'act' => $act,
's' => $s
@@ -3257,7 +3261,12 @@ class Activity {
}
}
- if (is_array($x) && $x['item_id']) {
+ if ($x['success']) {
+
+ if (check_item_source($channel['channel_id'], $x['item']) && in_array($x['item']['obj_type'], ['Event', ACTIVITY_OBJ_EVENT])) {
+ event_addtocal($x['item_id'], $channel['channel_id']);
+ }
+
if ($is_child_node) {
if ($item['owner_xchan'] === $channel['channel_hash']) {
// We are the owner of this conversation, so send all received comments back downstream
diff --git a/include/event.php b/include/event.php
index 894a1e4f7..745469064 100644
--- a/include/event.php
+++ b/include/event.php
@@ -9,6 +9,7 @@ use Sabre\VObject;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
+use Zotlabs\Access\AccessList;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
@@ -718,56 +719,95 @@ function event_addtocal($item_id, $uid) {
$item = $r[0];
- $ev = bbtoevent($r[0]['body']);
+ $ev = parse_event_object($item['obj']);
- if(x($ev,'summary') && x($ev,'dtstart')) {
- $ev['event_xchan'] = $item['author_xchan'];
- $ev['uid'] = $channel['channel_id'];
- $ev['account'] = $channel['channel_account_id'];
- $ev['edited'] = $item['edited'];
- $ev['mid'] = $item['mid'];
- $ev['private'] = $item['item_private'];
+ // if we could not parse the object, parse try to parse the body bbcode
+ if (!$ev) {
+ $ev = bbtoevent($item['body']);
+ }
- // is this an edit?
+ if (!$ev) {
+ return false;
+ }
- if($item['resource_type'] === 'event' && (! $ev['event_hash'])) {
- $ev['event_hash'] = $item['resource_id'];
- }
+ $ev['event_xchan'] = $item['author_xchan'];
+ $ev['uid'] = $channel['channel_id'];
+ $ev['account'] = $channel['channel_account_id'];
+ $ev['edited'] = $item['edited'];
+ $ev['mid'] = $item['mid'];
+ $ev['private'] = $item['item_private'];
- if($ev['private'])
- $ev['allow_cid'] = '<' . $channel['channel_hash'] . '>';
- else {
- $acl = new Zotlabs\Access\AccessList($channel);
- $x = $acl->get();
- $ev['allow_cid'] = $x['allow_cid'];
- $ev['allow_gid'] = $x['allow_gid'];
- $ev['deny_cid'] = $x['deny_cid'];
- $ev['deny_gid'] = $x['deny_gid'];
- }
+ if($item['resource_type'] === 'event' && (! $ev['event_hash'])) {
+ $ev['event_hash'] = $item['resource_id'];
+ }
- $event = event_store_event($ev);
- if($event) {
- $r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d",
- dbesc($event['event_hash']),
- intval($item['id']),
- intval($channel['channel_id'])
- );
+ if($ev['private']) {
+ $ev['allow_cid'] = '<' . $channel['channel_hash'] . '>';
+ $ev['allow_gid'] = '';
+ $ev['deny_cid'] = '';
+ $ev['deny_gid'] = '';
+ }
+ else {
+ $acl = new AccessList($channel);
+ $x = $acl->get();
+ $ev['allow_cid'] = $x['allow_cid'];
+ $ev['allow_gid'] = $x['allow_gid'];
+ $ev['deny_cid'] = $x['deny_cid'];
+ $ev['deny_gid'] = $x['deny_gid'];
+ }
- $item['resource_id'] = $event['event_hash'];
- $item['resource_type'] = 'event';
+ $event = event_store_event($ev);
+ if($event) {
+ $r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d",
+ dbesc($event['event_hash']),
+ intval($item['id']),
+ intval($channel['channel_id'])
+ );
- $i = array($item);
- xchan_query($i);
- $sync_item = fetch_post_tags($i);
- $z = q("select * from event where event_hash = '%s' and uid = %d limit 1",
- dbesc($event['event_hash']),
- intval($channel['channel_id'])
- );
- if($z) {
- Libsync::build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
- }
- return true;
+ $item['resource_id'] = $event['event_hash'];
+ $item['resource_type'] = 'event';
+
+ $i = [$item];
+
+ xchan_query($i);
+ $sync_item = fetch_post_tags($i);
+
+ $z = q("select * from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+
+ if($z) {
+ libsync::build_sync_packet($channel['channel_id'], ['event_item' => [encode_item($sync_item[0], true)], 'event' => $z]);
}
+
+ return true;
+ }
+
+}
+
+function parse_event_object($event_object_json) {
+
+ $object = json_decode($event_object_json, true);
+
+ $tz = $object['timezone'] ?? 'UTC';
+
+ $ev['summary'] = $object['summary'] ?? $object['name'] ?? '';
+ $ev['description'] = html2bbcode($content['content']) ?? '';
+ $ev['dtstart'] = $object['startTime'] ? datetime_convert('UTC', 'UTC', $object['startTime']) : '';
+ $ev['dtend'] = $object['endTime'] ? datetime_convert('UTC', 'UTC', $object['endTime']) : $ev['dtstart'];
+ $ev['location'] = $object['location']['name'] ?? '';
+ $ev['event_hash'] = $object['uuid'] ?? $object['diaspora:guid'] ?? uuid_from_url($object['id']);
+ $ev['timezone'] = $tz;
+ $ev['adjust'] = (strpos($object['startTime'], 'Z') !== false || !empty($object['dfrn:adjust']) || $tz !== 'UTC');
+
+ $ev['nofinish'] = 0;
+ if($ev['dtend'] === $ev['dtstart']) {
+ $ev['nofinish'] = 1;
+ }
+
+ if ($ev['summary'] && $ev['dtstart']) {
+ return $ev;
}
return false;