Merge pull request #7922 from annando/reshare-delivery

Do reshares as native as possible
This commit is contained in:
Hypolite Petovan 2019-12-08 17:17:34 -05:00 committed by GitHub
commit a4cc22e8fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View file

@ -363,7 +363,7 @@ class Transmitter
}
}
if (Config::get('debug', 'total_ap_delivery')) {
if (self::isAnnounce($item) || Config::get('debug', 'total_ap_delivery')) {
// Will be activated in a later step
$networks = Protocol::FEDERATED;
} else {
@ -1423,6 +1423,23 @@ class Transmitter
return ['object' => $reshared_item, 'actor' => $profile, 'comment' => $reshared['comment']];
}
/**
* Checks if the provided item array is an announce
*
* @param array $item
*
* @return boolean
*/
public static function isAnnounce($item)
{
$announce = self::getAnnounceArray($item);
if (empty($announce)) {
return false;
}
return empty($announce['comment']);
}
/**
* Creates an activity id for a given contact id
*

View file

@ -251,6 +251,13 @@ class Delivery extends BaseObject
*/
private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
{
// Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora
if (Diaspora::isReshare($target_item['body']) && !empty(Diaspora::personByHandle(contact['addr'], false))) {
Logger::info('Reshare will be transmitted via Diaspora', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return;
}
Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url']));
if ($cmd == self::MAIL) {

View file

@ -625,6 +625,11 @@ class Notifier
return false;
}
// We deliver reshares via AP whenever possible
if (ActivityPub\Transmitter::isAnnounce($item)) {
return true;
}
// Skip DFRN when the item will be (forcefully) delivered via AP
if (Config::get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) {
return true;