1
0
Fork 0

Code cleanup and first steps for a better comment distribition with DFRN and OStatus

This commit is contained in:
Michael Vogel 2015-12-13 12:15:45 +01:00
parent 169088b243
commit 15063c8d5b
4 changed files with 30 additions and 49 deletions

View file

@ -393,7 +393,6 @@ function delivery_run(&$argv, &$argc){
if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire))
$slaps[] = ostatus_salmon($item,$owner); $slaps[] = ostatus_salmon($item,$owner);
//$slaps[] = atom_entry($item,'html',null,$owner,true);
} }
logger('notifier: slapdelivery: ' . $contact['name']); logger('notifier: slapdelivery: ' . $contact['name']);

View file

@ -302,6 +302,7 @@ function notifier_run(&$argv, &$argc){
$public_message = false; // not public $public_message = false; // not public
$conversant_str = dbesc($parent['contact-id']); $conversant_str = dbesc($parent['contact-id']);
$recipients = array($parent['contact-id']); $recipients = array($parent['contact-id']);
$recipients_followup = array($parent['contact-id']);
//if (!$target_item['private'] AND $target_item['wall'] AND //if (!$target_item['private'] AND $target_item['wall'] AND
if (!$target_item['private'] AND if (!$target_item['private'] AND
@ -309,26 +310,20 @@ function notifier_run(&$argv, &$argc){
$target_item['deny_cid'].$target_item['deny_gid']) == 0)) $target_item['deny_cid'].$target_item['deny_gid']) == 0))
$push_notify = true; $push_notify = true;
// We notify Friendica users in the thread when it is an OStatus thread.
// Hopefully this transfers the messages to the other Friendica servers. (Untested)
if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) { if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
$push_notify = true; $push_notify = true;
if ($parent["network"] == NETWORK_OSTATUS) { if ($parent["network"] == NETWORK_OSTATUS) {
$r = q("SELECT `author-link` FROM `item` WHERE `parent` = %d AND `author-link` != '%s'", // Distribute the message to the DFRN contacts as if this wasn't a followup since OStatus can't relay comments
intval($target_item["parent"]), dbesc($owner['url'])); $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND NOT `blocked` AND NOT `pending`",
foreach($r as $parent_item) { intval($uid),
$probed_contact = probe_url($parent_item["author-link"]); dbesc(NETWORK_DFRN)
if (($probed_contact["notify"] != "") AND ($probed_contact["network"] == NETWORK_DFRN)) { );
logger('Notify Friendica user '.$probed_contact["url"].': '.$probed_contact["notify"]); if(count($r))
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; foreach($r as $rr)
} $recipients_followup[] = $rr['id'];
}
} }
if (count($url_recipients))
logger("url_recipients ".print_r($url_recipients,true));
} }
logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG); logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
} else { } else {
@ -505,7 +500,7 @@ function notifier_run(&$argv, &$argc){
set_config('system','site_pubkey', $res['pubkey']); set_config('system','site_pubkey', $res['pubkey']);
} }
$rp = q("SELECT `resource-id` , `scale`, type FROM `photo` $rp = q("SELECT `resource-id` , `scale`, type FROM `photo`
WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid); WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
$photos = array(); $photos = array();
$ext = Photo::supportedTypes(); $ext = Photo::supportedTypes();
@ -533,19 +528,19 @@ function notifier_run(&$argv, &$argc){
} else { } else {
$slap = ostatus_salmon($target_item,$owner); $slap = ostatus_salmon($target_item,$owner);
//$slap = atom_entry($target_item,'html',null,$owner,false);
if($followup) { if($followup) {
logger("Section A1: ".$item_id);
foreach($items as $item) { // there is only one item foreach($items as $item) { // there is only one item
if(! $item['parent']) if(! $item['parent'])
continue; continue;
if($item['id'] == $item_id) { if($item['id'] == $item_id) {
logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA); logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
//$slap = atom_entry($item,'html',null,$owner,false);
$atom .= atom_entry($item,'text',null,$owner,false); $atom .= atom_entry($item,'text',null,$owner,false);
} }
} }
} else { } else {
logger("Section A2: ".$item_id);
foreach($items as $item) { foreach($items as $item) {
if(! $item['parent']) if(! $item['parent'])
@ -574,7 +569,6 @@ function notifier_run(&$argv, &$argc){
if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire))
$slaps[] = ostatus_salmon($item,$owner); $slaps[] = ostatus_salmon($item,$owner);
//$slaps[] = atom_entry($item,'html',null,$owner,true);
} }
} }
} }
@ -592,7 +586,7 @@ function notifier_run(&$argv, &$argc){
if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid'])) if((! strlen($target_item['allow_cid'])) && (! strlen($target_item['allow_gid']))
&& (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid'])) && (! strlen($target_item['deny_cid'])) && (! strlen($target_item['deny_gid']))
&& (intval($target_item['pubmail']))) { && (intval($target_item['pubmail']))) {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'", $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
intval($uid), intval($uid),
dbesc(NETWORK_MAIL) dbesc(NETWORK_MAIL)
); );
@ -604,14 +598,14 @@ function notifier_run(&$argv, &$argc){
} }
if($followup) if($followup)
$recip_str = $parent['contact-id']; $recip_str = implode(', ', $recipients_followup);
else else
$recip_str = implode(', ', $recipients); $recip_str = implode(', ', $recipients);
if ($relocate) if ($relocate)
$r = $recipients_relocate; $r = $recipients_relocate;
else else
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ", $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending`",
dbesc($recip_str) dbesc($recip_str)
); );
@ -699,6 +693,7 @@ function notifier_run(&$argv, &$argc){
$basepath = implode('/', array_slice(explode('/',$contact['url']),0,3)); $basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
if(link_compare($basepath,$a->get_baseurl())) { if(link_compare($basepath,$a->get_baseurl())) {
logger("Section B1: ".$item_id);
$nickname = basename($contact['url']); $nickname = basename($contact['url']);
if($contact['issued-id']) if($contact['issued-id'])
@ -750,6 +745,7 @@ function notifier_run(&$argv, &$argc){
break; break;
} }
} }
logger("Section B2: ".$item_id);
logger('notifier: dfrndelivery: ' . $contact['name']); logger('notifier: dfrndelivery: ' . $contact['name']);
$deliver_status = dfrn_deliver($owner,$contact,$atom); $deliver_status = dfrn_deliver($owner,$contact,$atom);
@ -772,6 +768,7 @@ function notifier_run(&$argv, &$argc){
break; break;
if($followup && $contact['notify']) { if($followup && $contact['notify']) {
logger("Section C1: ".$item_id);
logger('slapdelivery followup item '.$item_id.' to ' . $contact['name']); logger('slapdelivery followup item '.$item_id.' to ' . $contact['name']);
$deliver_status = slapper($owner,$contact['notify'],$slap); $deliver_status = slapper($owner,$contact['notify'],$slap);
@ -780,6 +777,7 @@ function notifier_run(&$argv, &$argc){
add_to_queue($contact['id'],NETWORK_OSTATUS,$slap); add_to_queue($contact['id'],NETWORK_OSTATUS,$slap);
} }
} else { } else {
logger("Section C2: ".$item_id);
// only send salmon if public - e.g. if it's ok to notify // only send salmon if public - e.g. if it's ok to notify
// a public hub, it's ok to send a salmon // a public hub, it's ok to send a salmon
@ -814,7 +812,7 @@ function notifier_run(&$argv, &$argc){
if($cmd === 'wall-new' || $cmd === 'comment-new') { if($cmd === 'wall-new' || $cmd === 'comment-new') {
$it = null; $it = null;
if($cmd === 'wall-new') if($cmd === 'wall-new')
$it = $items[0]; $it = $items[0];
else { else {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@ -894,6 +892,7 @@ function notifier_run(&$argv, &$argc){
break; break;
if($mail) { if($mail) {
logger("Section D1: ".$item_id);
diaspora_send_mail($item,$owner,$contact); diaspora_send_mail($item,$owner,$contact);
break; break;
} }
@ -905,10 +904,14 @@ function notifier_run(&$argv, &$argc){
// all other public posts processed as public batches further below // all other public posts processed as public batches further below
if($public_message) { if($public_message) {
if($followup) logger("Section D2: ".$item_id);
if($followup) {
logger("Section D3: ".$item_id);
diaspora_send_followup($target_item,$owner,$contact, true); diaspora_send_followup($target_item,$owner,$contact, true);
}
break; break;
} }
logger("Section D4: ".$item_id);
if(! $contact['pubkey']) if(! $contact['pubkey'])
break; break;
@ -923,22 +926,26 @@ function notifier_run(&$argv, &$argc){
} }
if(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) { if(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
logger("Section D5: ".$item_id);
// send both top-level retractions and relayable retractions for owner to relay // send both top-level retractions and relayable retractions for owner to relay
diaspora_send_retraction($target_item,$owner,$contact); diaspora_send_retraction($target_item,$owner,$contact);
break; break;
} }
elseif($followup) { elseif($followup) {
logger("Section D6: ".$item_id);
// send comments and likes to owner to relay // send comments and likes to owner to relay
diaspora_send_followup($target_item,$owner,$contact); diaspora_send_followup($target_item,$owner,$contact);
break; break;
} }
elseif($target_item['uri'] !== $target_item['parent-uri']) { elseif($target_item['uri'] !== $target_item['parent-uri']) {
logger("Section D7: ".$item_id);
// we are the relay - send comments, likes and relayable_retractions // we are the relay - send comments, likes and relayable_retractions
// (of comments and likes) to our conversants // (of comments and likes) to our conversants
diaspora_send_relay($target_item,$owner,$contact); diaspora_send_relay($target_item,$owner,$contact);
break; break;
} }
elseif(($top_level) && (! $walltowall)) { elseif(($top_level) && (! $walltowall)) {
logger("Section D8: ".$item_id);
// currently no workable solution for sending walltowall // currently no workable solution for sending walltowall
diaspora_send_status($target_item,$owner,$contact); diaspora_send_status($target_item,$owner,$contact);
break; break;
@ -946,13 +953,6 @@ function notifier_run(&$argv, &$argc){
break; break;
case NETWORK_FEED:
case NETWORK_FACEBOOK:
if(get_config('system','dfrn_only'))
break;
case NETWORK_PUMPIO:
if(get_config('system','dfrn_only'))
break;
default: default:
break; break;
} }

View file

@ -13,7 +13,6 @@ function handle_pubsubhubbub() {
$r = q("SELECT * FROM `push_subscriber` WHERE `push` > 0"); $r = q("SELECT * FROM `push_subscriber` WHERE `push` > 0");
foreach($r as $rr) { foreach($r as $rr) {
//$params = get_feed_for($a, '', $rr['nickname'], $rr['last_update'], 0, true);
$params = ostatus_feed($a, $rr['nickname'], $rr['last_update']); $params = ostatus_feed($a, $rr['nickname'], $rr['last_update']);
$hmac_sig = hash_hmac("sha1", $params, $rr['secret']); $hmac_sig = hash_hmac("sha1", $params, $rr['secret']);

View file

@ -78,23 +78,6 @@ function slapper($owner,$url,$slap) {
return; return;
} }
// add all namespaces to item
$namespaces = <<< EOT
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xmlns:at="http://purl.org/atompub/tombstones/1.0"
xmlns:media="http://purl.org/syndication/atommedia"
xmlns:dfrn="http://purl.org/macgirvin/dfrn/1.0"
xmlns:as="http://activitystrea.ms/spec/1.0/"
xmlns:georss="http://www.georss.org/georss"
xmlns:poco="http://portablecontacts.net/spec/1.0"
xmlns:ostatus="http://ostatus.org/schema/1.0"
xmlns:statusnet="http://status.net/schema/api/1/" > >
EOT;
$slap = str_replace('<entry>',$namespaces,$slap);
logger('slapper called for '.$url.'. Data: ' . $slap); logger('slapper called for '.$url.'. Data: ' . $slap);
// create a magic envelope // create a magic envelope