From 3fc23a34b690f9e1dbc6dba1f387611b95a86001 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Tue, 3 Sep 2024 06:49:03 +1000 Subject: [PATCH] couple of identity matcher fixes --- src/Daemon/Notifier.php | 6 +---- src/Lib/Activity.php | 46 ++++++++++++++++++++++++++++++++++++- src/Lib/ActivityStreams.php | 6 +++++ src/Module/Inbox.php | 9 +++++++- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/Daemon/Notifier.php b/src/Daemon/Notifier.php index 2d8ae4995..1b50ccd48 100644 --- a/src/Daemon/Notifier.php +++ b/src/Daemon/Notifier.php @@ -625,7 +625,6 @@ class Notifier implements DaemonInterface } logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list, true), LOGGER_DEBUG); - // Now we have collected recipients (except for external mentions, @FIXME) // Let's reduce this to a set of hubs; checking that the site is not dead. @@ -661,7 +660,6 @@ class Notifier implements DaemonInterface } } } - if (! $hubs) { logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE); return; @@ -865,9 +863,7 @@ class Notifier implements DaemonInterface if ($parentItem['replyto']) { $ptr = unserialise($parentItem['replyto']); if (is_string($ptr)) { - if (ActivityStreams::is_url($ptr)) { - $audience[] = $ptr; - } + $audience[] = $ptr; } elseif (is_array($ptr)) { foreach ($ptr as $rto) { if (is_string($rto) && ActivityStreams::is_url($rto)) { diff --git a/src/Lib/Activity.php b/src/Lib/Activity.php index 4b233e617..7a6942fc8 100644 --- a/src/Lib/Activity.php +++ b/src/Lib/Activity.php @@ -2407,9 +2407,10 @@ class Activity $ap_hubloc = null; $hublocs = self::get_actor_hublocs($url); + if ($hublocs) { foreach ($hublocs as $hub) { - if ($hub['hubloc_network'] === 'activitypub') { + if (in_array($hub['hubloc_network'], ['activitypub', 'apnomadic'])) { $ap_hubloc = $hub; } if (in_array($hub['hubloc_network'],['zot6','nomad'])) { @@ -2847,6 +2848,15 @@ class Activity return; } + $hublocs = self::get_actor_hublocs($portableId); + if ($hublocs) { + foreach ($hublocs as $hubloc) { + if (in_array($hubloc['hubloc_network'], ['zot6', 'nomad'])) { + return; + } + } + } + $count = 0; foreach ($gateways as $gateway) { @@ -4650,6 +4660,20 @@ class Activity public static function find_best_identity($xchan) { + $actorId = new ActorId($xchan); + if ($actorId->getType() === ActorId::ACTORID_TYPE_DIDKEY) { + $query = q("select * from xchan where xchan_epubkey = '%s'", + dbesc(str_replace('did:key:', '', $actorId->getId())) + ); + if ($query) { + foreach ($query as $test) { + if (in_array($test['xchan_network'], ['zot6', 'nomad'])) { + return $test['xchan_hash']; + } + } + } + } + $r = q( "select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0 order by hubloc_id desc", dbesc($xchan) @@ -5159,6 +5183,26 @@ class Activity } } + // Edge case. Communications from an apnomadic URL, but they also have a zot6 or nomad hubloc record + // with a traditional hubloc_id_url. Pull out the xchan_hash of the zot6/nomad identity and use it + // instead of the URL that was passed. + + $actorId = new ActorId($url); + if ($actorId->getType() === ActorId::ACTORID_TYPE_DIDKEY) { + $ekey = str_replace('did:key:', '', $actorId->getId()); + $query = q("select * from xchan where epubkey = '%s'", + dbesc($ekey) + ); + if ($query) { + foreach ($query as $test) { + if (in_array($test['xchan_network'], ['nomad', 'zot6'])) { + $url = $test['xchan_hash']; + break; + } + } + } + } + return match (trim($options_arr[0])) { 'activitypub' => q( "select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' $sql_options order by hubloc_id DESC ", diff --git a/src/Lib/ActivityStreams.php b/src/Lib/ActivityStreams.php index 81b17f5d1..0b796badd 100644 --- a/src/Lib/ActivityStreams.php +++ b/src/Lib/ActivityStreams.php @@ -117,6 +117,12 @@ class ActivityStreams if (!$this->replyto) { $this->replyto = $this->get_property_obj('replyTo'); } + if ($this->replyto) { + $actorId = new ActorId($this->replyto); + if ($actorId->getType() !== ActorId::ACTORID_TYPE_URL) { + $this->replyto = Activity::find_best_identity($actorId->getId()); + } + } $this->edsig = $this->get_compound_property('proof'); if ($this->edsig) { diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index e5d96f5b5..8a6d21df3 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -145,7 +145,14 @@ class Inbox extends Controller // if the sender has the ability to send messages over zot/nomad, ignore messages sent via activitypub // as observer aware features and client side markup will be unavailable - $test = Activity::get_actor_hublocs($hsig['portable_id'], 'all,not_deleted'); + if (str_starts_with($hsig['portable_id'], 'did:key:')) { + $test = q("select xchan_network as hubloc_network from xchan where xchan_epubkey = '%s'", + dbesc(str_replace('did:key:', '', $hsig['portable_id'])) + ); + } + else { + $test = Activity::get_actor_hublocs($hsig['portable_id'], 'all,not_deleted'); + } if ($test) { foreach ($test as $t) { if (in_array($t['hubloc_network'], ['zot6', 'nomad'])) {