From acd99b901067f1c61cd98e36965c443c647389d1 Mon Sep 17 00:00:00 2001
From: Michael
Date: Thu, 27 Feb 2020 05:01:43 +0000
Subject: [PATCH 01/10] Push/Pull indicator
---
src/Protocol/ActivityPub/Processor.php | 9 +++++++++
src/Protocol/ActivityPub/Receiver.php | 11 +++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 089d41729..65f101746 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -474,6 +474,15 @@ class Processor
return;
}
+ if (isset($activity['push'])) {
+ $push_app = $activity['push'] ? '📨' : '🚜';
+ if (!empty($item['app'])) {
+ $item['app'] .= ' (' . $push_app . ')';
+ } else {
+ $item['app'] .= $push_app;
+ }
+ }
+
$item['plink'] = $activity['alternate-url'] ?? $item['uri'];
$item = self::constructAttachList($activity, $item);
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 7d25d94f1..96e1588d4 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -127,7 +127,7 @@ class Receiver
$trust_source = false;
}
- self::processActivity($ldactivity, $body, $uid, $trust_source);
+ self::processActivity($ldactivity, $body, $uid, $trust_source, true);
}
/**
@@ -183,7 +183,7 @@ class Receiver
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function prepareObjectData($activity, $uid, &$trust_source)
+ private static function prepareObjectData($activity, $uid, $push, &$trust_source)
{
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
if (empty($actor)) {
@@ -225,13 +225,16 @@ class Receiver
if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) {
if ($type == 'as:Announce') {
$trust_source = false;
+ $push = false;
}
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source, $uid);
if (empty($object_data)) {
Logger::log("Object data couldn't be processed", Logger::DEBUG);
return [];
}
+
$object_data['object_id'] = $object_id;
+ $object_data['push'] = $push;
// Test if it is an answer to a mail
if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
@@ -339,7 +342,7 @@ class Receiver
* @param boolean $trust_source Do we trust the source?
* @throws \Exception
*/
- public static function processActivity($activity, $body = '', $uid = null, $trust_source = false)
+ public static function processActivity($activity, $body = '', $uid = null, $trust_source = false, $push = false)
{
$type = JsonLD::fetchElement($activity, '@type');
if (!$type) {
@@ -369,7 +372,7 @@ class Receiver
}
// $trust_source is called by reference and is set to true if the content was retrieved successfully
- $object_data = self::prepareObjectData($activity, $uid, $trust_source);
+ $object_data = self::prepareObjectData($activity, $uid, $push, $trust_source);
if (empty($object_data)) {
Logger::log('No object data found', Logger::DEBUG);
return;
From af6db659616d8f17d8c0c2fb82e3c503cec78190 Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 08:01:04 +0000
Subject: [PATCH 02/10] Store the push/pull direction in the conversation table
---
database.sql | 3 ++-
src/Model/Conversation.php | 17 +++++++++++++++++
src/Protocol/ActivityPub/Processor.php | 7 +------
src/Protocol/ActivityPub/Receiver.php | 8 +++++---
static/dbstructure.config.php | 3 ++-
5 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/database.sql b/database.sql
index 04a35634e..3cb87fc90 100644
--- a/database.sql
+++ b/database.sql
@@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2020.03-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1334
+-- DB_UPDATE_VERSION 1335
-- ------------------------------------------
@@ -279,6 +279,7 @@ CREATE TABLE IF NOT EXISTS `conversation` (
`conversation-uri` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation URI',
`conversation-href` varbinary(255) NOT NULL DEFAULT '' COMMENT 'GNU Social conversation link',
`protocol` tinyint unsigned NOT NULL DEFAULT 255 COMMENT 'The protocol of the item',
+ `direction` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'How the message arrived here: 1=push, 2=pull',
`source` mediumtext COMMENT 'Original source',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Receiving date',
PRIMARY KEY(`item-uri`),
diff --git a/src/Model/Conversation.php b/src/Model/Conversation.php
index 661cfcd6a..80103b2dc 100644
--- a/src/Model/Conversation.php
+++ b/src/Model/Conversation.php
@@ -41,6 +41,19 @@ class Conversation
const PARCEL_TWITTER = 67;
const PARCEL_UNKNOWN = 255;
+ /**
+ * Unknown message direction
+ */
+ const UNKNOWN = 0;
+ /**
+ * The message had been pushed to this sytem
+ */
+ const PUSH = 1;
+ /**
+ * The message had been fetched by our system
+ */
+ const PULL = 2;
+
public static function getByItemUri($item_uri)
{
return DBA::selectFirst('conversation', [], ['item-uri' => $item_uri]);
@@ -79,6 +92,10 @@ class Conversation
$conversation['protocol'] = $arr['protocol'];
}
+ if (isset($arr['direction'])) {
+ $conversation['direction'] = $arr['direction'];
+ }
+
if (isset($arr['source'])) {
$conversation['source'] = $arr['source'];
}
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 6d6c652fd..e79fcaff6 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -490,12 +490,7 @@ class Processor
}
if (isset($activity['push'])) {
- $push_app = $activity['push'] ? '📨' : '🚜';
- if (!empty($item['app'])) {
- $item['app'] .= ' (' . $push_app . ')';
- } else {
- $item['app'] .= $push_app;
- }
+ $item['direction'] = $activity['push'] ? Conversation::PUSH : Conversation::PULL;
}
$item['plink'] = $activity['alternate-url'] ?? $item['uri'];
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 39655f45d..97eb3b62c 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -174,9 +174,10 @@ class Receiver
/**
* Prepare the object array
*
- * @param array $activity
- * @param integer $uid User ID
- * @param $trust_source
+ * @param array $activity Array with activity data
+ * @param integer $uid User ID
+ * @param boolean $push Message had been pushed to our system
+ * @param boolean $trust_source Do we trust the source?
*
* @return array with object data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -312,6 +313,7 @@ class Receiver
* @param string $body
* @param integer $uid User ID
* @param boolean $trust_source Do we trust the source?
+ * @param boolean $push Message had been pushed to our system
* @throws \Exception
*/
public static function processActivity($activity, $body = '', $uid = null, $trust_source = false, $push = false)
diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php
index 5b2e3bc09..0c0b28941 100755
--- a/static/dbstructure.config.php
+++ b/static/dbstructure.config.php
@@ -51,7 +51,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1334);
+ define('DB_UPDATE_VERSION', 1335);
}
return [
@@ -342,6 +342,7 @@ return [
"conversation-uri" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation URI"],
"conversation-href" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "GNU Social conversation link"],
"protocol" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "255", "comment" => "The protocol of the item"],
+ "direction" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "How the message arrived here: 1=push, 2=pull"],
"source" => ["type" => "mediumtext", "comment" => "Original source"],
"received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Receiving date"],
],
From e3d3dc50e506f276f6adfa9a20b17140a9d98877 Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 08:04:14 +0000
Subject: [PATCH 03/10] Store the direction only when there is content to store
---
src/Protocol/ActivityPub/Processor.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index e79fcaff6..14b993e6e 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -461,6 +461,10 @@ class Processor
$item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
$item['conversation-href'] = $activity['context'] ?? '';
$item['conversation-uri'] = $activity['conversation'] ?? '';
+
+ if (isset($activity['push'])) {
+ $item['direction'] = $activity['push'] ? Conversation::PUSH : Conversation::PULL;
+ }
}
$isForum = false;
@@ -489,10 +493,6 @@ class Processor
return;
}
- if (isset($activity['push'])) {
- $item['direction'] = $activity['push'] ? Conversation::PUSH : Conversation::PULL;
- }
-
$item['plink'] = $activity['alternate-url'] ?? $item['uri'];
$item = self::constructAttachList($activity, $item);
From 0e0de5fcada213a7a58e76c40549e2598a34cd2e Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 21:25:18 +0000
Subject: [PATCH 04/10] Debug switch added, output added
---
view/theme/frio/templates/sub/direction.tpl | 10 ++++++++++
view/theme/vier/templates/sub/direction.tpl | 10 ++++++++++
2 files changed, 20 insertions(+)
create mode 100644 view/theme/frio/templates/sub/direction.tpl
create mode 100644 view/theme/vier/templates/sub/direction.tpl
diff --git a/view/theme/frio/templates/sub/direction.tpl b/view/theme/frio/templates/sub/direction.tpl
new file mode 100644
index 000000000..be34a1edc
--- /dev/null
+++ b/view/theme/frio/templates/sub/direction.tpl
@@ -0,0 +1,10 @@
+{{if $direction.direction > 0}}
+
+ •
+ {{if $direction.direction == 1}}
+
+ {{elseif $direction.direction == 2}}
+
+ {{/if}}
+
+{{/if}}
diff --git a/view/theme/vier/templates/sub/direction.tpl b/view/theme/vier/templates/sub/direction.tpl
new file mode 100644
index 000000000..859102609
--- /dev/null
+++ b/view/theme/vier/templates/sub/direction.tpl
@@ -0,0 +1,10 @@
+{{if $direction.direction > 0}}
+
+ •
+ {{if $direction.direction == 1}}
+
+ {{elseif $direction.direction == 2}}
+
+ {{/if}}
+
+{{/if}}
From d63e903d9ff184fa6e4e8f6a2d2da745c74fa582 Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 21:29:51 +0000
Subject: [PATCH 05/10] Changed template for direction
---
src/Object/Post.php | 10 ++++++++++
static/defaults.config.php | 4 ++++
view/theme/frio/templates/wall_thread.tpl | 9 +++++++++
view/theme/vier/templates/wall_thread.tpl | 3 +++
4 files changed, 26 insertions(+)
diff --git a/src/Object/Post.php b/src/Object/Post.php
index 1c1f85e2a..76cf6b036 100644
--- a/src/Object/Post.php
+++ b/src/Object/Post.php
@@ -406,6 +406,15 @@ class Post
$remote_comment = '';
}
+ $direction = [];
+ if (DI::config()->get('debug', 'show_direction')) {
+ $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
+ if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
+ $title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
+ $direction = ['direction' => $conversation['direction'], 'title' => $title[$conversation['direction']]];
+ }
+ }
+
$tmp_item = [
'template' => $this->getTemplate(),
'type' => implode("", array_slice(explode("/", $item['verb']), -1)),
@@ -482,6 +491,7 @@ class Post
'commented' => $item['commented'],
'created_date' => $item['created'],
'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
+ 'direction' => $direction,
'delivery' => [
'queue_count' => $item['delivery_queue_count'],
'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
diff --git a/static/defaults.config.php b/static/defaults.config.php
index ab47eef19..110c016eb 100644
--- a/static/defaults.config.php
+++ b/static/defaults.config.php
@@ -496,6 +496,10 @@ return [
// Logs every call to /inbox as a JSON file in Friendica's temporary directory
'ap_inbox_log' => false,
+ // show_direction (Boolean)
+ // Display if a post had been fetched or had been pushed towards our server
+ 'show_direction' => false,
+
// total_ap_delivery (Boolean)
// Deliver via AP to every possible receiver and we suppress the delivery to these contacts with other protocols
'total_ap_delivery' => false,
diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl
index 5a0cf57fa..a5a785af7 100644
--- a/view/theme/frio/templates/wall_thread.tpl
+++ b/view/theme/frio/templates/wall_thread.tpl
@@ -155,6 +155,9 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
+ {{if $item.direction}}
+ {{include file="sub/direction.tpl" direction=$item.direction}}
+ {{/if}}
{{if $item.pinned}}
•
{{$item.pinned}}
@@ -183,6 +186,9 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
+ {{if $item.direction}}
+ {{include file="sub/direction.tpl" direction=$item.direction}}
+ {{/if}}
@@ -202,6 +208,9 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
+ {{if $item.direction}}
+ {{include file="sub/direction.tpl" direction=$item.direction}}
+ {{/if}}
diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl
index aef411bca..31ab92a3d 100644
--- a/view/theme/vier/templates/wall_thread.tpl
+++ b/view/theme/vier/templates/wall_thread.tpl
@@ -60,6 +60,9 @@
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
+ {{if $item.direction}}
+ {{include file="sub/direction.tpl" direction=$item.direction}}
+ {{/if}}
{{$item.pinned}}
{{if $item.lock}}{{$item.lock}}{{/if}}
From e38640da76bb75ff9f8624c225ebcdd36a43f87d Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 21:58:03 +0000
Subject: [PATCH 06/10] The original content of the post hadn't always been
stored
---
src/Protocol/ActivityPub.php | 2 +-
src/Protocol/ActivityPub/Processor.php | 2 +-
src/Protocol/ActivityPub/Receiver.php | 6 +++++-
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php
index f1cd652f4..fd2f84e51 100644
--- a/src/Protocol/ActivityPub.php
+++ b/src/Protocol/ActivityPub.php
@@ -209,7 +209,7 @@ class ActivityPub
foreach ($items as $activity) {
$ldactivity = JsonLD::compact($activity);
- ActivityPub\Receiver::processActivity($ldactivity, '', $uid, true);
+ ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity), $uid, true);
}
}
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 14b993e6e..2f4c78453 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -687,7 +687,7 @@ class Processor
$ldactivity['thread-completion'] = true;
- ActivityPub\Receiver::processActivity($ldactivity);
+ ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity));
Logger::notice('Activity had been fetched and processed.', ['url' => $url, 'object' => $activity['id']]);
return $activity['id'];
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 97eb3b62c..67404af5e 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -784,7 +784,11 @@ class Receiver
}
if (in_array($type, self::CONTENT_TYPES)) {
- return self::processObject($object);
+ $object_data = self::processObject($object);
+ if (!empty($data)) {
+ $object_data['raw'] = json_encode($data);
+ }
+ return $object_data;
}
if ($type == 'as:Announce') {
From 986877b1cf229537cc1f5f44f77afa4646fa3917 Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 22:22:59 +0000
Subject: [PATCH 07/10] Restore previous state
---
src/Protocol/ActivityPub.php | 2 +-
src/Protocol/ActivityPub/Processor.php | 2 +-
src/Protocol/ActivityPub/Receiver.php | 6 +-----
3 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php
index fd2f84e51..f1cd652f4 100644
--- a/src/Protocol/ActivityPub.php
+++ b/src/Protocol/ActivityPub.php
@@ -209,7 +209,7 @@ class ActivityPub
foreach ($items as $activity) {
$ldactivity = JsonLD::compact($activity);
- ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity), $uid, true);
+ ActivityPub\Receiver::processActivity($ldactivity, '', $uid, true);
}
}
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 2f4c78453..14b993e6e 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -687,7 +687,7 @@ class Processor
$ldactivity['thread-completion'] = true;
- ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity));
+ ActivityPub\Receiver::processActivity($ldactivity);
Logger::notice('Activity had been fetched and processed.', ['url' => $url, 'object' => $activity['id']]);
return $activity['id'];
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 67404af5e..97eb3b62c 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -784,11 +784,7 @@ class Receiver
}
if (in_array($type, self::CONTENT_TYPES)) {
- $object_data = self::processObject($object);
- if (!empty($data)) {
- $object_data['raw'] = json_encode($data);
- }
- return $object_data;
+ return self::processObject($object);
}
if ($type == 'as:Announce') {
From 8410c5e2837b8c18406743995b820f18ff886475 Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 22:43:19 +0000
Subject: [PATCH 08/10] The direction field needs to be removed
---
src/Model/Conversation.php | 1 +
src/Protocol/ActivityPub/Processor.php | 3 ++-
src/Protocol/ActivityPub/Receiver.php | 7 ++++++-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/Model/Conversation.php b/src/Model/Conversation.php
index 80103b2dc..1dcb6b0c2 100644
--- a/src/Model/Conversation.php
+++ b/src/Model/Conversation.php
@@ -135,6 +135,7 @@ class Conversation
unset($arr['conversation-href']);
unset($arr['protocol']);
unset($arr['source']);
+ unset($arr['direction']);
return $arr;
}
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 14b993e6e..2fd2f2f77 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -687,7 +687,8 @@ class Processor
$ldactivity['thread-completion'] = true;
- ActivityPub\Receiver::processActivity($ldactivity);
+ ActivityPub\Receiver::processActivity($ldactivity, json_encode($activity));
+
Logger::notice('Activity had been fetched and processed.', ['url' => $url, 'object' => $activity['id']]);
return $activity['id'];
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 97eb3b62c..075bc942e 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -784,7 +784,12 @@ class Receiver
}
if (in_array($type, self::CONTENT_TYPES)) {
- return self::processObject($object);
+ $object_data = self::processObject($object);
+
+ if (!empty($data)) {
+ $object_data['raw'] = json_encode($data);
+ }
+ return $object_data;
}
if ($type == 'as:Announce') {
From 79986c1fe58276a6eec9d5275bcbf4ba7d235a6a Mon Sep 17 00:00:00 2001
From: Michael
Date: Tue, 3 Mar 2020 22:57:29 +0000
Subject: [PATCH 09/10] Spaces removed
---
src/Protocol/ActivityPub/Processor.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 2fd2f2f77..4fa2d33f7 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -461,10 +461,10 @@ class Processor
$item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
$item['conversation-href'] = $activity['context'] ?? '';
$item['conversation-uri'] = $activity['conversation'] ?? '';
-
+
if (isset($activity['push'])) {
$item['direction'] = $activity['push'] ? Conversation::PUSH : Conversation::PULL;
- }
+ }
}
$isForum = false;
From 7b7132971a64a92a685a5fd860fe4709dce1765a Mon Sep 17 00:00:00 2001
From: Michael
Date: Wed, 4 Mar 2020 06:04:27 +0000
Subject: [PATCH 10/10] Raw content is now stored with announce messages as
well
---
src/Protocol/ActivityPub/Receiver.php | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 075bc942e..21aba5094 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -225,7 +225,6 @@ class Receiver
if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) {
if ($type == 'as:Announce') {
$trust_source = false;
- $push = false;
}
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source, $uid);
if (empty($object_data)) {
@@ -234,7 +233,12 @@ class Receiver
}
$object_data['object_id'] = $object_id;
- $object_data['push'] = $push;
+
+ if ($type == 'as:Announce') {
+ $object_data['push'] = false;
+ } else {
+ $object_data['push'] = $push;
+ }
// Test if it is an answer to a mail
if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
@@ -357,7 +361,7 @@ class Receiver
return;
}
- if (!empty($body)) {
+ if (!empty($body) && empty($object_data['raw'])) {
$object_data['raw'] = $body;
}
@@ -395,6 +399,11 @@ class Receiver
$announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
$announce_object_data['object_id'] = $object_data['object_id'];
$announce_object_data['object_type'] = $object_data['object_type'];
+ $announce_object_data['push'] = $push;
+
+ if (!empty($body)) {
+ $announce_object_data['raw'] = $body;
+ }
ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
}