Browse Source

Store the push/pull direction in the conversation table

pull/8362/head
Michael 1 year ago
parent
commit
af6db65961
5 changed files with 27 additions and 11 deletions
  1. +2
    -1
      database.sql
  2. +17
    -0
      src/Model/Conversation.php
  3. +1
    -6
      src/Protocol/ActivityPub/Processor.php
  4. +5
    -3
      src/Protocol/ActivityPub/Receiver.php
  5. +2
    -1
      static/dbstructure.config.php

+ 2
- 1
database.sql 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`),


+ 17
- 0
src/Model/Conversation.php 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'];
}


+ 1
- 6
src/Protocol/ActivityPub/Processor.php View File

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


+ 5
- 3
src/Protocol/ActivityPub/Receiver.php View File

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


+ 2
- 1
static/dbstructure.config.php 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"],
],


Loading…
Cancel
Save