From bdd5c05668fafbadbc19026b75269ff9e97dbc70 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 27 May 2015 08:16:05 +0200 Subject: [PATCH] OStatus: Don't be confused by posts from the statusnet connector. --- include/items.php | 52 +++++++++++++++++++++++--------- include/ostatus_conversation.php | 23 +++++++++----- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/include/items.php b/include/items.php index 3b4a5a193..69b4a0f25 100644 --- a/include/items.php +++ b/include/items.php @@ -1149,6 +1149,19 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } } + // If there is no guid then take the same guid that was taken before for the same plink + if ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "")) { + logger('item_store: checking for an existing guid for plink '.$arr['plink'], LOGGER_DEBUG); + $r = q("SELECT `guid` FROM `item` WHERE `plink` = '%s' AND `guid` != '' LIMIT 1", + dbesc(trim($arr['plink'])) + ); + + if(count($r)) { + $arr['guid'] = $r[0]["guid"]; + logger('item_store: found guid '.$arr['guid'].' for plink '.$arr['plink'], LOGGER_DEBUG); + } + } + // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) @@ -1355,26 +1368,37 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } } - $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", dbesc($arr['uri']), + dbesc($arr['network']), intval($arr['uid']) ); - if($r && count($r)) { logger('duplicated item with the same uri found. ' . print_r($arr,true)); return 0; - } else { - // Check for an existing post with the same content. There seems to be a problem with OStatus. - $r = q("SELECT `id` FROM `item` WHERE `body` = '%s' AND `created` = '%s' AND `contact-id` = %d AND `uid` = %d LIMIT 1", - dbesc($arr['body']), - dbesc($arr['created']), - intval($arr['contact-id']), - intval($arr['uid']) - ); - if($r && count($r)) { - logger('duplicated item with the same body found. ' . print_r($arr,true)); - return 0; - } + } + + $r = q("SELECT `id` FROM `item` WHERE `plink` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", + dbesc($arr['plink']), + dbesc($arr['network']), + intval($arr['uid']) + ); + if($r && count($r)) { + logger('duplicated item with the same plink found. ' . print_r($arr,true)); + return 0; + } + + // Check for an existing post with the same content. There seems to be a problem with OStatus. + $r = q("SELECT `id` FROM `item` WHERE `body` = '%s' AND `network` = '%s' AND `created` = '%s' AND `contact-id` = %d AND `uid` = %d LIMIT 1", + dbesc($arr['body']), + dbesc($arr['network']), + dbesc($arr['created']), + intval($arr['contact-id']), + intval($arr['uid']) + ); + if($r && count($r)) { + logger('duplicated item with the same body found. ' . print_r($arr,true)); + return 0; } // Is this item available in the global items (with uid=0)? diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index da8dda292..f21f8248f 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -143,6 +143,8 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $plink = $single_conv->provider->url."notice/".$single_conv->statusnet_notice_info->local_id; elseif (isset($single_conv->provider->url) AND isset($single_conv->statusnet->notice_info->local_id)) $plink = $single_conv->provider->url."notice/".$single_conv->statusnet->notice_info->local_id; + elseif (isset($single_conv->provider->url) AND isset($single_conv->status_net->notice_info->local_id)) + $plink = $single_conv->provider->url."notice/".$single_conv->status_net->notice_info->local_id; if (@!$single_conv->id) continue; @@ -153,8 +155,9 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio 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)); + $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", + intval($message["uid"]), dbesc($first_id), + dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($new_parents) { $parent = $new_parents[0]; logger('adopting new parent '.$parent["id"].' for '.$itemid); @@ -169,17 +172,21 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio else $parent_uri = $parent["uri"]; - $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `plink` = '%s' LIMIT 1", - intval($message["uid"]), dbesc($plink)); + $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `plink` = '%s' AND `network` IN ('%s','%s') LIMIT 1", + intval($message["uid"]), dbesc($plink), + dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if (!$message_exists) - $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", - intval($message["uid"]), dbesc($single_conv->id)); + $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", + intval($message["uid"]), dbesc($single_conv->id), + dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($message_exists) { if ($parent["id"] != 0) { $existing_message = $message_exists[0]; + 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"]), @@ -229,7 +236,9 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $arr["author-avatar"] = $single_conv->actor->image->url; $arr["body"] = html2bbcode($single_conv->content); - if (isset($single_conv->statusnet->notice_info->source)) + if (isset($single_conv->status_net->notice_info->source)) + $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); + elseif (isset($single_conv->statusnet->notice_info->source)) $arr["app"] = strip_tags($single_conv->statusnet->notice_info->source); elseif (isset($single_conv->statusnet_notice_info->source)) $arr["app"] = strip_tags($single_conv->statusnet_notice_info->source);