Issue 10926: Transmit pending events to accepted contacts

This commit is contained in:
Michael 2022-05-30 20:52:43 +00:00
parent 0b312ae9b3
commit cc6192df02
2 changed files with 45 additions and 8 deletions

View File

@ -27,6 +27,7 @@ use Friendica\Content\Text\Markdown;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
@ -46,6 +47,7 @@ use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\JsonLD;
use Friendica\Util\Strings;
use Friendica\Worker\Delivery;
/**
* ActivityPub Processor Protocol class
@ -1277,6 +1279,10 @@ class Processor
return;
}
if ($result && DI::config()->get('system', 'transmit_pending_events') && ($owner['contact-type'] == Contact::TYPE_COMMUNITY)) {
self::transmitPendingEvents($cid, $owner['uid']);
}
if (empty($contact)) {
Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
}
@ -1284,6 +1290,33 @@ class Processor
Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
}
/**
* Transmit pending events to the new follower
*
* @param integer $cid
* @param integer $uid
* @return void
*/
private static function transmitPendingEvents(int $cid, int $uid)
{
$account = DBA::selectFirst('account-user-view', ['ap-inbox', 'ap-sharedinbox'], ['id' => $cid]);
$inbox = $account['ap-sharedinbox'] ?: $account['ap-inbox'];
$events = DBA::select('event', ['id'], ["`uid` = ? AND `start` > ? AND `type` != ?", $uid, DateTimeFormat::utcNow(), 'birthday']);
while ($event = DBA::fetch($events)) {
$post = Post::selectFirst(['id', 'uri-id', 'created'], ['event-id' => $event['id']]);
if (empty($post)) {
continue;
}
if (DI::config()->get('system', 'bulk_delivery')) {
Post\Delivery::add($post['uri-id'], $uid, $inbox, $post['created'], Delivery::POST, [$cid]);
Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0);
} else {
Worker::add(PRIORITY_HIGH, 'APDelivery', Delivery::POST, $post['id'], $inbox, $uid, [$cid], $post['uri-id']);
}
}
}
/**
* Update the given profile
*

View File

@ -557,6 +557,10 @@ return [
// Maximum number of posts that a user can send per month with the API. 0 to disable monthly throttling.
'throttle_limit_month' => 0,
// transmit_pending_events (Boolean)
// Transmit pending events upon accepted contact request for forums
'transmit_pending_events' => false,
// update_active_contacts (Boolean)
// When activated, only public contacts will be activated regularly that are used for example in items or tags.
'update_active_contacts' => false,