diff options
author | Mario <mario@mariovavti.com> | 2020-10-12 20:22:07 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-10-12 20:22:07 +0000 |
commit | 8d3c201830020d63a5204df04fdcb2ae04bf2b0f (patch) | |
tree | ce4981bda03362cad20eef11c16fb64bf65a4d0e /include | |
parent | 8595835aa0d5fff5a51d6c8c42dbb6ff140b4f57 (diff) | |
download | volse-hubzilla-8d3c201830020d63a5204df04fdcb2ae04bf2b0f.tar.gz volse-hubzilla-8d3c201830020d63a5204df04fdcb2ae04bf2b0f.tar.bz2 volse-hubzilla-8d3c201830020d63a5204df04fdcb2ae04bf2b0f.zip |
if we receive an item with a zot xchan as author or owner rewrite them to the zot6 xchan if we have their zot6 xchan in abook
Diffstat (limited to 'include')
-rw-r--r-- | include/zot.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/zot.php b/include/zot.php index e10ef6fd7..ce5fd0174 100644 --- a/include/zot.php +++ b/include/zot.php @@ -9,6 +9,7 @@ */ use Zotlabs\Lib\DReport; +use Zotlabs\Lib\Libzot; require_once('include/crypto.php'); require_once('include/items.php'); @@ -1952,6 +1953,31 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ intval($channel['channel_id']), dbesc($arr['owner_xchan']) ); + + if(! $ab) { + + $best_owner_xchan = find_best_zot_identity($arr['owner_xchan']); + + $ab = q("select * from abook where abook_channel = %d and abook_xchan = '%s'", + intval($channel['channel_id']), + dbesc($best_owner_xchan) + ); + + if($ab) + $arr['owner_xchan'] = $best_owner_xchan; + } + + $best_author_xchan = find_best_zot_identity($arr['author_xchan']); + + $ab_author = q("select * from abook where abook_channel = %d and abook_xchan = '%s'", + intval($channel['channel_id']), + dbesc($best_author_xchan) + ); + + if($ab_author) + $arr['author_xchan'] = $best_author_xchan; + + $abook = (($ab) ? $ab[0] : null); if(intval($arr['item_deleted'])) { @@ -2044,6 +2070,10 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $result[] = $DR->get(); } else { + + hz_syslog(print_r($arr,true)); + + $item_result = item_store($arr); if($item_result['success']) { $item_id = $item_result['item_id']; @@ -5341,3 +5371,33 @@ function zot_record_preferred($arr, $check = 'hubloc_network') { return $arr[0]; } + +function find_best_zot_identity($xchan) { + + if (filter_var($xchan, FILTER_VALIDATE_URL)) { + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s'", + dbesc($xchan) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + return $r['hubloc_hash']; + } + } + + $r = q("select hubloc_addr from hubloc where hubloc_hash = '%s'", + dbesc($xchan) + ); + + if ($r) { + + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_addr = '%s'", + dbesc($r[0]['hubloc_addr']) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + return $r['hubloc_hash']; + } + } + + return $xchan; +} |