OStatus: Replies now arrive their target.

This commit is contained in:
Michael Vogel 2015-01-12 00:14:51 +01:00
parent f6ee51bcd7
commit beaca70126
5 changed files with 114 additions and 82 deletions

View File

@ -2074,7 +2074,7 @@ if(! function_exists('load_contact_links')) {
if(! $uid || x($a->contacts,'empty')) if(! $uid || x($a->contacts,'empty'))
return; return;
$r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ", $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `thumb` != ''",
intval($uid) intval($uid)
); );
if(count($r)) { if(count($r)) {

View File

@ -697,7 +697,7 @@ function bb_RemovePictureLinks($match) {
} }
function bb_expand_links($match) { function bb_expand_links($match) {
if (stristr($match[2], $match[3]) OR ($match[2] == $match[3])) if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3]))
return ($match[1]."[url]".$match[2]."[/url]"); return ($match[1]."[url]".$match[2]."[/url]");
else else
return ($match[1].$match[3]." [url]".$match[2]."[/url]"); return ($match[1].$match[3]." [url]".$match[2]."[/url]");

View File

@ -90,7 +90,7 @@ function notifier_run(&$argv, &$argc){
$expire = false; $expire = false;
$mail = false; $mail = false;
$fsuggest = false; $fsuggest = false;
$relocate = false; $relocate = false;
$top_level = false; $top_level = false;
$recipients = array(); $recipients = array();
$url_recipients = array(); $url_recipients = array();
@ -110,11 +110,10 @@ function notifier_run(&$argv, &$argc){
$recipients[] = $message[0]['contact-id']; $recipients[] = $message[0]['contact-id'];
$item = $message[0]; $item = $message[0];
} } elseif($cmd === 'expire') {
elseif($cmd === 'expire') {
$normal_mode = false; $normal_mode = false;
$expire = true; $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 10 MINUTE", AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE",
intval($item_id) intval($item_id)
); );
@ -122,8 +121,7 @@ function notifier_run(&$argv, &$argc){
$item_id = 0; $item_id = 0;
if(! count($items)) if(! count($items))
return; return;
} } elseif($cmd === 'suggest') {
elseif($cmd === 'suggest') {
$normal_mode = false; $normal_mode = false;
$fsuggest = true; $fsuggest = true;
@ -135,8 +133,7 @@ function notifier_run(&$argv, &$argc){
$uid = $suggest[0]['uid']; $uid = $suggest[0]['uid'];
$recipients[] = $suggest[0]['cid']; $recipients[] = $suggest[0]['cid'];
$item = $suggest[0]; $item = $suggest[0];
} } elseif($cmd === 'removeme') {
elseif($cmd === 'removeme') {
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id)); $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
if (! $r) if (! $r)
return; return;
@ -156,13 +153,11 @@ function notifier_run(&$argv, &$argc){
terminate_friendship($user, $self, $contact); terminate_friendship($user, $self, $contact);
} }
return; return;
} } elseif($cmd === 'relocate') {
elseif($cmd === 'relocate') { $normal_mode = false;
$normal_mode = false;
$relocate = true; $relocate = true;
$uid = $item_id; $uid = $item_id;
} } else {
else {
// find ancestors // find ancestors
$r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1", $r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
intval($item_id) intval($item_id)
@ -181,7 +176,7 @@ function notifier_run(&$argv, &$argc){
if(! $parent_id) if(! $parent_id)
return; return;
$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", 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) intval($parent_id)
); );
@ -204,10 +199,10 @@ function notifier_run(&$argv, &$argc){
} }
$r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`,
`user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`,
`user`.`page-flags`, `user`.`prvnets` `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", WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
intval($uid) intval($uid)
); );
@ -306,9 +301,9 @@ function notifier_run(&$argv, &$argc){
return; return;
} }
if((strlen($parent['allow_cid'])) if((strlen($parent['allow_cid']))
|| (strlen($parent['allow_gid'])) || (strlen($parent['allow_gid']))
|| (strlen($parent['deny_cid'])) || (strlen($parent['deny_cid']))
|| (strlen($parent['deny_gid']))) { || (strlen($parent['deny_gid']))) {
$public_message = false; // private recipients, not public $public_message = false; // private recipients, not public
} }
@ -410,8 +405,7 @@ function notifier_run(&$argv, &$argc){
'$content' => xmlify($body), '$content' => xmlify($body),
'$parent_id' => xmlify($item['parent-uri']) '$parent_id' => xmlify($item['parent-uri'])
)); ));
} } elseif($fsuggest) {
elseif($fsuggest) {
$public_message = false; // suggestions are not public $public_message = false; // suggestions are not public
$sugg_template = get_markup_template('atom_suggest.tpl'); $sugg_template = get_markup_template('atom_suggest.tpl');
@ -430,9 +424,8 @@ function notifier_run(&$argv, &$argc){
intval($item['id']) intval($item['id'])
); );
} } elseif($relocate) {
elseif($relocate) { $public_message = false; // suggestions are not public
$public_message = false; // suggestions are not public
$sugg_template = get_markup_template('atom_relocate.tpl'); $sugg_template = get_markup_template('atom_relocate.tpl');
@ -444,8 +437,8 @@ 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();
foreach($rp as $p){ foreach($rp as $p){
@ -453,24 +446,23 @@ function notifier_run(&$argv, &$argc){
} }
unset($rp, $ext); unset($rp, $ext);
$atom .= replace_macros($sugg_template, array( $atom .= replace_macros($sugg_template, array(
'$name' => xmlify($owner['name']), '$name' => xmlify($owner['name']),
'$photo' => xmlify($photos[4]), '$photo' => xmlify($photos[4]),
'$thumb' => xmlify($photos[5]), '$thumb' => xmlify($photos[5]),
'$micro' => xmlify($photos[6]), '$micro' => xmlify($photos[6]),
'$url' => xmlify($owner['url']), '$url' => xmlify($owner['url']),
'$request' => xmlify($owner['request']), '$request' => xmlify($owner['request']),
'$confirm' => xmlify($owner['confirm']), '$confirm' => xmlify($owner['confirm']),
'$notify' => xmlify($owner['notify']), '$notify' => xmlify($owner['notify']),
'$poll' => xmlify($owner['poll']), '$poll' => xmlify($owner['poll']),
'$sitepubkey' => xmlify(get_config('system','site_pubkey')), '$sitepubkey' => xmlify(get_config('system','site_pubkey')),
//'$pubkey' => xmlify($owner['pubkey']), //'$pubkey' => xmlify($owner['pubkey']),
//'$prvkey' => xmlify($owner['prvkey']), //'$prvkey' => xmlify($owner['prvkey']),
)); ));
$recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN); $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
unset($photos); unset($photos);
} } else {
else {
if($followup) { if($followup) {
foreach($items as $item) { // there is only one item foreach($items as $item) { // there is only one item
if(! $item['parent']) if(! $item['parent'])
@ -481,8 +473,7 @@ function notifier_run(&$argv, &$argc){
$atom .= atom_entry($item,'text',null,$owner,false); $atom .= atom_entry($item,'text',null,$owner,false);
} }
} }
} } else {
else {
foreach($items as $item) { foreach($items as $item) {
if(! $item['parent']) if(! $item['parent'])
@ -510,7 +501,7 @@ function notifier_run(&$argv, &$argc){
else else
$atom .= atom_entry($item,'text',null,$owner,true); $atom .= atom_entry($item,'text',null,$owner,true);
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[] = atom_entry($item,'html',null,$owner,true); $slaps[] = atom_entry($item,'html',null,$owner,true);
} }
} }
@ -545,12 +536,12 @@ function notifier_run(&$argv, &$argc){
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 `blocked` = 0 AND `pending` = 0 ",
dbesc($recip_str) dbesc($recip_str)
); );
require_once('include/salmon.php'); require_once('include/salmon.php');
@ -700,13 +691,33 @@ function notifier_run(&$argv, &$argc){
if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only')) if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
break; break;
if($followup && $contact['notify']) { $ostatus_contact = $contact;
logger('notifier: slapdelivery: ' . $contact['name']);
$deliver_status = slapper($owner,$contact['notify'],$slap); // If the contact doesn't fit with the contact, then fetch the correct contact
// This is more a test than a good solution. The whole OStatus stuff needs a rework.
if ($followup) {
$thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"]));
if (count($thrparent) AND (normalise_link($contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
require_once("include/Scrape.php");
$probed_contact = probe_url($thrparent[0]["author-link"]);
if ($probed_contact["network"] != NETWORK_FEED) {
$ostatus_contact = $probed_contact;
$ostatus_contact["nurl"] = normalise_link($probed_contact["url"]);
$ostatus_contact["thumb"] = $probed_contact["photo"];
$ostatus_contact["micro"] = $probed_contact["photo"];
}
logger('scrape data for slapper: '.print_r($ostatus_contact, true));
}
}
if($followup && $ostatus_contact['notify']) {
logger('notifier: slapdelivery: ' . $ostatus_contact['name']);
$deliver_status = slapper($owner,$ostatus_contact['notify'],$slap);
if($deliver_status == (-1)) { if($deliver_status == (-1)) {
// queue message for redelivery // queue message for redelivery
add_to_queue($contact['id'],NETWORK_OSTATUS,$slap); add_to_queue($ostatus_contact['id'],NETWORK_OSTATUS,$slap);
} }
} else { } else {

View File

@ -20,12 +20,12 @@ function check_conversations() {
if($last) { if($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);
if($next > time()) { if($next > time()) {
logger('complete_conversation: poll interval not reached'); logger('poll interval not reached');
return; return;
} }
} }
logger('complete_conversation: cron_start'); logger('cron_start');
$start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60)); $start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60));
$conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'",
@ -36,7 +36,7 @@ function check_conversations() {
complete_conversation($id, $url); complete_conversation($id, $url);
} }
logger('complete_conversation: cron_end'); logger(' cron_end');
set_config('system','ostatus_last_poll', time()); set_config('system','ostatus_last_poll', time());
} }
@ -52,8 +52,6 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
$a->last_ostatus_conversation_url = $conversation_url; $a->last_ostatus_conversation_url = $conversation_url;
//logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid);
$messages = q("SELECT `uid`, `parent`, `created` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); $messages = q("SELECT `uid`, `parent`, `created` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
if (!$messages) if (!$messages)
return; return;
@ -90,8 +88,6 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
do { do {
$conv_as = fetch_url($conv."?page=".$pageno); $conv_as = fetch_url($conv."?page=".$pageno);
//$conv_as = fetch_url($conv."?page=".$pageno, false, 0, 10);
//$conv_as = file_get_contents($conv."?page=".$pageno);
$conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as);
$conv_as = json_decode($conv_as); $conv_as = json_decode($conv_as);
@ -110,7 +106,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
$items = array_reverse($items); $items = array_reverse($items);
foreach ($items as $single_conv) { foreach ($items as $single_conv) {
// identi.ca just changed the format of the activity streams. This is a quick fix. // status.net changed the format of the activity streams. This is a quick fix.
if (@is_string($single_conv->object->id)) if (@is_string($single_conv->object->id))
$single_conv->id = $single_conv->object->id; $single_conv->id = $single_conv->object->id;
@ -127,7 +123,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
intval($message["uid"]), dbesc($first_id)); intval($message["uid"]), dbesc($first_id));
if ($new_parents) { if ($new_parents) {
$parent = $new_parents[0]; $parent = $new_parents[0];
logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid); logger('adopting new parent '.$parent["id"].' for '.$itemid);
} else { } else {
$parent["id"] = 0; $parent["id"] = 0;
$parent["uri"] = $first_id; $parent["uri"] = $first_id;
@ -144,6 +140,8 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
if ($message_exists) { if ($message_exists) {
if ($parent["id"] != 0) { if ($parent["id"] != 0) {
$existing_message = $message_exists[0]; $existing_message = $message_exists[0];
// This is partly bad, since the entry in the thread table isn't updated
$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d", $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d",
intval($parent["id"]), intval($parent["id"]),
dbesc($parent["uri"]), dbesc($parent["uri"]),
@ -153,12 +151,23 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
continue; continue;
} }
$contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
$message["uid"], normalise_link($single_conv->actor->id), NETWORK_STATUSNET);
if (count($contact)) {
logger("Found contact for url ".$single_conv->actor->id, LOGGER_DEBUG);
$contact_id = $contact[0]["id"];
} else {
logger("No contact found for url ".$single_conv->actor->id, LOGGER_DEBUG);
$contact_id = $parent["contact-id"];
}
$arr = array(); $arr = array();
$arr["network"] = NETWORK_OSTATUS; $arr["network"] = NETWORK_OSTATUS;
$arr["uri"] = $single_conv->id; $arr["uri"] = $single_conv->id;
$arr["plink"] = $single_conv->id; $arr["plink"] = $single_conv->id;
$arr["uid"] = $message["uid"]; $arr["uid"] = $message["uid"];
$arr["contact-id"] = $parent["contact-id"]; // To-Do $arr["contact-id"] = $contact_id;
if ($parent["id"] != 0) if ($parent["id"] != 0)
$arr["parent"] = $parent["id"]; $arr["parent"] = $parent["id"];
$arr["parent-uri"] = $parent["uri"]; $arr["parent-uri"] = $parent["uri"];
@ -201,20 +210,13 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
// If the newly created item is the top item then change the parent settings of the thread // If the newly created item is the top item then change the parent settings of the thread
if ($newitem AND ($arr["uri"] == $first_id)) { if ($newitem AND ($arr["uri"] == $first_id)) {
logger('complete_conversation: setting new parent to id '.$newitem); logger('setting new parent to id '.$newitem);
$new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
intval($message["uid"]), intval($newitem)); intval($message["uid"]), intval($newitem));
if ($new_parents) { if ($new_parents) {
$parent = $new_parents[0]; $parent = $new_parents[0];
logger('complete_conversation: done changing parents to parent '.$newitem); logger('done changing parents to parent '.$newitem);
} }
/*logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]);
$r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d",
intval($newitem),
dbesc($arr["uri"]),
intval($parent["id"]));
logger('complete_conversation: done changing parents to parent '.$newitem.' '.print_r($r, true));*/
} }
} }
} }

