OStatus: Don't be confused by posts from the statusnet connector.

This commit is contained in:
Michael Vogel 2015-05-27 08:16:05 +02:00
parent 03214254ff
commit bdd5c05668
2 changed files with 54 additions and 21 deletions

View file

@ -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,18 +1368,30 @@ 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 {
}
$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 `created` = '%s' AND `contact-id` = %d AND `uid` = %d LIMIT 1",
$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'])
@ -1375,7 +1400,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
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)?
if ($arr["uid"] == 0) {

View file

@ -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);