X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fostatus_conversation.php;h=403f95f4b0ca249ee33aa019a4be3da970771f21;hb=a26d04574dc402adfb501f222cc824161aece9ea;hp=1185c01f95a1128e4affb30c3e1f6948b2efbf89;hpb=edf8bde58107afbb8a2395ac8021a4dbcc73cd5f;p=friendica.git diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index 1185c01f95..403f95f4b0 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -20,15 +20,15 @@ function check_conversations() { if($last) { $next = $last + ($poll_interval * 60); if($next > time()) { - logger('complete_conversation: poll interval not reached'); + logger('poll interval not reached'); return; } } - logger('complete_conversation: cron_start'); + logger('cron_start'); $start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60)); - $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", + $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", dbesc($start)); foreach ($conversations AS $conversation) { $id = $conversation['oid']; @@ -36,7 +36,7 @@ function check_conversations() { complete_conversation($id, $url); } - logger('complete_conversation: cron_end'); + logger(' cron_end'); set_config('system','ostatus_last_poll', time()); } @@ -44,7 +44,13 @@ function check_conversations() { function complete_conversation($itemid, $conversation_url, $only_add_conversation = false) { global $a; - //logger('complete_conversation: completing conversation url '.$conversation_url.' for id '.$itemid); + if (intval(get_config('system','ostatus_poll_interval')) == -2) + return; + + if ($a->last_ostatus_conversation_url == $conversation_url) + return; + + $a->last_ostatus_conversation_url = $conversation_url; $messages = q("SELECT `uid`, `parent`, `created` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) @@ -82,8 +88,6 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio do { $conv_as = fetch_url($conv."?page=".$pageno); - //$conv_as = fetch_url($conv."?page=".$pageno, false, 0, 10); - //$conv_as = file_get_contents($conv."?page=".$pageno); $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); @@ -102,7 +106,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $items = array_reverse($items); foreach ($items as $single_conv) { - // identi.ca just changed the format of the activity streams. This is a quick fix. + // status.net changed the format of the activity streams. This is a quick fix. if (@is_string($single_conv->object->id)) $single_conv->id = $single_conv->object->id; @@ -119,7 +123,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio intval($message["uid"]), dbesc($first_id)); if ($new_parents) { $parent = $new_parents[0]; - logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid); + logger('adopting new parent '.$parent["id"].' for '.$itemid); } else { $parent["id"] = 0; $parent["uri"] = $first_id; @@ -136,7 +140,9 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio if ($message_exists) { if ($parent["id"] != 0) { $existing_message = $message_exists[0]; - $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d LIMIT 1", + + // 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), @@ -145,11 +151,23 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio continue; } + $contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", + $message["uid"], normalise_link($single_conv->actor->id), NETWORK_STATUSNET); + + if (count($contact)) { + logger("Found contact for url ".$single_conv->actor->id, LOGGER_DEBUG); + $contact_id = $contact[0]["id"]; + } else { + logger("No contact found for url ".$single_conv->actor->id, LOGGER_DEBUG); + $contact_id = $parent["contact-id"]; + } + $arr = array(); + $arr["network"] = NETWORK_OSTATUS; $arr["uri"] = $single_conv->id; $arr["plink"] = $single_conv->id; $arr["uid"] = $message["uid"]; - $arr["contact-id"] = $parent["contact-id"]; // To-Do + $arr["contact-id"] = $contact_id; if ($parent["id"] != 0) $arr["parent"] = $parent["id"]; $arr["parent-uri"] = $parent["uri"]; @@ -192,20 +210,13 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio // If the newly created item is the top item then change the parent settings of the thread if ($newitem AND ($arr["uri"] == $first_id)) { - logger('complete_conversation: setting new parent to id '.$newitem); + 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) { $parent = $new_parents[0]; - logger('complete_conversation: done changing parents to parent '.$newitem); + logger('done changing parents to parent '.$newitem); } - - /*logger('complete_conversation: changing parents to parent '.$newitem.' old parent: '.$parent["id"].' new uri: '.$arr["uri"]); - $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s' WHERE `parent` = %d", - intval($newitem), - dbesc($arr["uri"]), - intval($parent["id"])); - logger('complete_conversation: done changing parents to parent '.$newitem.' '.print_r($r, true));*/ } } }