-- ------------------------------------------
-- Friendica 2020.03-dev (Dalmatian Bellflower)
--- DB_UPDATE_VERSION 1334
+-- DB_UPDATE_VERSION 1335
-- ------------------------------------------
`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`),
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]);
$conversation['protocol'] = $arr['protocol'];
}
+ if (isset($arr['direction'])) {
+ $conversation['direction'] = $arr['direction'];
+ }
+
if (isset($arr['source'])) {
$conversation['source'] = $arr['source'];
}
unset($arr['conversation-href']);
unset($arr['protocol']);
unset($arr['source']);
+ unset($arr['direction']);
return $arr;
}
$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)),
'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
$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;
$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'];
$trust_source = false;
}
- self::processActivity($ldactivity, $body, $uid, $trust_source);
+ self::processActivity($ldactivity, $body, $uid, $trust_source, true);
}
/**
/**
* 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
* @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)) {
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;
* @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) {
}
// $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;
return;
}
- if (!empty($body)) {
+ if (!empty($body) && empty($object_data['raw'])) {
$object_data['raw'] = $body;
}
$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);
}
}
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') {
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1334);
+ define('DB_UPDATE_VERSION', 1335);
}
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"],
],
// 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,
--- /dev/null
+{{if $direction.direction > 0}}
+<span class="direction">
+ •
+ {{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}}
{{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}}
• <i class="fa fa-thumb-tack" aria-hidden="true" title="{{$item.pinned}}"></i>
<span class="sr-only">{{$item.pinned}}</span>
{{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>
{{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>
--- /dev/null
+{{if $direction.direction > 0}}
+<span class="direction">
+ •
+ {{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}}
{{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}}