Merge pull request #11582 from annando/issue-10926

Issue 10926: Transmit pending events to accepted contacts
This commit is contained in:
Hypolite Petovan 2022-05-30 22:37:50 -04:00 committed by GitHub
commit 0a44143ef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\APContact; use Friendica\Model\APContact;
@ -46,6 +47,7 @@ use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\JsonLD; use Friendica\Util\JsonLD;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Worker\Delivery;
/** /**
* ActivityPub Processor Protocol class * ActivityPub Processor Protocol class
@ -1277,6 +1279,10 @@ class Processor
return; return;
} }
if ($result && DI::config()->get('system', 'transmit_pending_events') && ($owner['contact-type'] == Contact::TYPE_COMMUNITY)) {
self::transmitPendingEvents($cid, $owner['uid']);
}
if (empty($contact)) { if (empty($contact)) {
Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]); 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']); 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 * 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. // Maximum number of posts that a user can send per month with the API. 0 to disable monthly throttling.
'throttle_limit_month' => 0, '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) // update_active_contacts (Boolean)
// When activated, only public contacts will be activated regularly that are used for example in items or tags. // When activated, only public contacts will be activated regularly that are used for example in items or tags.
'update_active_contacts' => false, 'update_active_contacts' => false,