Reworked receiver detection
This commit is contained in:
parent
555856208e
commit
d64c910f69
|
@ -207,8 +207,6 @@ class Receiver
|
||||||
$uid = self::getFirstUserFromReceivers($receivers);
|
$uid = self::getFirstUserFromReceivers($receivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::log('Receivers: ' . $uid . ' - ' . json_encode($receivers), Logger::DEBUG);
|
|
||||||
|
|
||||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||||
if (empty($object_id)) {
|
if (empty($object_id)) {
|
||||||
Logger::log('No object found', Logger::DEBUG);
|
Logger::log('No object found', Logger::DEBUG);
|
||||||
|
@ -539,19 +537,7 @@ class Receiver
|
||||||
$receivers['uid:-1'] = -1;
|
$receivers['uid:-1'] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
|
// Fetch the receivers for the public and the followers collection
|
||||||
// This will most likely catch all OStatus connections to Mastodon
|
|
||||||
$condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
|
|
||||||
, 'archive' => false, 'pending' => false];
|
|
||||||
$contacts = DBA::select('contact', ['uid'], $condition);
|
|
||||||
while ($contact = DBA::fetch($contacts)) {
|
|
||||||
if ($contact['uid'] != 0) {
|
|
||||||
$receivers['uid:' . $contact['uid']] = $contact['uid'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DBA::close($contacts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
|
if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
|
||||||
$receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
|
$receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
|
||||||
continue;
|
continue;
|
||||||
|
@ -599,12 +585,23 @@ class Receiver
|
||||||
* @return array with receivers (user id)
|
* @return array with receivers (user id)
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getReceiverForActor($actor, $tags)
|
private static function getReceiverForActor($actor, $tags)
|
||||||
{
|
{
|
||||||
$receivers = [];
|
$receivers = [];
|
||||||
$networks = Protocol::FEDERATED;
|
$basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
|
||||||
$condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
|
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
|
||||||
'network' => $networks, 'archive' => false, 'pending' => false];
|
|
||||||
|
$condition = DBA::mergeConditions($basecondition, ['nurl' => Strings::normaliseLink($actor)]);
|
||||||
|
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
|
||||||
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
|
if (self::isValidReceiverForActor($contact, $actor, $tags)) {
|
||||||
|
$receivers['uid:' . $contact['uid']] = $contact['uid'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DBA::close($contacts);
|
||||||
|
|
||||||
|
// The queries are split because of performance issues
|
||||||
|
$condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?)", Strings::normaliseLink($actor), $actor]);
|
||||||
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
|
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
|
||||||
while ($contact = DBA::fetch($contacts)) {
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
if (self::isValidReceiverForActor($contact, $actor, $tags)) {
|
if (self::isValidReceiverForActor($contact, $actor, $tags)) {
|
||||||
|
|
Loading…
Reference in a new issue