$target_item['deny_cid'].$target_item['deny_gid']) == 0))
$push_notify = true;
- if ($parent['network'] == NETWORK_OSTATUS) {
- logger('Parent is OStatus', LOGGER_DEBUG);
+ $thr_parent = q("SELECT `network` FROM `item` WHERE `uri` = '%s' AMD `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.
+ if (($thr_parent AND ($thr_parent['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
+ logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent['network'], LOGGER_DEBUG);
$push_notify = true;
// Send a salmon notification to every person we mentioned in the post
- // To-Do: Send a Salmon to every Friendica user in that thread
$arr = explode(',',$target_item['tag']);
foreach($arr as $x) {
- logger('Checking tag '.$x, LOGGER_DEBUG);
+ //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('scrape data for slapper: '.print_r($probed_contact, true));
+ 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", intval($target_item["parent"]));
+ foreach($r as $parent_item) {
+ $probed_contact = probe_url($parent_item["author-link"]);
+ if (($probed_contact["notify"] != "") AND ($probed_contact["network"] == NETWORK_DFRN)) {
+ logger('Notify Friendica user '.$probed_contact["url"].': '.$probed_contact["notify"]);
+ $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
+ }
+ }
+ }
/*
// Check if the recipient isn't in your contact list, try to slap it
// Not sure if it is working or not.
function ostatus_import($xml,$importer,&$contact, &$hub) {
- // To-Do:
- // Hub
-
$a = get_app();
logger("Import OStatus message", LOGGER_DEBUG);
$orig_contact = $contact;
$orig_author = ostatus_fetchauthor($xpath, $activityobjects, $importer, $orig_contact);
- $prefix = share_header($orig_author['author-name'], $orig_author['author-link'], $orig_author['author-avatar'], "", $orig_created, $orig_uri);
- $item["body"] = $prefix.html2bbcode($orig_body)."[/share]";
+ if (!intval(get_config('system','wall-to-wall_share'))) {
+ $prefix = share_header($orig_author['author-name'], $orig_author['author-link'], $orig_author['author-avatar'], "", $orig_created, $orig_uri);
+ $item["body"] = $prefix.add_page_info_to_body(html2bbcode($orig_body))."[/share]";
+ } else {
+ $author["author-name"] = $orig_author["author-name"];
+ $author["author-link"] = $orig_author["author-link"];
+ $author["author-avatar"] = $orig_author["author-avatar"];
+ $item["body"] = add_page_info_to_body(html2bbcode($orig_body));
+ $item["uri"] = $orig_uri;
+ $item["created"] = $orig_created;
+ }
$item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue;
$item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue;
<?php
require_once("include/Contact.php");
+require_once("include/threads.php");
define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes
$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `created`, `received`, `guid`) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')",
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION),
dbesc($message["created"]), dbesc($conversation_url), dbesc($message["created"]), dbesc($message["received"]), dbesc($message["guid"]));
- logger('complete_conversation: Storing conversation url '.$conversation_url.' for id '.$itemid);
+ logger('Storing conversation url '.$conversation_url.' for id '.$itemid);
}
if ($only_add_conversation)
$pageno = 1;
$items = array();
- logger('complete_conversation: fetching conversation url '.$conv.' for '.$itemid);
+ logger('fetching conversation url '.$conv.' for id '.$itemid.' and parent '.$parent["id"]);
do {
$conv_as = fetch_url($conv."?page=".$pageno);
if ($first_id == "") {
$first_id = $single_conv->id;
- // To-Do:
- // Only fetch a new parent if the new one doesn't have parents
- // It can happen that OStatus servers have incomplete threads.
- $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1",
+ $new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1",
intval($message["uid"]), dbesc($first_id),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN));
if ($new_parents) {
- $parent = $new_parents[0];
- if ($parent["id"] != $message["parent"])
- logger('Fetch new parent id '.$parent["id"].' for '.$itemid.' Old parent: '.$message["parent"]);
+ // It can happen that OStatus servers have incomplete threads.
+ // Then keep the current parent
+ if ($parent["id"] == $parent["parent"]) {
+ $parent = $new_parents[0];
+
+ if ($parent["id"] != $message["parent"])
+ logger('Fetch new parent id '.$parent["id"].' - Old parent: '.$message["parent"]);
+ } else {
+ $first_id = $parent["uri"];
+ //logger('Keep parent for '.$itemid.' - Old parent: '.$message["parent"]);
+ }
} else {
$parent["id"] = 0;
$parent["uri"] = $first_id;
if ($parent["id"] != 0) {
$existing_message = $message_exists[0];
- // Normally this shouldn't happen anymore, since we improved the way we fetch OStatus messages
+ // We improved the way we fetch OStatus messages, this shouldn't happen very often now
if ($existing_message["parent"] != $parent["id"]) {
- logger('updating id '.$existing_message["id"].' to parent '.$parent["id"].' uri '.$parent["uri"].' thread '.$parent_uri, LOGGER_DEBUG);
-
- // 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",
- intval($parent["id"]),
- dbesc($parent["uri"]),
- dbesc($parent_uri),
- intval($existing_message["id"]));
+ logger('updating id '.$existing_message["id"].' with parent '.$existing_message["parent"].' to parent '.$parent["id"].' uri '.$parent["uri"].' thread '.$parent_uri, LOGGER_DEBUG);
+
+ // Update the parent id of the selected item
+ $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `id` = %d",
+ intval($parent["id"]), dbesc($parent["uri"]), intval($existing_message["id"]));
+
+ // Update the parent uri in the thread - but only if it points to itself
+ $r = q("UPDATE `item` SET `thr-parent` = '%s' WHERE `id` = %d AND `uri` = `thr-parent`",
+ dbesc($parent_uri), intval($existing_message["id"]));
+
+ // try to change all items of the same parent
+ $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d",
+ intval($parent["id"]), dbesc($parent["uri"]), intval($existing_message["parent"]));
+
+ // Update the parent uri in the thread - but only if it points to itself
+ $r = q("UPDATE `item` SET `thr-parent` = '%s' WHERE (`parent` = %d) AND (`uri` = `thr-parent`)",
+ dbesc($parent["uri"]), intval($existing_message["parent"]));
+
+ // Now delete the thread
+ delete_thread($existing_message["parent"]);
}
}
continue;
$newitem = item_store($arr);
- logger('Stored new item '.$plink.' under id '.$newitem, LOGGER_DEBUG);
+ logger('Stored new item '.$plink.' for parent '.$arr["parent"].' under id '.$newitem, LOGGER_DEBUG);
// Add the conversation entry (but don't fetch the whole conversation)
complete_conversation($newitem, $conversation_url, true);
// If the newly created item is the top item then change the parent settings of the thread
- // This shouldn't happen anymore. This could is supposed to be absolote.
+ // This shouldn't happen anymore. This is supposed to be absolote.
if ($newitem AND ($arr["uri"] == $first_id)) {
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",
intval($message["uid"]), intval($newitem));
- if ($new_parents) {
+ if ($new_parents)
$parent = $new_parents[0];
- logger('done changing parents to parent '.$newitem);
- }
}
}
}