Merge pull request #3074 from annando/1701-diaspora-ostatus-mentions

Bugfix: Answers to OStatus posts should never reach Diaspora
This commit is contained in:
rabuzarus 2017-01-12 02:12:25 +01:00 committed by GitHub
commit 63e2695d22

View file

@ -64,8 +64,9 @@ function notifier_run(&$argv, &$argc){
load_hooks();
if($argc < 3)
if ($argc < 3) {
return;
}
$a->set_baseurl(get_config('system','url'));
@ -106,8 +107,7 @@ function notifier_run(&$argv, &$argc){
$recipients[] = $message[0]['contact-id'];
$item = $message[0];
}
elseif($cmd === 'expire') {
} elseif ($cmd === 'expire') {
$normal_mode = false;
$expire = true;
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
@ -116,18 +116,19 @@ function notifier_run(&$argv, &$argc){
);
$uid = $item_id;
$item_id = 0;
if(! count($items))
if (! count($items)) {
return;
}
elseif($cmd === 'suggest') {
} elseif ($cmd === 'suggest') {
$normal_mode = false;
$fsuggest = true;
$suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
intval($item_id)
);
if(! count($suggest))
if (! count($suggest)) {
return;
}
$uid = $suggest[0]['uid'];
$recipients[] = $suggest[0]['cid'];
$item = $suggest[0];
@ -150,9 +151,9 @@ function notifier_run(&$argv, &$argc){
$self = $r[0];
$r = q("SELECT * FROM `contact` WHERE NOT `self` AND `uid` = %d", intval($item_id));
if(!$r)
if (!$r) {
return;
}
require_once('include/Contact.php');
foreach ($r as $contact) {
terminate_friendship($user, $self, $contact);
@ -191,9 +192,10 @@ function notifier_run(&$argv, &$argc){
// avoid race condition with deleting entries
if ($items[0]['deleted']) {
foreach($items as $item)
foreach ($items as $item) {
$item['deleted'] = 1;
}
}
if ((count($items) == 1) && ($items[0]['id'] === $target_item['id']) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
logger('notifier: top level post');
@ -220,6 +222,9 @@ function notifier_run(&$argv, &$argc){
$hub = get_config('system','huburl');
// Should the post be transmitted to Diaspora?
$diaspora_delivery = true;
// If this is a public conversation, notify the feed hub
$public_message = true;
@ -240,7 +245,7 @@ function notifier_run(&$argv, &$argc){
$thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
// This is IMPORTANT!!!!
@ -264,9 +269,9 @@ function notifier_run(&$argv, &$argc){
$localhost = str_replace('www.','',$a->get_hostname());
if(strpos($localhost,':'))
if (strpos($localhost,':')) {
$localhost = substr($localhost,0,strpos($localhost,':'));
}
/**
*
* Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
@ -290,12 +295,12 @@ function notifier_run(&$argv, &$argc){
// we will just use it as a fallback test
// later we will be able to use it as the primary test of whether or not to relay.
if(! $target_item['origin'])
if (! $target_item['origin']) {
$relay_to_owner = false;
if($parent['origin'])
}
if ($parent['origin']) {
$relay_to_owner = false;
}
if ($relay_to_owner) {
logger('notifier: followup '.$target_item["guid"], LOGGER_DEBUG);
// local followup to remote post
@ -322,11 +327,13 @@ function notifier_run(&$argv, &$argc){
intval($uid),
dbesc(NETWORK_DFRN)
);
if (dbm::is_result($r))
foreach($r as $rr)
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$recipients_followup[] = $rr['id'];
}
}
}
}
logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
} else {
$followup = false;
@ -371,8 +378,7 @@ function notifier_run(&$argv, &$argc){
if (substr($person,0,4) === 'cid:') {
$recipients[] = intval(substr($person,4));
$conversants[] = intval(substr($person,4));
}
else {
} else {
$url_recipients[] = substr($person,4);
}
}
@ -396,16 +402,19 @@ function notifier_run(&$argv, &$argc){
// We have not only to look at the parent, since it could be a Friendica thread.
if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
$diaspora_delivery = false;
logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent[0]['author-link']." - Owner: ".$thr_parent[0]['owner-link'], LOGGER_DEBUG);
// Send a salmon to the parent author
$r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
$r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
dbesc(normalise_link($thr_parent[0]['author-link'])),
intval($uid));
if ($r)
if (dbm::is_result($r)) {
$probed_contact = $r[0];
else
} else {
$probed_contact = probe_url($thr_parent[0]['author-link']);
}
if ($probed_contact["notify"] != "") {
logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
@ -413,13 +422,15 @@ function notifier_run(&$argv, &$argc){
}
// Send a salmon to the parent owner
$r = q("SELECT `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
$r = q("SELECT `url`, `notify` FROM `contact` WHERE `nurl`='%s' AND `uid` IN (0, %d) AND `notify` != ''",
dbesc(normalise_link($thr_parent[0]['owner-link'])),
intval($uid));
if ($r)
if (dbm::is_result($r)) {
$probed_contact = $r[0];
else
} else {
$probed_contact = probe_url($thr_parent[0]['owner-link']);
}
if ($probed_contact["notify"] != "") {
logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
@ -441,16 +452,12 @@ function notifier_run(&$argv, &$argc){
// It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora
$sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."')";
} else
} else {
$sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')";
$r = q("SELECT * FROM `contact` WHERE `id` IN ($conversant_str) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra);
if (dbm::is_result($r))
$contacts = $r;
} else
}
} else {
$public_message = false;
}
// If this is a public message and pubmail is set on the parent, include all your email contacts
@ -465,39 +472,40 @@ function notifier_run(&$argv, &$argc){
dbesc(NETWORK_MAIL)
);
if (dbm::is_result($r)) {
foreach($r as $rr)
foreach ($r as $rr) {
$recipients[] = $rr['id'];
}
}
}
}
if($followup)
if ($followup) {
$recip_str = implode(', ', $recipients_followup);
else
} else {
$recip_str = implode(', ', $recipients);
if ($relocate)
}
if ($relocate) {
$r = $recipients_relocate;
else
$r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`",
} else {
$r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra,
dbesc($recip_str)
);
}
$interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
// If we are using the worker we don't need a delivery interval
if (get_config("system", "worker"))
if (get_config("system", "worker")) {
$interval = false;
}
// delivery loop
if (dbm::is_result($r)) {
foreach ($r as $contact) {
if (!$contact['self']) {
if(($contact['network'] === NETWORK_DIASPORA) && ($public_message))
if (($contact['network'] === NETWORK_DIASPORA) && ($public_message)) {
continue;
}
q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)",
dbesc($cmd),
intval($item_id),
@ -520,17 +528,18 @@ function notifier_run(&$argv, &$argc){
// When using the workerqueue, we don't need this functionality.
$deliveries_per_process = intval(get_config('system','delivery_batch_count'));
if (($deliveries_per_process <= 0) OR get_config("system", "worker"))
if (($deliveries_per_process <= 0) OR get_config("system", "worker")) {
$deliveries_per_process = 1;
}
$this_batch = array();
for ($x = 0; $x < count($r); $x ++) {
$contact = $r[$x];
if($contact['self'])
if ($contact['self']) {
continue;
}
logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
// potentially more than one recipient. Start a new process and space them out a bit.
@ -541,16 +550,18 @@ function notifier_run(&$argv, &$argc){
if (count($this_batch) >= $deliveries_per_process) {
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
$this_batch = array();
if($interval)
if ($interval) {
@time_sleep_until(microtime(true) + (float) $interval);
}
}
continue;
}
// be sure to pick up any stragglers
if(count($this_batch))
if (count($this_batch)) {
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch);
}
}
// send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
// They are especially used for notifications to OStatus users that don't follow us.
@ -570,10 +581,13 @@ function notifier_run(&$argv, &$argc){
if ($public_message) {
if (!$followup)
$r0 = Diaspora::relay_list();
else
$r0 = array();
$r1 = array();
if ($diaspora_delivery) {
if (!$followup) {
$r0 = Diaspora::relay_list();
}
$r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()",
@ -581,6 +595,7 @@ function notifier_run(&$argv, &$argc){
intval($owner['uid']),
intval(CONTACT_IS_SHARING)
);
}
$r2 = q("SELECT `id`, `name`,`network` FROM `contact`
WHERE `network` in ( '%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive`
@ -621,11 +636,12 @@ function notifier_run(&$argv, &$argc){
if ((! $mail) && (! $fsuggest) && (! $followup)) {
logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']);
if($interval)
if ($interval) {
@time_sleep_until(microtime(true) + (float) $interval);
}
}
}
}
$push_notify = true;
@ -637,8 +653,9 @@ function notifier_run(&$argv, &$argc){
if (count($hubs)) {
foreach ($hubs as $h) {
$h = trim($h);
if(! strlen($h))
if (! strlen($h)) {
continue;
}
if ($h === '[internal]') {
// Set push flag for PuSH subscribers to this topic,
@ -654,10 +671,11 @@ function notifier_run(&$argv, &$argc){
post_url($h,$params);
logger('publish for item '.$item_id.' ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code());
}
if(count($hubs) > 1)
if (count($hubs) > 1) {
sleep(7); // try and avoid multiple hubs responding at precisely the same time
}
}
}
// Handling the pubsubhubbub requests
proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
@ -665,8 +683,9 @@ function notifier_run(&$argv, &$argc){
logger('notifier: calling hooks', LOGGER_DEBUG);
if($normal_mode)
if ($normal_mode) {
call_hooks('notifier_normal',$target_item);
}
call_hooks('notifier_end',$target_item);