diff options
Diffstat (limited to 'include')
-rwxr-xr-x | include/items.php | 2 | ||||
-rw-r--r-- | include/notifier.php | 20 | ||||
-rw-r--r-- | include/zot.php | 31 |
3 files changed, 35 insertions, 18 deletions
diff --git a/include/items.php b/include/items.php index 47b919bc6..a6ecbbb88 100755 --- a/include/items.php +++ b/include/items.php @@ -1249,7 +1249,7 @@ function item_store($arr,$force_parent = false) { dbesc($arr['uri']), intval($arr['uid']) ); - if($r && count($r)) { + if($r) { logger('item-store: duplicate item ignored. ' . print_r($arr,true)); return 0; } diff --git a/include/notifier.php b/include/notifier.php index b4ccf69cc..21f587708 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -43,6 +43,7 @@ require_once('include/html2plain.php'); * * ZOT * permission_updated abook_id + * relay item_id (item was relayed to owner, we will deliver it as owner) * */ @@ -168,16 +169,16 @@ function notifier_run($argv, $argc){ // Normal items // Fetch the target item -dbg(1); + $r = q("SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1", intval($item_id) ); if(! $r) return; -logger('notify1'); + xchan_query($r); -dbg(0); + $r = fetch_post_tags($r); $target_item = $r[0]; @@ -188,7 +189,7 @@ dbg(0); if($s) $channel = $s[0]; -logger('notify2'); + if($target_item['id'] == $target_item['parent']) { $parent_item = $target_item; $top_level_post = true; @@ -199,8 +200,6 @@ logger('notify2'); intval($target_item['parent']) ); -logger('notify3'); - if(! $r) return; xchan_query($r); @@ -209,7 +208,7 @@ logger('notify3'); $parent_item = $r[0]; $top_level_post = false; } -logger('notify4'); + $encoded_item = encode_item($target_item); @@ -224,6 +223,8 @@ logger('notify4'); } else { logger('notifier: normal distribution', LOGGER_DEBUG); + if($cmd === 'relay') + logger('notifier: owner relay'); $private = false; $recipients = collect_recipients($parent_item,$private); @@ -265,7 +266,6 @@ logger('notify4'); $deliveries_per_process = 1; $deliver = array(); - $current_count = 0; foreach($hubs as $hub) { $hash = random_string(); @@ -282,8 +282,8 @@ logger('notify4'); dbesc(json_encode($encoded_item)) ); $deliver[] = $hash; - $current_count ++; - if($current_count >= $deliveries_per_process) { + + if(count($deliver) >= $deliveries_per_process) { proc_run('php','include/deliver.php',$deliver); $deliver = array(); if($interval) diff --git a/include/zot.php b/include/zot.php index 654b17353..318948ccc 100644 --- a/include/zot.php +++ b/include/zot.php @@ -610,6 +610,9 @@ function zot_import($arr) { logger('zot_import: ' . print_r($arr,true), LOGGER_DATA); $data = json_decode($arr['body'],true); + + logger('zot_import: data1: ' . print_r($data,true)); + if(array_key_exists('iv',$data)) { $data = json_decode(aes_unencapsulate($data,get_config('system','prvkey')),true); } @@ -620,6 +623,10 @@ function zot_import($arr) { if(is_array($incoming)) { foreach($incoming as $i) { + if(array_key_exists('iv',$i['notify'])) { + $i['notify'] = json_decode(aes_unencapsulate($i['notify'],get_config('system','prvkey')),true); + } + $i['notify']['sender']['hash'] = base64url_encode(hash('whirlpool',$i['notify']['sender']['guid'] . $i['notify']['sender']['guid_sig'], true)); $deliveries = null; @@ -658,7 +665,8 @@ function zot_import($arr) { logger('Activity received: ' . print_r($arr,true)); logger('Activity recipients: ' . print_r($deliveries,true)); dbg(1); - process_delivery($i['notify']['sender'],$arr,$deliveries); + $relay = ((array_key_exists('flags',$i['message']) && in_array('relay',$i['message']['flags'])) ? true : false); + process_delivery($i['notify']['sender'],$arr,$deliveries,$relay); dbg(0); } elseif($i['message']['type'] === 'mail') { @@ -726,7 +734,7 @@ function public_recips($msg) { } -function process_delivery($sender,$arr,$deliveries) { +function process_delivery($sender,$arr,$deliveries,$relay) { foreach($deliveries as $d) { @@ -745,29 +753,38 @@ function process_delivery($sender,$arr,$deliveries) { logger("permission denied for delivery {$channel['channel_id']}"); continue; } + if($arr['item_restrict'] & ITEM_DELETED) { delete_imported_item($sender,$arr,$channel['channel_id']); continue; } - $r = q("select edited from item where uri = '%s' and uid = %d limit 1", + $r = q("select id, edited from item where uri = '%s' and uid = %d limit 1", dbesc($arr['uri']), - intval($channel['uid']) + intval($channel['channel_id']) ); - if($r) - update_imported_item($sender,$arr,$channel['channel_id']); + if($r) { + if($arr['edited'] > $r[0]['edited']) + update_imported_item($sender,$arr,$channel['channel_id']); + $item_id = $r[0]['id']; + } else { $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; $item_id = item_store($arr); } + + if($relay && $item_id) { + logger('process_delivery: invoking relay'); + proc_run('php','include/notifier.php','relay',intval($item_id)); + } } } function update_imported_item($sender,$item,$uid) { // FIXME - logger('item exists: updating or ignoring'); + logger('update_imported_item'); } |