mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-11 09:34:26 +02:00
Improved delivery / fix falsely delivery content via DFRN
This commit is contained in:
parent
a3f38d36b9
commit
5e3f9d1235
2 changed files with 112 additions and 107 deletions
|
@ -637,14 +637,6 @@ class Transmitter
|
|||
$audience[] = $owner['url'];
|
||||
}
|
||||
|
||||
if (self::isAnnounce($item) || self::isAPPost($last_id)) {
|
||||
// Will be activated in a later step
|
||||
$networks = Protocol::FEDERATED;
|
||||
} else {
|
||||
// For now only send to these contacts:
|
||||
$networks = [Protocol::ACTIVITYPUB];
|
||||
}
|
||||
|
||||
$data = ['to' => [], 'cc' => [], 'bto' => [], 'bcc' => [], 'audience' => $audience];
|
||||
|
||||
if ($item['gravity'] == Item::GRAVITY_PARENT) {
|
||||
|
@ -704,7 +696,7 @@ class Transmitter
|
|||
$cid = Contact::getIdForURL($term['url'], $item['uid']);
|
||||
if (!empty($cid) && in_array($cid, $receiver_list)) {
|
||||
$contact = DBA::selectFirst('contact', ['url', 'network', 'protocol', 'gsid'], ['id' => $cid, 'network' => Protocol::FEDERATED]);
|
||||
if (!DBA::isResult($contact) || !self::isAPContact($contact, $networks)) {
|
||||
if (!DBA::isResult($contact)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -741,7 +733,7 @@ class Transmitter
|
|||
}
|
||||
|
||||
$contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol', 'gsid'], ['id' => $receiver, 'network' => Protocol::FEDERATED]);
|
||||
if (!DBA::isResult($contact) || !self::isAPContact($contact, $networks)) {
|
||||
if (!DBA::isResult($contact)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -984,44 +976,16 @@ class Transmitter
|
|||
return DBA::exists('inbox-status', ['url' => $url, 'archive' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given contact should be delivered via AP
|
||||
*
|
||||
* @param array $contact Contact array
|
||||
* @param array $networks Array with networks
|
||||
* @return bool Whether the used protocol matches ACTIVITYPUB
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function isAPContact(array $contact, array $networks): bool
|
||||
{
|
||||
if (in_array($contact['network'], $networks) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return GServer::getProtocol($contact['gsid'] ?? 0) == Post\DeliveryData::ACTIVITYPUB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of inboxes of followers of a given user
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @param boolean $all_ap Retrieve all AP enabled inboxes
|
||||
* @return array of follower inboxes
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function fetchTargetInboxesforUser(int $uid, bool $all_ap = false): array
|
||||
public static function fetchTargetInboxesforUser(int $uid): array
|
||||
{
|
||||
$inboxes = [];
|
||||
|
||||
if ($all_ap) {
|
||||
// Will be activated in a later step
|
||||
$networks = Protocol::FEDERATED;
|
||||
} else {
|
||||
// For now only send to these contacts:
|
||||
$networks = [Protocol::ACTIVITYPUB];
|
||||
}
|
||||
|
||||
$condition = [
|
||||
'uid' => $uid,
|
||||
'self' => false,
|
||||
|
@ -1029,37 +993,51 @@ class Transmitter
|
|||
'pending' => false,
|
||||
'blocked' => false,
|
||||
'network' => Protocol::FEDERATED,
|
||||
'contact-type' => [Contact::TYPE_UNKNOWN, Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION],
|
||||
];
|
||||
|
||||
if (!empty($uid)) {
|
||||
$condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND];
|
||||
}
|
||||
|
||||
$contacts = DBA::select('contact', ['id', 'url', 'network', 'protocol', 'gsid'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
if (!self::isAPContact($contact, $networks)) {
|
||||
return self::addInboxesForCondition($condition, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch inboxes for a list of contacts
|
||||
*
|
||||
* @param array $recipients
|
||||
* @param array $inboxes
|
||||
* @return array
|
||||
*/
|
||||
public static function addInboxesForRecipients(array $recipients, array $inboxes): array
|
||||
{
|
||||
return self::addInboxesForCondition(['id' => $recipients], $inboxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of inboxes for a given contact condition
|
||||
*
|
||||
* @param array $condition
|
||||
* @param array $inboxes
|
||||
* @return array
|
||||
*/
|
||||
private static function addInboxesForCondition(array $condition, array $inboxes): array
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ["(`ap-inbox` IS NOT NULL OR `ap-sharedinbox` IS NOT NULL)"]);
|
||||
|
||||
$accounts = DBA::select('account-user-view', ['id', 'url', 'ap-inbox', 'ap-sharedinbox'], $condition);
|
||||
while ($account = DBA::fetch($accounts)) {
|
||||
if (!empty($account['ap-sharedinbox']) && !Contact::isLocal($account['url'])) {
|
||||
$target = $account['ap-sharedinbox'];
|
||||
} elseif (!empty($account['ap-inbox'])) {
|
||||
$target = $account['ap-inbox'];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Network::isUrlBlocked($contact['url'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$profile = APContact::getByURL($contact['url'], false);
|
||||
if (!empty($profile)) {
|
||||
if (empty($profile['sharedinbox']) || Contact::isLocal($contact['url'])) {
|
||||
$target = $profile['inbox'];
|
||||
} else {
|
||||
$target = $profile['sharedinbox'];
|
||||
}
|
||||
if (!self::archivedInbox($target)) {
|
||||
$inboxes[$target][] = $contact['id'];
|
||||
}
|
||||
if (!Transmitter::archivedInbox($target) && (empty($inboxes[$target]) || !in_array($account['id'], $inboxes[$target]))) {
|
||||
$inboxes[$target][] = $account['id'];
|
||||
}
|
||||
}
|
||||
DBA::close($contacts);
|
||||
|
||||
return $inboxes;
|
||||
}
|
||||
|
||||
|
@ -1106,7 +1084,7 @@ class Transmitter
|
|||
}
|
||||
|
||||
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
|
||||
$inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid, true));
|
||||
$inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid));
|
||||
} else {
|
||||
$profile = APContact::getByURL($receiver, false);
|
||||
if (!empty($profile)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue