From 87ade53162d20dfbea018e061ae9896014409bdc Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 24 Jun 2015 14:21:42 +0200 Subject: [PATCH 1/6] Some test code added --- include/notifier.php | 33 +++++++++++++++++---------------- include/ostatus.php | 3 +++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index 19f0134729..312d45d062 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -304,10 +304,11 @@ function notifier_run(&$argv, &$argc){ $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); + // 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)) { - logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG); $push_notify = true; @@ -338,22 +339,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 +405,21 @@ function notifier_run(&$argv, &$argc){ $conversant_str = dbesc(implode(', ',$conversants)); } + // Test! + // 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)) diff --git a/include/ostatus.php b/include/ostatus.php index 463ebcd30a..fccd178fe8 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -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) { @@ -862,6 +864,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); From 5bf7a3b7a507cdd17596d351e7ceefb99a98950b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 24 Jun 2015 22:31:38 +0200 Subject: [PATCH 2/6] Fixed inReplyTo in conversations --- include/ostatus.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index fccd178fe8..4509293423 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -656,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"]; - } - } else - $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; + } $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), From db256217e668a6dc2a8b9c7b662347848e577a3a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 24 Jun 2015 22:51:46 +0200 Subject: [PATCH 3/6] Removed test --- include/notifier.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index 312d45d062..f5a898e89e 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -405,21 +405,6 @@ function notifier_run(&$argv, &$argc){ $conversant_str = dbesc(implode(', ',$conversants)); } - // Test! - // 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)) From 7581bd0f3618ebd0d8fffda6c320202bbe523b77 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 25 Jun 2015 00:47:59 +0200 Subject: [PATCH 4/6] Send a salmon notice whenever an OStatus user is mentioned. --- include/notifier.php | 57 +++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/include/notifier.php b/include/notifier.php index f5a898e89e..24dc63d696 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -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,33 +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"])); - - logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG); - - // 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)) { $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'])); @@ -405,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)) @@ -516,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); } } @@ -932,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) { From 7f052b654f9e5366c5cfc7eb897cf6e62de1a321 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 25 Jun 2015 07:18:02 +0200 Subject: [PATCH 5/6] PuSH now supports answers to OStatus messages inside of Friendica threads as well. --- include/items.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/items.php b/include/items.php index 7a30130bbc..2ff7bffbe3 100644 --- a/include/items.php +++ b/include/items.php @@ -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 { From 704110456a97f6b9616fe83d2dd29afc9326ffe1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 25 Jun 2015 07:30:14 +0200 Subject: [PATCH 6/6] Removed test code --- include/ostatus.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 4509293423..c985f5d0f4 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -516,7 +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)"; + //$arr["app"] .= " (OStatus-NoCompletion)"; $item_stored = item_store($item, true); return($item_stored); } @@ -585,7 +585,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) { if (!sizeof($items)) { if (count($item) > 0) { - $arr["app"] .= " (OStatus-NoConvFetched)"; + //$arr["app"] .= " (OStatus-NoConvFetched)"; $item_stored = item_store($item, true); if ($item_stored) { @@ -773,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"]; @@ -839,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); @@ -870,7 +870,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) { } if (($item_stored < 0) AND (count($item) > 0)) { - $arr["app"] .= " (OStatus-NoConvFound)"; + //$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);