OStatus: Send even Friendica comments to OStatus

This commit is contained in:
Michael Vogel 2015-12-07 21:52:42 +01:00
parent d944b65253
commit bfc0857953
3 changed files with 124 additions and 49 deletions

View file

@ -303,7 +303,8 @@ function notifier_run(&$argv, &$argc){
$conversant_str = dbesc($parent['contact-id']); $conversant_str = dbesc($parent['contact-id']);
$recipients = array($parent['contact-id']); $recipients = 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
(strlen($target_item['allow_cid'].$target_item['allow_gid']. (strlen($target_item['allow_cid'].$target_item['allow_gid'].
$target_item['deny_cid'].$target_item['deny_gid']) == 0)) $target_item['deny_cid'].$target_item['deny_gid']) == 0))
$push_notify = true; $push_notify = true;
@ -329,6 +330,7 @@ function notifier_run(&$argv, &$argc){
if (count($url_recipients)) if (count($url_recipients))
logger("url_recipients ".print_r($url_recipients,true)); logger("url_recipients ".print_r($url_recipients,true));
} }
logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
} else { } else {
$followup = false; $followup = false;

View file

@ -9,6 +9,7 @@ require_once("include/socgraph.php");
require_once("include/Photo.php"); require_once("include/Photo.php");
require_once("include/Scrape.php"); require_once("include/Scrape.php");
require_once("include/follow.php"); require_once("include/follow.php");
require_once("include/api.php");
require_once("mod/proxy.php"); require_once("mod/proxy.php");
define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
@ -1318,10 +1319,13 @@ class="attachment thumbnail" id="attachment-572819" rel="nofollow external">http
*/ */
function ostatus_entry($doc, $item, $owner, $toplevel = false) { function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) {
$a = get_app(); $a = get_app();
if (!$toplevel) { if (!$toplevel AND $repeat) {
$entry = $doc->createElement("activity:object");
$title = sprintf("New note by %s", $owner["nick"]);
} elseif (!$toplevel) {
$entry = $doc->createElement("entry"); $entry = $doc->createElement("entry");
$title = sprintf("New note by %s", $owner["nick"]); $title = sprintf("New note by %s", $owner["nick"]);
} else { } else {
@ -1359,7 +1363,11 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
// But: it seems as if it doesn't federate well between the GS servers // But: it seems as if it doesn't federate well between the GS servers
// So we just set it to "note" to be sure that it reaches their target systems // So we just set it to "note" to be sure that it reaches their target systems
if (!$repeat)
xml_add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); xml_add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
else
xml_add_element($doc, $entry, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA.'activity');
xml_add_element($doc, $entry, "id", $item["uri"]); xml_add_element($doc, $entry, "id", $item["uri"]);
xml_add_element($doc, $entry, "title", $title); xml_add_element($doc, $entry, "title", $title);
@ -1382,12 +1390,54 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
"href" => $a->get_baseurl()."/display/".$item["guid"])); "href" => $a->get_baseurl()."/display/".$item["guid"]));
xml_add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"])); xml_add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
$repeated_item = $item;
$is_repeat = false;
if (!$repeat)
$is_repeat = api_share_as_retweet($repeated_item);
if (!$is_repeat)
xml_add_element($doc, $entry, "activity:verb", construct_verb($item)); xml_add_element($doc, $entry, "activity:verb", construct_verb($item));
else
xml_add_element($doc, $entry, "activity:verb", ACTIVITY_SHARE);
xml_add_element($doc, $entry, "published", datetime_convert("UTC","UTC",$item["created"]."+00:00",ATOM_TIME)); xml_add_element($doc, $entry, "published", datetime_convert("UTC","UTC",$item["created"]."+00:00",ATOM_TIME));
xml_add_element($doc, $entry, "updated", datetime_convert("UTC","UTC",$item["edited"]."+00:00",ATOM_TIME)); xml_add_element($doc, $entry, "updated", datetime_convert("UTC","UTC",$item["edited"]."+00:00",ATOM_TIME));
if ($is_repeat) {
$repeated_owner = array();
$repeated_owner["name"] = $repeated_item["author-name"];
$repeated_owner["url"] = $repeated_item["author-link"];
$repeated_owner["photo"] = normalise_link($repeated_item["author-avatar"]);
$repeated_owner["nick"] = "";
$repeated_owner["location"] = "";
$repeated_owner["about"] = "";
$repeated_owner["uid"] = 0;
$r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"]));
if ($r) {
$repeated_owner["nick"] = $r[0]["nick"];
$repeated_owner["location"] = $r[0]["location"];
$repeated_owner["about"] = $r[0]["about"];
}
$entry_repeat = ostatus_entry($doc, $repeated_item, $repeated_owner, false, true);
$entry->appendChild($entry_repeat);
} elseif ($repeat) {
$profile = array();
$profile["name"] = $owner["name"];
$profile["photo"] = $owner["photo"];
$profile["thumb"] = $owner["photo"];
$profile["about"] = $owner["about"];
$author = ostatus_add_author($doc, $owner, $profile);
$entry->appendChild($author);
}
$mentioned = array();
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array( $attributes = array(
@ -1400,6 +1450,9 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
"rel" => "related", "rel" => "related",
"href" => $a->get_baseurl()."/display/".$parent[0]["guid"]); "href" => $a->get_baseurl()."/display/".$parent[0]["guid"]);
xml_add_element($doc, $entry, "link", "", $attributes); xml_add_element($doc, $entry, "link", "", $attributes);
$mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
$mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
} }
xml_add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", xml_add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation",
@ -1411,9 +1464,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
if(count($tags)) if(count($tags))
foreach($tags as $t) foreach($tags as $t)
if ($t[0] == "@") if ($t[0] == "@")
$mentioned[$t[1]] = $t[1];
foreach ($mentioned AS $mention)
xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned", xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => ACTIVITY_OBJ_PERSON, "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
"href" => $t[1])); "href" => $mention));
if (!$item["private"]) if (!$item["private"])
xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned", xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
@ -1441,7 +1497,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) {
if ($app == "") if ($app == "")
$app = "web"; $app = "web";
xml_add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item["id"], "source" => $app));
$attributes = array("local_id" => $item["id"], "source" => $app);
if ($is_repeat)
$attributes["repeat_of"] = $item["id"];
xml_add_element($doc, $entry, "statusnet:notice_info", "", $attributes);
return $entry; return $entry;
} }
@ -1468,12 +1529,17 @@ function ostatus_feed(&$a, $owner_nick, $last_update) {
WHERE `item`.`uid` = %d AND `item`.`received` > '%s' AND NOT `item`.`private` AND NOT `item`.`deleted` WHERE `item`.`uid` = %d AND `item`.`received` > '%s' AND NOT `item`.`private` AND NOT `item`.`deleted`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND ((`item`.`wall` AND (`item`.`parent` = `item`.`id`)) AND ((`item`.`wall` AND (`item`.`parent` = `item`.`id`))
OR (`item`.`network` = '%s' AND ((`thread`.`network`='%s') OR (`thritem`.`network` = '%s'))) AND `thread`.`mention`) OR (`item`.`network` = '%s' AND ((`thread`.`network` IN ('%s', '%s')) OR (`thritem`.`network` IN ('%s', '%s')))) AND `thread`.`mention`)
AND (`item`.`owner-link` IN ('%s', '%s')) AND ((`item`.`owner-link` IN ('%s', '%s') AND (`item`.`parent` = `item`.`id`))
OR (`item`.`author-link` IN ('%s', '%s')))
ORDER BY `item`.`received` DESC ORDER BY `item`.`received` DESC
LIMIT 0, 300", LIMIT 0, 300",
intval($owner["uid"]), dbesc($check_date), intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN),
dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS), //dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
//dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN),
dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"])),
dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"])) dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"]))
); );

View file

@ -16,6 +16,7 @@ function ref_session_read ($id) {
global $session_exists; global $session_exists;
if(x($id)) if(x($id))
$r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id)); $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
if(count($r)) { if(count($r)) {
$session_exists = true; $session_exists = true;
return $r[0]['data']; return $r[0]['data'];
@ -28,6 +29,7 @@ function ref_session_read ($id) {
if(! function_exists('ref_session_write')) { if(! function_exists('ref_session_write')) {
function ref_session_write ($id,$data) { function ref_session_write ($id,$data) {
global $session_exists, $session_expire; global $session_exists, $session_expire;
if(! $id || ! $data) { if(! $id || ! $data) {
return false; return false;
} }
@ -35,12 +37,17 @@ function ref_session_write ($id,$data) {
$expire = time() + $session_expire; $expire = time() + $session_expire;
$default_expire = time() + 300; $default_expire = time() + 300;
if($session_exists) if($session_exists) {
$r = q("UPDATE `session` $r = q("UPDATE `session`
SET `data` = '%s', `expire` = '%s' SET `data` = '%s'
WHERE `sid` = '%s'", WHERE `data` != '%s' AND `sid` = '%s'",
dbesc($data), dbesc($expire), dbesc($id)); dbesc($data), dbesc($data), dbesc($id));
else
$r = q("UPDATE `session`
SET `expire` = '%s'
WHERE `expire` != '%s' AND `sid` = '%s'",
dbesc($expire), dbesc($expire), dbesc($id));
} else
$r = q("INSERT INTO `session` $r = q("INSERT INTO `session`
SET `sid` = '%s', `expire` = '%s', `data` = '%s'", SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
dbesc($id), dbesc($default_expire), dbesc($data)); dbesc($id), dbesc($default_expire), dbesc($data));