Merge pull request #5909 from annando/ap-receiver

The outbox is now more complete / No more duplicates in the receiver
This commit is contained in:
Tobias Diekershoff 2018-10-14 10:06:39 +02:00 committed by GitHub
commit fe9b283057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,8 +151,8 @@ class Transmitter
{ {
$public_contact = Contact::getIdForURL($owner['url'], 0, true); $public_contact = Contact::getIdForURL($owner['url'], 0, true);
$condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact, $condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
'deleted' => false, 'visible' => true]; 'deleted' => false, 'visible' => true];
$count = DBA::count('item', $condition); $count = DBA::count('item', $condition);
@ -329,6 +329,10 @@ class Transmitter
if (!empty($profile) && empty($contacts[$profile['url']])) { if (!empty($profile) && empty($contacts[$profile['url']])) {
$data['to'][] = $profile['url']; $data['to'][] = $profile['url'];
$contacts[$profile['url']] = $profile['url']; $contacts[$profile['url']] = $profile['url'];
if (($key = array_search($profile['url'], $data['cc'])) !== false) {
unset($data['cc'][$key]);
}
} }
} }
} else { } else {
@ -342,6 +346,10 @@ class Transmitter
$contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]);
$data['to'][] = $contact['url']; $data['to'][] = $contact['url'];
$contacts[$contact['url']] = $contact['url']; $contacts[$contact['url']] = $contact['url'];
if (($key = array_search($profile['url'], $data['cc'])) !== false) {
unset($data['cc'][$key]);
}
} }
} }
@ -354,7 +362,7 @@ class Transmitter
} }
} }
$parents = Item::select(['id', 'author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
while ($parent = Item::fetch($parents)) { while ($parent = Item::fetch($parents)) {
// Don't include data from future posts // Don't include data from future posts
if ($parent['id'] >= $item['id']) { if ($parent['id'] >= $item['id']) {
@ -362,6 +370,15 @@ class Transmitter
} }
$profile = APContact::getByURL($parent['author-link'], false); $profile = APContact::getByURL($parent['author-link'], false);
if (!empty($profile) && ($parent['uri'] == $item['thr-parent'])) {
$data['to'][] = $profile['url'];
$contacts[$profile['url']] = $profile['url'];
if (($key = array_search($profile['url'], $data['cc'])) !== false) {
unset($data['cc'][$key]);
}
}
if (!empty($profile) && empty($contacts[$profile['url']])) { if (!empty($profile) && empty($contacts[$profile['url']])) {
$data['cc'][] = $profile['url']; $data['cc'][] = $profile['url'];
$contacts[$profile['url']] = $profile['url']; $contacts[$profile['url']] = $profile['url'];
@ -379,7 +396,15 @@ class Transmitter
} }
DBA::close($parents); DBA::close($parents);
return $data; if (($key = array_search($item['author-link'], $data['to'])) !== false) {
unset($data['to'][$key]);
}
if (($key = array_search($item['author-link'], $data['cc'])) !== false) {
unset($data['cc'][$key]);
}
return ['to' => array_values(array_unique($data['to'])), 'cc' => array_values(array_unique($data['cc']))];
} }
/** /**