Improved message handling / new activity relay handling
This commit is contained in:
parent
7834359957
commit
86105635ca
26 changed files with 280 additions and 428 deletions
|
|
@ -38,6 +38,7 @@ use Friendica\Util\DateTimeFormat;
|
|||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\JsonLD;
|
||||
use Friendica\Util\Network;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
|
||||
class APContact
|
||||
{
|
||||
|
|
@ -310,6 +311,8 @@ class APContact
|
|||
|
||||
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
|
||||
|
||||
$apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
|
||||
|
||||
if (!empty($compacted['as:generator'])) {
|
||||
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
|
||||
$apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
|
||||
|
|
@ -380,11 +383,11 @@ class APContact
|
|||
if (strlen($apcontact['photo']) > 255) {
|
||||
$parts = parse_url($apcontact['photo']);
|
||||
unset($parts['fragment']);
|
||||
$apcontact['photo'] = Network::unparseURL($parts);
|
||||
$apcontact['photo'] = Uri::fromParts($parts);
|
||||
|
||||
if (strlen($apcontact['photo']) > 255) {
|
||||
unset($parts['query']);
|
||||
$apcontact['photo'] = Network::unparseURL($parts);
|
||||
$apcontact['photo'] = Uri::fromParts($parts);
|
||||
}
|
||||
|
||||
if (strlen($apcontact['photo']) > 255) {
|
||||
|
|
|
|||
|
|
@ -21,11 +21,6 @@
|
|||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
class Conversation
|
||||
{
|
||||
/*
|
||||
|
|
@ -62,61 +57,4 @@ class Conversation
|
|||
*/
|
||||
const RELAY = 3;
|
||||
|
||||
public static function getByItemUri(string $item_uri)
|
||||
{
|
||||
return DBA::selectFirst('conversation', [], ['item-uri' => $item_uri]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the conversation data
|
||||
*
|
||||
* @param array $arr Item array with conversation data
|
||||
* @return array Item array with removed conversation data
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function insert(array $arr): array
|
||||
{
|
||||
if (in_array(($arr['network'] ?? '') ?: Protocol::PHANTOM,
|
||||
[Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) {
|
||||
$conversation = ['item-uri' => $arr['uri'], 'received' => DateTimeFormat::utcNow()];
|
||||
|
||||
if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
|
||||
$conversation['reply-to-uri'] = $arr['parent-uri'];
|
||||
}
|
||||
|
||||
if (isset($arr['thr-parent']) && ($arr['thr-parent'] != $arr['uri'])) {
|
||||
$conversation['reply-to-uri'] = $arr['thr-parent'];
|
||||
}
|
||||
|
||||
if (isset($arr['conversation-uri'])) {
|
||||
$conversation['conversation-uri'] = $arr['conversation-uri'];
|
||||
}
|
||||
|
||||
if (isset($arr['conversation-href'])) {
|
||||
$conversation['conversation-href'] = $arr['conversation-href'];
|
||||
}
|
||||
|
||||
if (isset($arr['protocol'])) {
|
||||
$conversation['protocol'] = $arr['protocol'];
|
||||
}
|
||||
|
||||
if (isset($arr['direction'])) {
|
||||
$conversation['direction'] = $arr['direction'];
|
||||
}
|
||||
|
||||
if (isset($arr['source'])) {
|
||||
$conversation['source'] = $arr['source'];
|
||||
}
|
||||
|
||||
if (!DBA::exists('conversation', ['item-uri' => $conversation['item-uri']])) {
|
||||
DBA::insert('conversation', $conversation, Database::INSERT_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
unset($arr['conversation-uri']);
|
||||
unset($arr['conversation-href']);
|
||||
unset($arr['source']);
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -563,8 +563,13 @@ class GServer
|
|||
|
||||
$serverdata['registered-users'] = $serverdata['registered-users'] ?? 0;
|
||||
|
||||
// Numbers above a reasonable value (10 millions) are ignored
|
||||
if ($serverdata['registered-users'] > 10000000) {
|
||||
$serverdata['registered-users'] = 0;
|
||||
}
|
||||
|
||||
// On an active server there has to be at least a single user
|
||||
if (!in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED]) && ($serverdata['registered-users'] == 0)) {
|
||||
if (!in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED]) && ($serverdata['registered-users'] <= 0)) {
|
||||
$serverdata['registered-users'] = 1;
|
||||
} elseif (in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED])) {
|
||||
$serverdata['registered-users'] = 0;
|
||||
|
|
|
|||
|
|
@ -801,7 +801,10 @@ class Item
|
|||
$item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
|
||||
|
||||
// Store conversation data
|
||||
$item = Conversation::insert($item);
|
||||
$source = $item['source'] ?? '';
|
||||
unset($item['conversation-uri']);
|
||||
unset($item['conversation-href']);
|
||||
unset($item['source']);
|
||||
|
||||
/*
|
||||
* Do we already have this item?
|
||||
|
|
@ -1259,6 +1262,9 @@ class Item
|
|||
}
|
||||
|
||||
if ($transmit) {
|
||||
if (!empty($source)) {
|
||||
Post\Activity::insert($item['uri-id'], $source);
|
||||
}
|
||||
Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$posted_item['uri-id'], (int)$posted_item['uid']);
|
||||
}
|
||||
|
||||
|
|
|
|||
74
src/Model/Post/Activity.php
Normal file
74
src/Model/Post/Activity.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model\Post;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
class Activity
|
||||
{
|
||||
/**
|
||||
* Insert a new post-activity entry
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param array $fields
|
||||
*
|
||||
* @return bool success
|
||||
*/
|
||||
public static function insert(int $uri_id, string $source): bool
|
||||
{
|
||||
// Additionally assign the key fields
|
||||
$fields = [
|
||||
'uri-id' => $uri_id,
|
||||
'activity' => $source,
|
||||
'received' => DateTimeFormat::utcNow()
|
||||
];
|
||||
|
||||
return DBA::insert('post-activity', $fields, Database::INSERT_IGNORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves activity of the given uri-id
|
||||
*
|
||||
* @param int $uriId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getByURIId(int $uriId): array
|
||||
{
|
||||
$activity = DBA::selectFirst('post-activity', [], ['uri-id' => $uriId]);
|
||||
return json_decode($activity['activity'] ?? '', true) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given uridid has a stored activity
|
||||
*
|
||||
* @param integer $uriId
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function exists(int $uriId): bool
|
||||
{
|
||||
return DBA::exists('post-activity', ['uri-id' => $uriId]);
|
||||
}
|
||||
}
|
||||
|
|
@ -545,7 +545,7 @@ class Tag
|
|||
break;
|
||||
|
||||
default:
|
||||
Logger:warning('Unknown tag type found', $tag);
|
||||
Logger::warning('Unknown tag type found', $tag);
|
||||
}
|
||||
}
|
||||
DBA::close($taglist);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue