Merge pull request #1691 from annando/1506-ostatus-evenbetter

OStatus: Bugfix in threading, answers to OStatus messages in Friendica posts
This commit is contained in:
fabrixxm 2015-06-25 08:38:47 +02:00
commit 33f0d00ee1
3 changed files with 57 additions and 54 deletions

View File

@ -38,7 +38,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0,
// default permissions - anonymous user
$sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
$sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' ";
$r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
@ -118,9 +118,10 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0,
// Include answers to status.net posts in pubsub feeds
if($forpubsub) {
$sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` ";
$visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND `thread`.`network`='%s')",
dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS));
$sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
LEFT JOIN `item` AS `thritem` ON `thritem`.`uri`=`item`.`thr-parent` AND `thritem`.`uid`=`item`.`uid`";
$visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND ((`thread`.`network`='%s') OR (`thritem`.`network` = '%s')))",
dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS));
$date_field = "`received`";
$sql_order = "`item`.`received` DESC";
} else {

View File

@ -234,6 +234,11 @@ function notifier_run(&$argv, &$argc){
$parent = $items[0];
$thr_parent = q("SELECT `network` 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);
// This is IMPORTANT!!!!
// We will only send a "notify owner to relay" or followup message if the referenced post
@ -301,32 +306,12 @@ function notifier_run(&$argv, &$argc){
$target_item['deny_cid'].$target_item['deny_gid']) == 0))
$push_notify = true;
$thr_parent = q("SELECT `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
// If the thread parent is OStatus then do some magic to distribute the messages.
// We have not only to look at the parent, since it could be a Friendica thread.
// 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)) {
logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
$push_notify = true;
// Send a salmon notification to every person we mentioned in the post
$arr = explode(',',$target_item['tag']);
foreach($arr as $x) {
//logger('Checking tag '.$x, LOGGER_DEBUG);
$matches = null;
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
$probed_contact = probe_url($matches[1]);
if ($probed_contact["notify"] != "") {
logger('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]);
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
}
}
// 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 ($parent["network"] == NETWORK_OSTATUS) {
$r = q("SELECT `author-link` FROM `item` WHERE `parent` = %d AND `author-link` != '%s'",
intval($target_item["parent"]), dbesc($owner['url']));
@ -338,22 +323,7 @@ function notifier_run(&$argv, &$argc){
}
}
}
/*
// Check if the recipient isn't in your contact list, try to slap it
// Not sure if it is working or not.
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']);
if (count($r)) {
$thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"]));
if (count($thrparent) AND (normalise_link($r[0]["url"]) != normalise_link($thrparent[0]["author-link"]))) {
$probed_contact = probe_url($thrparent[0]["author-link"]);
if ($probed_contact["notify"] != "") {
logger('scrape data for slapper: '.print_r($probed_contact, true));
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
}
}
*/
if (count($url_recipients))
logger("url_recipients ".print_r($url_recipients,true));
}
@ -419,6 +389,25 @@ function notifier_run(&$argv, &$argc){
$conversant_str = dbesc(implode(', ',$conversants));
}
// If the thread parent is OStatus then do some magic to distribute the messages.
// 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)) {
// Send a salmon notification to every person we mentioned in the post
$arr = explode(',',$target_item['tag']);
foreach($arr as $x) {
//logger('Checking tag '.$x, LOGGER_DEBUG);
$matches = null;
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
$probed_contact = probe_url($matches[1]);
if ($probed_contact["notify"] != "") {
logger('Notify mentioned user '.$probed_contact["url"].': '.$probed_contact["notify"]);
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
}
}
}
$r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0");
if(count($r))
@ -530,13 +519,16 @@ function notifier_run(&$argv, &$argc){
$recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
unset($photos);
} else {
$slap = atom_entry($target_item,'html',null,$owner,false);
if($followup) {
foreach($items as $item) { // there is only one item
if(! $item['parent'])
continue;
if($item['id'] == $item_id) {
logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
$slap = atom_entry($item,'html',null,$owner,false);
//$slap = atom_entry($item,'html',null,$owner,false);
$atom .= atom_entry($item,'text',null,$owner,false);
}
}
@ -946,7 +938,8 @@ function notifier_run(&$argv, &$argc){
// send additional slaps to mentioned remote tags (@foo@example.com)
if($slap && count($url_recipients) && ($followup || $top_level) && ($public_message || $push_notify) && (! $expire)) {
//if($slap && count($url_recipients) && ($followup || $top_level) && ($public_message || $push_notify) && (! $expire)) {
if($slap && count($url_recipients) && ($public_message || $push_notify) && (!$expire)) {
if(! get_config('system','dfrn_only')) {
foreach($url_recipients as $url) {
if($url) {

View File

@ -516,6 +516,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// If the thread shouldn't be completed then store the item and go away
if ((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) {
//$arr["app"] .= " (OStatus-NoCompletion)";
$item_stored = item_store($item, true);
return($item_stored);
}
@ -584,6 +585,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
if (!sizeof($items)) {
if (count($item) > 0) {
//$arr["app"] .= " (OStatus-NoConvFetched)";
$item_stored = item_store($item, true);
if ($item_stored) {
@ -654,17 +656,23 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
}
}
if (isset($single_conv->context->inReplyTo->id)) {
$parent_uri = $single_conv->context->inReplyTo->id;
$parent_uri = $parent["uri"];
// "context" only seems to exist on older servers
if (isset($single_conv->context->inReplyTo->id)) {
$parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1",
intval($uid), dbesc($parent_uri), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN));
if (!$parent_exists) {
logger("Parent ".$parent_uri." wasn't found here", LOGGER_DEBUG);
$parent_uri = $parent["uri"];
intval($uid), dbesc($single_conv->context->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN));
if ($parent_exists)
$parent_uri = $single_conv->context->inReplyTo->id;
}
// This is the current way
if (isset($single_conv->object->inReplyTo->id)) {
$parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1",
intval($uid), dbesc($single_conv->object->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN));
if ($parent_exists)
$parent_uri = $single_conv->object->inReplyTo->id;
}
} else
$parent_uri = $parent["uri"];
$message_exists = q("SELECT `id`, `parent`, `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1",
intval($uid), dbesc($single_conv->id),
@ -765,7 +773,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
else
$arr["app"] = "OStatus";
$arr["app"] .= " (Conversation)";
//$arr["app"] .= " (Conversation)";
$arr["object"] = json_encode($single_conv);
$arr["verb"] = $parent["verb"];
@ -831,7 +839,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
if (isset($item[$field]))
$arr[$field] = $item[$field];
$arr["app"] .= " (OStatus)";
//$arr["app"] .= " (OStatus)";
}
$newitem = item_store($arr);
@ -862,6 +870,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
}
if (($item_stored < 0) AND (count($item) > 0)) {
//$arr["app"] .= " (OStatus-NoConvFound)";
$item_stored = item_store($item, true);
if ($item_stored) {
logger("Uri ".$item["uri"]." wasn't found in conversation ".$conversation_url, LOGGER_DEBUG);