got comments going back and forth - we really need local_deliver now since even local deliveries are going through zot and that isn't necessary or desirable in the long term

This commit is contained in:
friendica 2012-11-27 17:09:01 -08:00
parent f3fdbb6021
commit 2fe2de1d5a
4 changed files with 36 additions and 19 deletions

View File

@ -1249,7 +1249,7 @@ function item_store($arr,$force_parent = false) {
dbesc($arr['uri']), dbesc($arr['uri']),
intval($arr['uid']) intval($arr['uid'])
); );
if($r && count($r)) { if($r) {
logger('item-store: duplicate item ignored. ' . print_r($arr,true)); logger('item-store: duplicate item ignored. ' . print_r($arr,true));
return 0; return 0;
} }

View File

@ -43,6 +43,7 @@ require_once('include/html2plain.php');
* *
* ZOT * ZOT
* permission_updated abook_id * 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 // Normal items
// Fetch the target item // Fetch the target item
dbg(1);
$r = q("SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1", $r = q("SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1",
intval($item_id) intval($item_id)
); );
if(! $r) if(! $r)
return; return;
logger('notify1');
xchan_query($r); xchan_query($r);
dbg(0);
$r = fetch_post_tags($r); $r = fetch_post_tags($r);
$target_item = $r[0]; $target_item = $r[0];
@ -188,7 +189,7 @@ dbg(0);
if($s) if($s)
$channel = $s[0]; $channel = $s[0];
logger('notify2');
if($target_item['id'] == $target_item['parent']) { if($target_item['id'] == $target_item['parent']) {
$parent_item = $target_item; $parent_item = $target_item;
$top_level_post = true; $top_level_post = true;
@ -199,8 +200,6 @@ logger('notify2');
intval($target_item['parent']) intval($target_item['parent'])
); );
logger('notify3');
if(! $r) if(! $r)
return; return;
xchan_query($r); xchan_query($r);
@ -209,7 +208,7 @@ logger('notify3');
$parent_item = $r[0]; $parent_item = $r[0];
$top_level_post = false; $top_level_post = false;
} }
logger('notify4');
$encoded_item = encode_item($target_item); $encoded_item = encode_item($target_item);
@ -224,6 +223,8 @@ logger('notify4');
} }
else { else {
logger('notifier: normal distribution', LOGGER_DEBUG); logger('notifier: normal distribution', LOGGER_DEBUG);
if($cmd === 'relay')
logger('notifier: owner relay');
$private = false; $private = false;
$recipients = collect_recipients($parent_item,$private); $recipients = collect_recipients($parent_item,$private);
@ -265,7 +266,6 @@ logger('notify4');
$deliveries_per_process = 1; $deliveries_per_process = 1;
$deliver = array(); $deliver = array();
$current_count = 0;
foreach($hubs as $hub) { foreach($hubs as $hub) {
$hash = random_string(); $hash = random_string();
@ -282,8 +282,8 @@ logger('notify4');
dbesc(json_encode($encoded_item)) dbesc(json_encode($encoded_item))
); );
$deliver[] = $hash; $deliver[] = $hash;
$current_count ++;
if($current_count >= $deliveries_per_process) { if(count($deliver) >= $deliveries_per_process) {
proc_run('php','include/deliver.php',$deliver); proc_run('php','include/deliver.php',$deliver);
$deliver = array(); $deliver = array();
if($interval) if($interval)

View File

@ -610,6 +610,9 @@ function zot_import($arr) {
logger('zot_import: ' . print_r($arr,true), LOGGER_DATA); logger('zot_import: ' . print_r($arr,true), LOGGER_DATA);
$data = json_decode($arr['body'],true); $data = json_decode($arr['body'],true);
logger('zot_import: data1: ' . print_r($data,true));
if(array_key_exists('iv',$data)) { if(array_key_exists('iv',$data)) {
$data = json_decode(aes_unencapsulate($data,get_config('system','prvkey')),true); $data = json_decode(aes_unencapsulate($data,get_config('system','prvkey')),true);
} }
@ -620,6 +623,10 @@ function zot_import($arr) {
if(is_array($incoming)) { if(is_array($incoming)) {
foreach($incoming as $i) { 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)); $i['notify']['sender']['hash'] = base64url_encode(hash('whirlpool',$i['notify']['sender']['guid'] . $i['notify']['sender']['guid_sig'], true));
$deliveries = null; $deliveries = null;
@ -658,7 +665,8 @@ function zot_import($arr) {
logger('Activity received: ' . print_r($arr,true)); logger('Activity received: ' . print_r($arr,true));
logger('Activity recipients: ' . print_r($deliveries,true)); logger('Activity recipients: ' . print_r($deliveries,true));
dbg(1); 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); dbg(0);
} }
elseif($i['message']['type'] === 'mail') { 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) { foreach($deliveries as $d) {
@ -746,28 +754,37 @@ function process_delivery($sender,$arr,$deliveries) {
continue; continue;
} }
if($arr['item_restrict'] & ITEM_DELETED) { if($arr['item_restrict'] & ITEM_DELETED) {
delete_imported_item($sender,$arr,$channel['channel_id']); delete_imported_item($sender,$arr,$channel['channel_id']);
continue; 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']), dbesc($arr['uri']),
intval($channel['uid']) intval($channel['channel_id'])
); );
if($r) if($r) {
update_imported_item($sender,$arr,$channel['channel_id']); if($arr['edited'] > $r[0]['edited'])
update_imported_item($sender,$arr,$channel['channel_id']);
$item_id = $r[0]['id'];
}
else { else {
$arr['aid'] = $channel['channel_account_id']; $arr['aid'] = $channel['channel_account_id'];
$arr['uid'] = $channel['channel_id']; $arr['uid'] = $channel['channel_id'];
$item_id = item_store($arr); $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) { function update_imported_item($sender,$item,$uid) {
// FIXME // FIXME
logger('item exists: updating or ignoring'); logger('update_imported_item');
} }

View File

@ -1 +1 @@
2012-11-26.151 2012-11-27.152