View File

@ -90,14 +90,14 @@ function item_post(&$a) {
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
intval($parent) intval($parent)
); );
} } elseif($parent_uri && local_user()) {
elseif($parent_uri && local_user()) {
// This is coming from an API source, and we are logged in // This is coming from an API source, and we are logged in
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($parent_uri), dbesc($parent_uri),
intval(local_user()) intval(local_user())
); );
} }
// if this isn't the real parent of the conversation, find it // if this isn't the real parent of the conversation, find it
if($r !== false && count($r)) { if($r !== false && count($r)) {
$parid = $r[0]['parent']; $parid = $r[0]['parent'];
@ -127,8 +127,27 @@ function item_post(&$a) {
intval($parent_item['contact-id']), intval($parent_item['contact-id']),
intval($uid) intval($uid)
); );
if(count($r)) if(count($r)) {
$parent_contact = $r[0]; $parent_contact = $r[0];
// If the contact id doesn't fit with the contact, then set the contact to null
$thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
$parent_contact = null;
require_once("include/Scrape.php");
$probed_contact = probe_url($thrparent[0]["author-link"]);
if ($probed_contact["network"] != NETWORK_FEED) {
$parent_contact = $probed_contact;
$parent_contact["nurl"] = normalise_link($probed_contact["url"]);
$parent_contact["thumb"] = $probed_contact["photo"];
$parent_contact["micro"] = $probed_contact["photo"];
}
logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG);
} else
logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG);
}
} }
} }