refactor recip list one more time. Mentions were not getting added correctly.

This commit is contained in:
Mike Macgirvin 2024-06-16 10:48:51 +10:00
parent b10fcd3166
commit 718d5aee94

View file

@ -3,6 +3,7 @@
use Code\Access\Permissions;
use Code\Access\PermissionLimits;
use Code\Extend\Hook;
use Code\Lib\Libzot;
require_once('include/security.php');
@ -543,13 +544,10 @@ function check_deliver_permissions($item, $arr)
if (!in_array($recipient,$willNotSend)) {
$deliverable = true;
}
if (in_array($recipient, [$item['author_xchan'], $item['owner_xchan']])) {
$deliverable = $accepting = true;
}
if (!$deliverable || !$accepting) {
if ($deliverable || !$accepting) {
// Groups don't generally provide send_stream permission as they aren't really following you,
// but they do allow you to send them group targeted posts.
if ($deliverable) {
$r = q("select xchan_hash from xchan where xchan_hash = '%s' and xchan_type = %d",
dbesc($recipient),
intval(XCHAN_TYPE_GROUP)
@ -561,35 +559,25 @@ function check_deliver_permissions($item, $arr)
}
}
}
// Send mentions even if you have no permission to do so. They might allow it.
if ($terms) {
foreach ($terms as $term) {
if (in_array($term['url'], $result)) {
continue;
}
// activitypub is easy because $x will match directly on the mention url
if ($recipient === $term['url'] && (!in_array($recipient, $result))) {
$result[] = $recipient;
break;
}
// zot/nomad is harder because we will need to match the portable_id to the mention url
// and won't be able to perform duplicate detection
$r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($recipient),
dbesc($term['url'])
);
if ($r && !in_array($recipient, $result)) {
$result[] = $recipient;
break;
}
}
}
}
if ($deliverable && $accepting && !in_array($recipient, $result)) {
$result[] = $recipient;
}
}
// Send mentions even if you have no permission to do so. They might allow it.
if ($terms) {
foreach ($terms as $term) {
$r = q("select * from hubloc where hubloc_hash = '%s' or hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($term['url']),
dbesc($term['url'])
);
$r = Libzot::zot_record_preferred($r);
if ($r && !in_array($r['hubloc_hash'], $result)) {
$result[] = $r['hubloc_hash'];
break;
}
}
}
}
return($result);
}