diff options
Diffstat (limited to 'include/zot.php')
-rw-r--r-- | include/zot.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/zot.php b/include/zot.php index e10ef6fd7..8a2177de7 100644 --- a/include/zot.php +++ b/include/zot.php @@ -9,6 +9,8 @@ */ use Zotlabs\Lib\DReport; +use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Activity; require_once('include/crypto.php'); require_once('include/items.php'); @@ -1952,6 +1954,34 @@ 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) { + logger('rewrite owner: ' . $arr['owner_xchan'] . ' > ' . $best_owner_xchan); + $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) { + logger('rewrite author: ' . $arr['author_xchan'] . ' > ' . $best_author_xchan); + $arr['author_xchan'] = $best_author_xchan; + } + $abook = (($ab) ? $ab[0] : null); if(intval($arr['item_deleted'])) { @@ -5341,3 +5371,24 @@ function zot_record_preferred($arr, $check = 'hubloc_network') { return $arr[0]; } + +function find_best_zot_identity($xchan) { + + $r = q("select hubloc_addr from hubloc where hubloc_hash = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0", + dbesc($xchan) + ); + + if ($r) { + + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_addr = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0", + dbesc($r[0]['hubloc_addr']) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + logger('find_best_zot_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); + return $r['hubloc_hash']; + } + } + + return $xchan; +} |