From 4750775752ed54bb936a302156fec05f2a69dec3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 30 May 2015 21:00:38 +0200 Subject: [PATCH] Cleaning the code. --- include/delivery.php | 47 ++++++++++++++++++++++---------------------- include/notifier.php | 24 ++++++---------------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/include/delivery.php b/include/delivery.php index fbbf7843f6..a913e13170 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -88,23 +88,25 @@ function delivery_run(&$argv, &$argc){ if($cmd === 'expire') { $normal_mode = false; $expire = true; - $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 + $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 30 MINUTE", intval($item_id) ); $uid = $item_id; $item_id = 0; if(! count($items)) - continue; + continue; } else { + // find ancestors $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1", intval($item_id) ); - if((! count($r)) || (! intval($r[0]['parent']))) + if((! count($r)) || (! intval($r[0]['parent']))) { continue; + } $target_item = $r[0]; $parent_id = intval($r[0]['parent']); @@ -116,13 +118,14 @@ function delivery_run(&$argv, &$argc){ continue; - $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` + $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC", intval($parent_id) ); - if(! count($items)) + if(! count($items)) { continue; + } $icontacts = null; $contacts_arr = array(); @@ -130,8 +133,8 @@ function delivery_run(&$argv, &$argc){ if(! in_array($item['contact-id'],$contacts_arr)) $contacts_arr[] = intval($item['contact-id']); if(count($contacts_arr)) { - $str_contacts = implode(',',$contacts_arr); - $icontacts = q("SELECT * FROM `contact` + $str_contacts = implode(',',$contacts_arr); + $icontacts = q("SELECT * FROM `contact` WHERE `id` IN ( $str_contacts ) " ); } @@ -151,10 +154,10 @@ function delivery_run(&$argv, &$argc){ } } - $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, + $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, + `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`, `user`.`prvnets` - FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` + FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($uid) ); @@ -198,13 +201,6 @@ function delivery_run(&$argv, &$argc){ if(strpos($localhost,':')) $localhost = substr($localhost,0,strpos($localhost,':')); - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0", - intval($contact_id) - ); - - if(count($r)) - $contact = $r[0]; - /** * * Be VERY CAREFUL if you make any changes to the following line. Seemingly innocuous changes @@ -213,7 +209,7 @@ function delivery_run(&$argv, &$argc){ * */ - if(!$top_level && ($parent["network"] != NETWORK_OSTATUS) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) { + if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) { logger('relay denied for delivery agent.'); /* no relay allowed for direct contact delivery */ @@ -227,6 +223,13 @@ function delivery_run(&$argv, &$argc){ $public_message = false; // private recipients, not public } + $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0", + intval($contact_id) + ); + + if(count($r)) + $contact = $r[0]; + $hubxml = feed_hublinks(); logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA); @@ -387,15 +390,11 @@ function delivery_run(&$argv, &$argc){ if(! $item_contact) continue; - // For OStatus don't notify all contacts in the thread - if (!$top_level AND ($parent["network"] == NETWORK_OSTATUS) AND ($item["id"] != $item_id)) - continue; - - if(($top_level OR ($parent["network"] == NETWORK_OSTATUS)) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) + if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) $slaps[] = atom_entry($item,'html',null,$owner,true); } - logger('slapdelivery item '.$item_id.' to ' . $contact['name']); + logger('notifier: slapdelivery: ' . $contact['name']); foreach($slaps as $slappy) { if($contact['notify']) { if(! was_recently_delayed($contact['id'])) diff --git a/include/notifier.php b/include/notifier.php index 962090326f..318e0eab25 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -227,9 +227,6 @@ function notifier_run(&$argv, &$argc){ // fill this in with a single salmon slap if applicable $slap = ''; - // List of OStatus receiptians of follow up messages - $ostatus_recip_str = ""; - if(! ($mail || $fsuggest || $relocate)) { require_once('include/group.php'); @@ -303,17 +300,8 @@ function notifier_run(&$argv, &$argc){ $push_notify = true; -/* $ostatus_recipients = array(); - - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'", intval($uid), dbesc(NETWORK_OSTATUS)); - if(count($r)) { - foreach($r as $rr) - $ostatus_recipients[] = $rr['id']; - - $ostatus_recip_str = ", ".implode(', ', $ostatus_recipients); - } -*/ - // Check if the recipient isn't in your contact list + // Check if the recipient isn't in your contact list, try to slap it + // This doesn't seem to work correctly by now $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']); if (count($r)) { $url_recipients = array(); @@ -570,7 +558,7 @@ function notifier_run(&$argv, &$argc){ } if($followup) - $recip_str = $parent['contact-id'].$ostatus_recip_str; + $recip_str = $parent['contact-id']; else $recip_str = implode(', ', $recipients); @@ -591,7 +579,7 @@ function notifier_run(&$argv, &$argc){ if(count($r)) { foreach($r as $contact) { - if((! $mail) && (! $fsuggest) && (!$followup OR ($parent['contact-id'] != $contact['id'])) && (!$relocate) && (! $contact['self'])) { + if((! $mail) && (! $fsuggest) && (! $followup) && (!$relocate) && (! $contact['self'])) { if(($contact['network'] === NETWORK_DIASPORA) && ($public_message)) continue; q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )", @@ -630,7 +618,7 @@ function notifier_run(&$argv, &$argc){ // potentially more than one recipient. Start a new process and space them out a bit. // we will deliver single recipient types of message and email recipients here. - if((! $mail) && (! $fsuggest) && (!$relocate) && (!$followup OR ($parent['contact-id'] != $contact['id']))) { + if((! $mail) && (! $fsuggest) && (!$relocate) && (! $followup)) { $this_batch[] = $contact['id']; @@ -957,7 +945,7 @@ function notifier_run(&$argv, &$argc){ // throw everything into the queue in case we get killed foreach($r as $rr) { - if((! $mail) && (! $fsuggest) && (!$followup OR ($parent['contact-id'] != $contact['id']))) { + if((! $mail) && (! $fsuggest) && (! $followup)) { q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )", dbesc($cmd), intval($item_id), -- 2.39.5