mirror of
https://github.com/friendica/friendica
synced 2025-05-06 20:24:11 +02:00
Improved direction and protocol detection
This commit is contained in:
parent
b8243689a0
commit
2987070d93
14 changed files with 95 additions and 164 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -105,34 +104,8 @@ class Conversation
|
|||
$conversation['source'] = $arr['source'];
|
||||
}
|
||||
|
||||
$fields = ['item-uri', 'reply-to-uri', 'conversation-uri', 'conversation-href', 'protocol', 'source'];
|
||||
$old_conv = DBA::selectFirst('conversation', $fields, ['item-uri' => $conversation['item-uri']]);
|
||||
if (DBA::isResult($old_conv)) {
|
||||
// Don't update when only the source has changed.
|
||||
// Only do this when there had been no source before.
|
||||
if ($old_conv['source'] != '') {
|
||||
unset($old_conv['source']);
|
||||
}
|
||||
// Update structure data all the time but the source only when its from a better protocol.
|
||||
if (
|
||||
empty($conversation['source'])
|
||||
|| (
|
||||
!empty($old_conv['source'])
|
||||
&& ($old_conv['protocol'] < (($conversation['protocol'] ?? '') ?: self::PARCEL_UNKNOWN))
|
||||
)
|
||||
) {
|
||||
unset($conversation['protocol']);
|
||||
unset($conversation['source']);
|
||||
}
|
||||
if (!DBA::update('conversation', $conversation, ['item-uri' => $conversation['item-uri']], $old_conv)) {
|
||||
Logger::log('Conversation: update for ' . $conversation['item-uri'] . ' from ' . $old_conv['protocol'] . ' to ' . $conversation['protocol'] . ' failed',
|
||||
Logger::DEBUG);
|
||||
}
|
||||
} else {
|
||||
if (!DBA::insert('conversation', $conversation, Database::INSERT_UPDATE)) {
|
||||
Logger::log('Conversation: insert for ' . $conversation['item-uri'] . ' (protocol ' . $conversation['protocol'] . ') failed',
|
||||
Logger::DEBUG);
|
||||
}
|
||||
if (!DBA::exists('conversation', ['item-uri' => $conversation['item-uri']])) {
|
||||
DBA::insert('conversation', $conversation, Database::INSERT_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,6 +257,16 @@ class Event
|
|||
*/
|
||||
public static function store($arr)
|
||||
{
|
||||
$network = $arr['network'] ?? Protocol::DFRN;
|
||||
$protocol = $arr['protocol'] ?? Conversation::PARCEL_UNKNOWN;
|
||||
$direction = $arr['direction'] ?? Conversation::UNKNOWN;
|
||||
$source = $arr['source'] ?? '';
|
||||
|
||||
unset($arr['network']);
|
||||
unset($arr['protocol']);
|
||||
unset($arr['direction']);
|
||||
unset($arr['source']);
|
||||
|
||||
$event = [];
|
||||
$event['id'] = intval($arr['id'] ?? 0);
|
||||
$event['uid'] = intval($arr['uid'] ?? 0);
|
||||
|
@ -373,7 +383,10 @@ class Event
|
|||
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
|
||||
$item_arr['body'] = self::getBBCode($event);
|
||||
$item_arr['event-id'] = $event['id'];
|
||||
$item_arr['network'] = Protocol::DFRN;
|
||||
$item_arr['network'] = $network;
|
||||
$item_arr['protocol'] = $protocol;
|
||||
$item_arr['direction'] = $direction;
|
||||
$item_arr['source'] = $source;
|
||||
|
||||
$item_arr['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
|
||||
|
|
|
@ -1581,6 +1581,7 @@ class Item
|
|||
$item['origin'] = 1;
|
||||
$item['network'] = Protocol::DFRN;
|
||||
$item['protocol'] = Conversation::PARCEL_DIRECT;
|
||||
$item['direction'] = Conversation::PUSH;
|
||||
|
||||
if (in_array($notify, PRIORITIES)) {
|
||||
$priority = $notify;
|
||||
|
@ -3336,6 +3337,8 @@ class Item
|
|||
'wall' => $item['wall'],
|
||||
'origin' => 1,
|
||||
'network' => Protocol::DFRN,
|
||||
'protocol' => Conversation::PARCEL_DIRECT,
|
||||
'direction' => Conversation::PUSH,
|
||||
'gravity' => GRAVITY_ACTIVITY,
|
||||
'parent' => $item['id'],
|
||||
'thr-parent' => $item['uri'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue