From 8e074a5fe4b90d2d1a6e6b9300f6005d010839f8 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Aug 2021 10:24:14 +0000 Subject: [PATCH] Simplify event storing --- src/Model/Event.php | 30 +++++++++++++++++++++++--- src/Model/Item.php | 2 +- src/Protocol/ActivityPub/Processor.php | 2 +- src/Protocol/DFRN.php | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Model/Event.php b/src/Model/Event.php index 924fc7eca3..331a77e3f1 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -337,12 +337,12 @@ class Event public static function getItemArrayForId(int $event_id, array $item = []):array { if (empty($event_id)) { - return []; + return $item; } $event = DBA::selectFirst('event', [], ['id' => $event_id]); if ($event['type'] != 'event') { - return []; + return $item; } if ($event['cid']) { @@ -375,7 +375,7 @@ class Event $item['allow_gid'] = $event['allow_gid']; $item['deny_cid'] = $event['deny_cid']; $item['deny_gid'] = $event['deny_gid']; - $item['private'] = intval($event['private'] ?? 0);; + $item['private'] = intval($event['private'] ?? 0); $item['visible'] = 1; $item['verb'] = Activity::POST; $item['object-type'] = Activity\ObjectType::EVENT; @@ -391,6 +391,30 @@ class Event return $item; } + public static function getItemArrayForImportedId(int $event_id, array $item = []):array + { + if (empty($event_id)) { + return $item; + } + + $event = DBA::selectFirst('event', [], ['id' => $event_id]); + if ($event['type'] != 'event') { + return $item; + } + + $item['post-type'] = Item::PT_EVENT; + $item['title'] = ''; + $item['object-type'] = Activity\ObjectType::EVENT; + $item['body'] = self::getBBCode($event); + $item['event-id'] = $event_id; + + $item['object'] = '' . XML::escape(Activity\ObjectType::EVENT) . '' . XML::escape($event['uri']) . ''; + $item['object'] .= '' . XML::escape(self::getBBCode($event)) . ''; + $item['object'] .= '' . "\n"; + + return $item; + } + /** * Create an array with translation strings used for events. * diff --git a/src/Model/Item.php b/src/Model/Item.php index 441808ea91..beb7db5764 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1039,7 +1039,7 @@ class Item } $event_id = Event::store($ev); - $item = Event::getItemArrayForId($event_id, $item); + $item = Event::getItemArrayForImportedId($event_id, $item); Logger::info('Event was stored', ['id' => $event_id]); } diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index d84453f736..496e735534 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -631,7 +631,7 @@ class Processor if (($item['gravity'] != GRAVITY_ACTIVITY) && ($activity['object_type'] == 'as:Event')) { $event_id = self::createEvent($activity, $item); - $item = Event::getItemArrayForId($event_id, $item); + $item = Event::getItemArrayForImportedId($event_id, $item); } $item_id = Item::insert($item); diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 3c28aca901..832e2bde23 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1978,7 +1978,7 @@ class DFRN $event_id = Event::store($ev); Logger::info('Event was stored', ['id' => $event_id]); - $item = Event::getItemArrayForId($event_id, $item); + $item = Event::getItemArrayForImportedId($event_id, $item); } } } -- 2.39.5