diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index f21c3431e..3bb97b2fe 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1854,7 +1854,7 @@ class Activity { if ($abconfig) { $clone['abconfig'] = $abconfig; } - Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => array($clone) ] ); + Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => [ $clone ] ] ); } } diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index b92b49ce7..2c198c1f9 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -341,7 +341,7 @@ class ActivityStreams { function get_actor($property,$base='',$namespace = '') { $x = $this->get_property_obj($property, $base, $namespace); - if ($this->is_url($x)) { + if (self::is_url($x)) { // SECURITY: If we have already stored the actor profile, re-generate it // from cached data - don't refetch it from the network @@ -380,7 +380,7 @@ class ActivityStreams { function get_compound_property($property, $base = '', $namespace = '', $first = false) { $x = $this->get_property_obj($property, $base, $namespace); - if ($this->is_url($x)) { + if (self::is_url($x)) { $y = $this->fetch_property($x); if (is_array($y)) { $x = $y; @@ -420,7 +420,7 @@ class ActivityStreams { * @return boolean */ - function is_url($url) { + static public function is_url($url) { if (($url) && (! is_array($url)) && ((strpos($url, 'http') === 0) || (strpos($url,'x-zot') === 0) || (strpos($url,'bear') === 0))) { return true; } diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index f00e69dde..e62a5f5be 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -481,6 +481,13 @@ class Libsync { foreach ($arr['abook'] as $abook) { + // this is here for debugging so we can find the issue source + + if (! is_array($abook)) { + btlogger('abook is not an array'); + continue; + } + $abconfig = null; if (array_key_exists('abconfig',$abook) && is_array($abook['abconfig']) && count($abook['abconfig'])) { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 75d44b469..b454f3cc9 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -513,11 +513,11 @@ class Libzot { unset($new_connection[0]['abook_id']); unset($new_connection[0]['abook_account']); unset($new_connection[0]['abook_channel']); - $abconfig = load_abconfig($channel['channel_id'],$new_connection['abook_xchan']); + $abconfig = load_abconfig($channel['channel_id'],$new_connection[0]['abook_xchan']); if ($abconfig) { - $new_connection['abconfig'] = $abconfig; + $new_connection[0]['abconfig'] = $abconfig; } - Libsync::build_sync_packet($channel['channel_id'], array('abook' => $new_connection)); + Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => $new_connection ]); } } diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php index 1675f68eb..968fa3384 100644 --- a/Zotlabs/Lib/Queue.php +++ b/Zotlabs/Lib/Queue.php @@ -106,12 +106,16 @@ class Queue { static function insert($arr) { + logger('insert: ' . print_r($arr,true), LOGGER_DATA); + // do not queue anything with no destination - if(! (array_key_exists('posturl',$arr) && trim($arr['posturl']))) { + if (! (array_key_exists('posturl',$arr) && trim($arr['posturl']))) { + logger('no destination'); return false; } + $x = q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority, outq_created, outq_updated, outq_scheduled, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s' )", @@ -235,7 +239,13 @@ class Queue { logger('missing channel: ' . $outq['outq_channel']); return; } - + + if (! ActivityStreams::is_url($outq['outq_posturl'])) { + logger('fetch item is not url: ' . $outq['outq_posturl']); + self::remove($outq['outq_hash']); + return; + } + $j = Activity::fetch($outq['outq_posturl'],$channel); if ($j) { $AS = new ActivityStreams($j, null, true); @@ -243,7 +253,8 @@ class Queue { if (ActivityStreams::is_an_actor($AS->data['type'])) { Activity::actor_store($AS->data['id'],$AS->data); } - if (strpos($AS->data['type'],'Collection')) { + if (strpos($AS->data['type'],'Collection') !== false) { + // we are probably fetching a collection already - and do not support collection recursion at this time self::remove($outq['outq_hash']); return; } diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index d85de64a6..3f6e30b48 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -6,6 +6,7 @@ use Zotlabs\Web\Controller; use Zotlabs\Lib\Activity; use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\ASCollection; +use Zotlabs\Lib\Queue; use Zotlabs\Daemon\Run; require_once("include/bbcode.php"); @@ -66,7 +67,8 @@ class Search extends Controller { // ActivityStreams object fetches from the navbar - if (local_channel() && strpos($search,'https://') === 0) { + if (local_channel() && strpos($search,'https://') === 0 && (! $update) && (! $load)) { + logger('searching for ActivityPub'); $channel = App::get_channel(); $hash = EMPTY_STR; $j = Activity::fetch($search,$channel); @@ -79,8 +81,8 @@ class Search extends Controller { if ($AS->is_valid() && isset($AS->data['type'])) { if (is_array($AS->obj)) { // matches Collection and orderedCollection - if (isset($AS->obj['type']) && strpos($AS->obj['type'],'Collection')) { - + if (isset($AS->obj['type']) && strpos($AS->obj['type'],'Collection') !== false) { + // Collections are awkward to process because they can be huge. // Our strategy is to limit a navbar search to 100 Collection items // and only fetch the first 10 conversations in the foreground. @@ -90,22 +92,28 @@ class Search extends Controller { // are fetched in the background while you're looking at the first ones. $max = intval(get_config('system','max_imported_search_collection',100)); + if (intval($max)) { $obj = new ASCollection($search, $channel, 0, $max); $messages = $obj->get(); + // logger('received: ' . print_r($messages,true)); $author = null; if ($messages) { + logger('received ' . count($messages) . ' items from collection.', LOGGER_DEBUG); $processed = 0; foreach ($messages as $message) { $processed ++; // only process the first several items in the foreground and // queue the remainder. if ($processed > 10) { + $fetch_url = ((is_string($message)) ? $message : EMPTY_STR); - $fetch_url = ((is_array($message) && array_key_exists('id',$message)) ? $message_id : $fetch_url); + $fetch_url = ((is_array($message) && array_key_exists('id',$message)) ? $message['id'] : $fetch_url); + if (! $fetch_url) { continue; } + $hash = new_uuid(); Queue::insert( [ @@ -120,6 +128,7 @@ class Search extends Controller { ); continue; } + if (is_string($message)) { $message = Activity::fetch($message,App::get_channel()); }