logger('complete_conversation: Storing conversation url '.$conversation_url.' for id '.$itemid);
logger('Storing conversation url '.$conversation_url.' for id '.$itemid);
}
if($only_add_conversation)
@ -113,7 +114,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
$pageno=1;
$items=array();
logger('complete_conversation: fetching conversation url '.$conv.' for '.$itemid);
logger('fetching conversation url '.$conv.' for id '.$itemid.an>' and parent '.$parent["id"]);
do{
$conv_as=fetch_url($conv."?page=".$pageno);
@ -152,16 +153,21 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
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;
@ -186,16 +192,28 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio
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",