Add and delete entries
This commit is contained in:
parent
ac47aed1b4
commit
ce38e63399
|
@ -223,7 +223,7 @@ class Processor
|
||||||
Post\History::add($item['uri-id'], $item);
|
Post\History::add($item['uri-id'], $item);
|
||||||
Item::update($item, ['uri' => $activity['id']]);
|
Item::update($item, ['uri' => $activity['id']]);
|
||||||
|
|
||||||
DBA::delete('inbox-queue', ['url' => $item['uri']]);
|
Receiver::removeFromQueue($activity);
|
||||||
|
|
||||||
if ($activity['object_type'] == 'as:Event') {
|
if ($activity['object_type'] == 'as:Event') {
|
||||||
$posts = Post::select(['event-id', 'uid'], ["`uri` = ? AND `event-id` > ?", $activity['id'], 0]);
|
$posts = Post::select(['event-id', 'uid'], ["`uri` = ? AND `event-id` > ?", $activity['id'], 0]);
|
||||||
|
@ -428,6 +428,7 @@ class Processor
|
||||||
|
|
||||||
Logger::info('Deleting item', ['object' => $activity['object_id'], 'owner' => $owner]);
|
Logger::info('Deleting item', ['object' => $activity['object_id'], 'owner' => $owner]);
|
||||||
Item::markForDeletion(['uri' => $activity['object_id'], 'owner-id' => $owner]);
|
Item::markForDeletion(['uri' => $activity['object_id'], 'owner-id' => $owner]);
|
||||||
|
Receiver::removeFromQueue($activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -892,7 +893,7 @@ class Processor
|
||||||
$item_id = Item::insert($item);
|
$item_id = Item::insert($item);
|
||||||
if ($item_id) {
|
if ($item_id) {
|
||||||
Logger::info('Item insertion successful', ['user' => $item['uid'], 'item_id' => $item_id]);
|
Logger::info('Item insertion successful', ['user' => $item['uid'], 'item_id' => $item_id]);
|
||||||
DBA::delete('inbox-queue', ['url' => $item['uri']]);
|
Receiver::removeFromQueue($activity);
|
||||||
} else {
|
} else {
|
||||||
Logger::notice('Item insertion aborted', ['user' => $item['uid']]);
|
Logger::notice('Item insertion aborted', ['user' => $item['uid']]);
|
||||||
}
|
}
|
||||||
|
@ -1351,6 +1352,7 @@ class Processor
|
||||||
|
|
||||||
Logger::info('Updating profile', ['object' => $activity['object_id']]);
|
Logger::info('Updating profile', ['object' => $activity['object_id']]);
|
||||||
Contact::updateFromProbeByURL($activity['object_id']);
|
Contact::updateFromProbeByURL($activity['object_id']);
|
||||||
|
Receiver::removeFromQueue($activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1379,6 +1381,7 @@ class Processor
|
||||||
DBA::close($contacts);
|
DBA::close($contacts);
|
||||||
|
|
||||||
Logger::info('Deleted contact', ['object' => $activity['object_id']]);
|
Logger::info('Deleted contact', ['object' => $activity['object_id']]);
|
||||||
|
Receiver::removeFromQueue($activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,19 +98,6 @@ class Receiver
|
||||||
|
|
||||||
$ldactivity = JsonLD::compact($activity);
|
$ldactivity = JsonLD::compact($activity);
|
||||||
|
|
||||||
$http_signer = HTTPSignature::getSigner($body, $header);
|
|
||||||
if ($http_signer === false) {
|
|
||||||
Logger::warning('Invalid HTTP signature, message will be discarded.');
|
|
||||||
return;
|
|
||||||
} elseif (empty($http_signer)) {
|
|
||||||
Logger::info('Signer is a tombstone. The message will be discarded, the signer account is deleted.');
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Logger::info('Valid HTTP signature', ['signer' => $http_signer]);
|
|
||||||
}
|
|
||||||
|
|
||||||
self::enqueuePost($ldactivity, $http_signer, $uid);
|
|
||||||
|
|
||||||
$actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id') ?? '';
|
$actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id') ?? '';
|
||||||
|
|
||||||
$apcontact = APContact::getByURL($actor);
|
$apcontact = APContact::getByURL($actor);
|
||||||
|
@ -125,6 +112,17 @@ class Receiver
|
||||||
APContact::unmarkForArchival($apcontact);
|
APContact::unmarkForArchival($apcontact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$http_signer = HTTPSignature::getSigner($body, $header);
|
||||||
|
if ($http_signer === false) {
|
||||||
|
Logger::warning('Invalid HTTP signature, message will be discarded.');
|
||||||
|
return;
|
||||||
|
} elseif (empty($http_signer)) {
|
||||||
|
Logger::info('Signer is a tombstone. The message will be discarded, the signer account is deleted.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Logger::info('Valid HTTP signature', ['signer' => $http_signer]);
|
||||||
|
}
|
||||||
|
|
||||||
$signer = [$http_signer];
|
$signer = [$http_signer];
|
||||||
|
|
||||||
Logger::info('Message for user ' . $uid . ' is from actor ' . $actor);
|
Logger::info('Message for user ' . $uid . ' is from actor ' . $actor);
|
||||||
|
@ -158,32 +156,45 @@ class Receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
$fetchQueue = new FetchQueue();
|
$fetchQueue = new FetchQueue();
|
||||||
self::processActivity($fetchQueue, $ldactivity, $body, $uid, $trust_source, true, $signer);
|
self::processActivity($fetchQueue, $ldactivity, $body, $uid, $trust_source, true, $signer, $http_signer);
|
||||||
$fetchQueue->process();
|
$fetchQueue->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function enqueuePost(array $ldactivity = [], string $signer, int $uid)
|
private static function enqueuePost(array $ldactivity = [], string $type, int $uid, string $http_signer): array
|
||||||
{
|
{
|
||||||
if (empty($ldactivity['as:object'])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = JsonLD::fetchElement($ldactivity, 'as:object', '@id');
|
|
||||||
$fields = [
|
$fields = [
|
||||||
'url' => $url,
|
'activity-id' => $ldactivity['id'],
|
||||||
'in-reply-to-url' => JsonLD::fetchElement($ldactivity['as:object'], 'as:inReplyTo', '@id'),
|
'object-id' => $ldactivity['object_id'],
|
||||||
'signer' => $signer,
|
'type' => $type,
|
||||||
'type' => JsonLD::fetchElement($ldactivity, '@type'),
|
'object-type' => $ldactivity['object_type'],
|
||||||
'object-type' => JsonLD::fetchElement($ldactivity['as:object'], '@type'),
|
|
||||||
'activity' => json_encode($ldactivity, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
'activity' => json_encode($ldactivity, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
'received' => DateTimeFormat::utcNow(),
|
'received' => DateTimeFormat::utcNow(),
|
||||||
];
|
];
|
||||||
DBA::insert('inbox-queue', $fields, Database::INSERT_IGNORE);
|
|
||||||
|
|
||||||
$queue = DBA::selectFirst('inbox-queue', ['id'], ['url' => $url]);
|
if (!empty($ldactivity['object_object_type'])) {
|
||||||
if (!empty($queue['id'])) {
|
$fields['object-object-type'] = $ldactivity['object_object_type'];
|
||||||
DBA::insert('inbox-queue-receiver', ['queue-id' => $queue['id'], 'uid' => $uid], Database::INSERT_IGNORE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($http_signer)) {
|
||||||
|
$fields['signer'] = $http_signer;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBA::insert('inbox-entry', $fields, Database::INSERT_IGNORE);
|
||||||
|
|
||||||
|
$queue = DBA::selectFirst('inbox-entry', ['id'], ['activity-id' => $ldactivity['id']]);
|
||||||
|
if (!empty($queue['id'])) {
|
||||||
|
$ldactivity['entry-id'] = $queue['id'];
|
||||||
|
DBA::insert('inbox-entry-receiver', ['queue-id' => $queue['id'], 'uid' => $uid], Database::INSERT_IGNORE);
|
||||||
|
}
|
||||||
|
return $ldactivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function removeFromQueue(array $activity = [])
|
||||||
|
{
|
||||||
|
if (empty($activity['entry-id'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DBA::delete('inbox-entry', ['id' => $activity['entry-id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,7 +528,7 @@ class Receiver
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function processActivity(FetchQueue $fetchQueue, array $activity, string $body = '', int $uid = null, bool $trust_source = false, bool $push = false, array $signer = [])
|
public static function processActivity(FetchQueue $fetchQueue, array $activity, string $body = '', int $uid = null, bool $trust_source = false, bool $push = false, array $signer = [], string $http_signer = '')
|
||||||
{
|
{
|
||||||
$type = JsonLD::fetchElement($activity, '@type');
|
$type = JsonLD::fetchElement($activity, '@type');
|
||||||
if (!$type) {
|
if (!$type) {
|
||||||
|
@ -591,6 +602,8 @@ class Receiver
|
||||||
$object_data['from-relay'] = $activity['from-relay'];
|
$object_data['from-relay'] = $activity['from-relay'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$object_data = self::enqueuePost($object_data, $type, $uid, $http_signer);
|
||||||
|
|
||||||
if (in_array('as:Question', [$object_data['object_type'] ?? '', $object_data['object_object_type'] ?? ''])) {
|
if (in_array('as:Question', [$object_data['object_type'] ?? '', $object_data['object_object_type'] ?? ''])) {
|
||||||
self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
|
self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -784,30 +784,31 @@ return [
|
||||||
"hook_file_function" => ["UNIQUE", "hook", "file", "function"],
|
"hook_file_function" => ["UNIQUE", "hook", "file", "function"],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"inbox-queue" => [
|
"inbox-entry" => [
|
||||||
"comment" => "Incoming activity",
|
"comment" => "Incoming activity",
|
||||||
"fields" => [
|
"fields" => [
|
||||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
|
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
|
||||||
"url" => ["type" => "varbinary(255)", "comment" => "id of the incoming activity"],
|
"activity-id" => ["type" => "varbinary(255)", "comment" => "id of the incoming activity"],
|
||||||
"in-reply-to-url" => ["type" => "varbinary(255)", "comment" => "related id of the incoming activity"],
|
"object-id" => ["type" => "varbinary(255)", "comment" => ""],
|
||||||
"signer" => ["type" => "varbinary(255)", "comment" => "Signer of the incoming activity"],
|
"type" => ["type" => "varchar(64)", "comment" => "Type of the activity"],
|
||||||
|
"object-type" => ["type" => "varchar(64)", "comment" => "Type of the object activity"],
|
||||||
|
"object-object-type" => ["type" => "varchar(64)", "comment" => "Type of the object's object activity"],
|
||||||
|
"received" => ["type" => "datetime", "comment" => "Receiving date"],
|
||||||
"activity" => ["type" => "mediumtext", "comment" => "The JSON activity"],
|
"activity" => ["type" => "mediumtext", "comment" => "The JSON activity"],
|
||||||
"received" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Receiving date"],
|
"signer" => ["type" => "varchar(255)", "comment" => ""],
|
||||||
"type" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "Type of the activity"],
|
|
||||||
"object-type" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "Type of the object activity"],
|
|
||||||
],
|
],
|
||||||
"indexes" => [
|
"indexes" => [
|
||||||
"PRIMARY" => ["id"],
|
"PRIMARY" => ["id"],
|
||||||
"url" => ["UNIQUE", "url"],
|
"activity-id" => ["UNIQUE", "activity-id"],
|
||||||
"in-reply-to-url" => ["in-reply-to-url"],
|
"object-id" => ["object-id"],
|
||||||
"received" => ["received"],
|
"received" => ["received"],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"inbox-queue-receiver" => [
|
"inbox-entry-receiver" => [
|
||||||
"comment" => "Receiver for the incoming activity",
|
"comment" => "Receiver for the incoming activity",
|
||||||
"fields" => [
|
"fields" => [
|
||||||
"queue-id" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["inbox-queue" => "id"], "comment" => ""],
|
"queue-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["inbox-entry" => "id"], "comment" => ""],
|
||||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"],
|
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "User id"],
|
||||||
],
|
],
|
||||||
"indexes" => [
|
"indexes" => [
|
||||||
"PRIMARY" => ["queue-id", "uid"],
|
"PRIMARY" => ["queue-id", "uid"],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user