From e668fece109f529345e5f3377c0bdcd2ab15161f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 28 Jan 2013 01:16:51 +0100 Subject: [PATCH] ostatus auto completion now seems to work. --- include/items.php | 6 ++++- include/ostatus_conversation.php | 40 +++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/items.php b/include/items.php index 94835d7ad..13566075b 100755 --- a/include/items.php +++ b/include/items.php @@ -8,6 +8,7 @@ require_once('include/Photo.php'); require_once('include/tags.php'); require_once('include/text.php'); require_once('include/email.php'); +require_once('include/ostatus_conversation.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -1098,7 +1099,6 @@ function item_store($arr,$force_parent = false) { $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); create_tags_from_item($r[0]['id']); - // ostatus_conversation } else { logger('item_store: could not locate created item'); return 0; @@ -1135,6 +1135,10 @@ function item_store($arr,$force_parent = false) { ); create_tags_from_item($current_post); + // Complete ostatus threads + if ($ostatus_conversation) + complete_conversation($current_post, $ostatus_conversation); + $arr['id'] = $current_post; $arr['parent'] = $parent_id; $arr['allow_cid'] = $allow_cid; diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index a56673390..2851fdb1f 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -1,5 +1,5 @@ items); foreach ($items as $single_conv) { //print_r($single_conv); + if ($first_id == "") { + $first_id = $single_conv->id; + + $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", + intval($message["uid"]), dbesc($first_id)); + if ($new_parents) + $parent = $new_parents[0]; + + logger('complete_conversation: adopting new parent '.$parent["id"].' for '.$itemid); + } + if (isset($single_conv->context->inReplyTo->id)) $parent_uri = $single_conv->context->inReplyTo->id; else @@ -99,14 +116,25 @@ function complete_conversation($itemid, $conversation_url) { if ($arr["coord"] == "") unset($arr["coord"]); - item_store($arr); + $newitem = item_store($arr); + + // 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: 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($arr); } } } - +/* $id = 282481; $conversation = "http://identi.ca/conversation/98268580"; complete_conversation($id, $conversation); +*/ ?>