mirror of
https://github.com/friendica/friendica
synced 2024-11-20 06:23:41 +00:00
Merge pull request #9647 from annando/original-relay
Relay posts with the original protocol
This commit is contained in:
commit
67573cf996
4 changed files with 62 additions and 40 deletions
|
@ -469,6 +469,21 @@ class Transmitter
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given item id is from ActivityPub
|
||||||
|
*
|
||||||
|
* @param integer $item_id
|
||||||
|
* @return boolean "true" if the post is from ActivityPub
|
||||||
|
*/
|
||||||
|
private static function isAPPost(int $item_id)
|
||||||
|
{
|
||||||
|
if (empty($item_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Item::exists(['id' => $item_id, 'network' => Protocol::ACTIVITYPUB]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of permissions from an item thread
|
* Creates an array of permissions from an item thread
|
||||||
*
|
*
|
||||||
|
@ -501,7 +516,7 @@ class Transmitter
|
||||||
$always_bcc = true;
|
$always_bcc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::isAnnounce($item) || DI::config()->get('debug', 'total_ap_delivery')) {
|
if (self::isAnnounce($item) || DI::config()->get('debug', 'total_ap_delivery') || self::isAPPost($last_id)) {
|
||||||
// Will be activated in a later step
|
// Will be activated in a later step
|
||||||
$networks = Protocol::FEDERATED;
|
$networks = Protocol::FEDERATED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -680,12 +695,13 @@ class Transmitter
|
||||||
*
|
*
|
||||||
* @param integer $uid User ID
|
* @param integer $uid User ID
|
||||||
* @param boolean $personal fetch personal inboxes
|
* @param boolean $personal fetch personal inboxes
|
||||||
|
* @param boolean $all_ap Retrieve all AP enabled inboxes
|
||||||
*
|
*
|
||||||
* @return array of follower inboxes
|
* @return array of follower inboxes
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function fetchTargetInboxesforUser($uid, $personal = false)
|
public static function fetchTargetInboxesforUser($uid, $personal = false, bool $all_ap = false)
|
||||||
{
|
{
|
||||||
$inboxes = [];
|
$inboxes = [];
|
||||||
|
|
||||||
|
@ -698,7 +714,7 @@ class Transmitter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DI::config()->get('debug', 'total_ap_delivery')) {
|
if (DI::config()->get('debug', 'total_ap_delivery') || $all_ap) {
|
||||||
// Will be activated in a later step
|
// Will be activated in a later step
|
||||||
$networks = Protocol::FEDERATED;
|
$networks = Protocol::FEDERATED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -793,7 +809,7 @@ class Transmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
|
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
|
||||||
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
|
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal, self::isAPPost($last_id)));
|
||||||
} else {
|
} else {
|
||||||
if (Contact::isLocal($receiver)) {
|
if (Contact::isLocal($receiver)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1033,33 +1049,31 @@ class Transmitter
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($type)) {
|
$condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
|
||||||
$condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
|
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
||||||
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
if (!$item['origin'] && DBA::isResult($conversation)) {
|
||||||
if (DBA::isResult($conversation)) {
|
$data = json_decode($conversation['source'], true);
|
||||||
$data = json_decode($conversation['source'], true);
|
if (!empty($data['type'])) {
|
||||||
if (!empty($data['type'])) {
|
if (in_array($data['type'], ['Create', 'Update'])) {
|
||||||
if (in_array($data['type'], ['Create', 'Update'])) {
|
if ($object_mode) {
|
||||||
if ($object_mode) {
|
unset($data['@context']);
|
||||||
unset($data['@context']);
|
unset($data['signature']);
|
||||||
unset($data['signature']);
|
|
||||||
}
|
|
||||||
Logger::info('Return stored conversation', ['item' => $item_id]);
|
|
||||||
return $data;
|
|
||||||
} elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
|
|
||||||
if (!empty($data['@context'])) {
|
|
||||||
$context = $data['@context'];
|
|
||||||
unset($data['@context']);
|
|
||||||
}
|
|
||||||
unset($data['actor']);
|
|
||||||
$object = $data;
|
|
||||||
}
|
}
|
||||||
|
Logger::info('Return stored conversation', ['item' => $item_id]);
|
||||||
|
return $data;
|
||||||
|
} elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
|
||||||
|
if (!empty($data['@context'])) {
|
||||||
|
$context = $data['@context'];
|
||||||
|
unset($data['@context']);
|
||||||
|
}
|
||||||
|
unset($data['actor']);
|
||||||
|
$object = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = self::getTypeOfItem($item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$type = self::getTypeOfItem($item);
|
||||||
|
|
||||||
if (!$object_mode) {
|
if (!$object_mode) {
|
||||||
$data = ['@context' => $context ?? ActivityPub::CONTEXT];
|
$data = ['@context' => $context ?? ActivityPub::CONTEXT];
|
||||||
|
|
||||||
|
|
|
@ -3031,7 +3031,18 @@ class Diaspora
|
||||||
$owner['uprvkey'] = $owner['prvkey'];
|
$owner['uprvkey'] = $owner['prvkey'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
|
// When sending content to Friendica contacts using the Diaspora protocol
|
||||||
|
// we have to fetch the public key from the fcontact.
|
||||||
|
// This is due to the fact that legacy DFRN had unique keys for every contact.
|
||||||
|
$pubkey = $contact['pubkey'];
|
||||||
|
if (!empty($contact['addr'])) {
|
||||||
|
$fcontact = FContact::getByURL($contact['addr']);
|
||||||
|
if (!empty($fcontact)) {
|
||||||
|
$pubkey = $fcontact['pubkey'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey, $public_batch);
|
||||||
|
|
||||||
$return_code = self::transmit($owner, $contact, $envelope, $public_batch, $guid);
|
$return_code = self::transmit($owner, $contact, $envelope, $public_batch, $guid);
|
||||||
|
|
||||||
|
|
|
@ -141,13 +141,7 @@ class Delivery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When commenting too fast after delivery, a post wasn't recognized as top level post.
|
$top_level = $target_item['gravity'] == GRAVITY_PARENT;
|
||||||
// The count then showed more than one entry. The additional check should help.
|
|
||||||
// The check for the "count" should be superfluous, but I'm not totally sure by now, so we keep it.
|
|
||||||
if ((($parent['id'] == $target_id) || (count($items) == 1)) && ($parent['uri'] === $parent['parent-uri'])) {
|
|
||||||
Logger::log('Top level post');
|
|
||||||
$top_level = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is IMPORTANT!!!!
|
// This is IMPORTANT!!!!
|
||||||
|
|
||||||
|
@ -211,7 +205,8 @@ class Delivery
|
||||||
// Transmit via Diaspora if the thread had started as Diaspora post.
|
// Transmit via Diaspora if the thread had started as Diaspora post.
|
||||||
// Also transmit via Diaspora if this is a direct answer to a Diaspora comment.
|
// Also transmit via Diaspora if this is a direct answer to a Diaspora comment.
|
||||||
// This is done since the uri wouldn't match (Diaspora doesn't transmit it)
|
// This is done since the uri wouldn't match (Diaspora doesn't transmit it)
|
||||||
if (!empty($parent) && !empty($thr_parent) && in_array(Protocol::DIASPORA, [$parent['network'], $thr_parent['network']])) {
|
// Also transmit relayed posts from Diaspora contacts via Diaspora.
|
||||||
|
if (!empty($parent) && !empty($thr_parent) && in_array(Protocol::DIASPORA, [$parent['network'], $thr_parent['network'], $target_item['network']])) {
|
||||||
$contact['network'] = Protocol::DIASPORA;
|
$contact['network'] = Protocol::DIASPORA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,10 +133,7 @@ class Notifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
|
$top_level = $target_item['gravity'] == GRAVITY_PARENT;
|
||||||
Logger::info('Top level post', ['target' => $target_id]);
|
|
||||||
$top_level = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($uid);
|
$owner = User::getOwnerDataById($uid);
|
||||||
|
@ -774,11 +771,16 @@ class Notifier
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also don't deliver when the direct thread parent was delivered via Diaspora
|
// Also don't deliver when the direct thread parent was delivered via Diaspora
|
||||||
if ($thr_parent['network'] == Protocol::DIASPORA) {
|
if ($thr_parent['network'] == Protocol::DIASPORA) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Posts from Diaspora contacts are transmitted via Diaspora
|
||||||
|
if ($target_item['network'] == Protocol::DIASPORA) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
$inboxes = [];
|
$inboxes = [];
|
||||||
$relay_inboxes = [];
|
$relay_inboxes = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue