Merge pull request #8362 from annando/push-pull

Debug indicator added to show how the post arrived
This commit is contained in:
Hypolite Petovan 2020-03-04 12:15:12 -05:00 committed by GitHub
commit 44eebde9cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 102 additions and 12 deletions

View File

@ -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`),

View File

@ -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'];
}
@ -118,6 +135,7 @@ class Conversation
unset($arr['conversation-href']);
unset($arr['protocol']);
unset($arr['source']);
unset($arr['direction']);
return $arr;
}

View File

@ -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

View File

@ -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;
@ -683,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'];

View File

@ -126,7 +126,7 @@ class Receiver
$trust_source = false;
}
self::processActivity($ldactivity, $body, $uid, $trust_source);
self::processActivity($ldactivity, $body, $uid, $trust_source, true);
}
/**
@ -174,15 +174,16 @@ class Receiver
/**
* Prepare the object array
*
* @param array $activity
* @param array $activity Array with activity data
* @param integer $uid User ID
* @param $trust_source
* @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
* @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)) {
@ -230,8 +231,15 @@ class Receiver
Logger::log("Object data couldn't be processed", Logger::DEBUG);
return [];
}
$object_data['object_id'] = $object_id;
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']])) {
$object_data['directmessage'] = true;
@ -309,9 +317,10 @@ 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)
public static function processActivity($activity, $body = '', $uid = null, $trust_source = false, $push = false)
{
$type = JsonLD::fetchElement($activity, '@type');
if (!$type) {
@ -341,7 +350,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;
@ -352,7 +361,7 @@ class Receiver
return;
}
if (!empty($body)) {
if (!empty($body) && empty($object_data['raw'])) {
$object_data['raw'] = $body;
}
@ -390,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);
}
@ -779,7 +793,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') {

View File

@ -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"],
],

View File

@ -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,

View File

@ -0,0 +1,10 @@
{{if $direction.direction > 0}}
<span class="direction">
&bull;
{{if $direction.direction == 1}}
<i class="fa fa-inbox" aria-hidden="true" title="{{$direction.title}}"></i>
{{elseif $direction.direction == 2}}
<i class="fa fa-download" aria-hidden="true" title="{{$direction.title}}"></i>
{{/if}}
</span>
{{/if}}

View File

@ -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}}
&bull; <i class="fa fa-thumb-tack" aria-hidden="true" title="{{$item.pinned}}"></i>
<span class="sr-only">{{$item.pinned}}</span>
@ -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}}
</small>
</p>
</h5>
@ -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}}
</small>
</span>
</h5>

View File

@ -0,0 +1,10 @@
{{if $direction.direction > 0}}
<span class="direction">
&bull;
{{if $direction.direction == 1}}
<i class="icon-inbox" aria-hidden="true" title="{{$direction.title}}"></i>
{{elseif $direction.direction == 2}}
<i class="icon-download" aria-hidden="true" title="{{$direction.title}}"></i>
{{/if}}
</span>
{{/if}}

View File

@ -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}}
<span class="pinned">{{$item.pinned}}</span>
</span>
{{if $item.lock}}<span class="icon s10 lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}