]> git.mxchange.org Git - friendica.git/commitdiff
Improved check for duplicates. Improvements with reshared Diaspora items.
authorMichael Vogel <icarus@dabo.de>
Mon, 25 May 2015 17:07:59 +0000 (19:07 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 25 May 2015 17:07:59 +0000 (19:07 +0200)
include/diaspora.php
include/items.php

index c683ded1da7e5274a315bee6622faa05df9aeb39..68e38f8c4ce6a3b53a07415dc70676cc852a8af1 100755 (executable)
@@ -785,12 +785,21 @@ function diaspora_is_redmatrix($url) {
 }
 
 function diaspora_plink($addr, $guid) {
-       $r = q("SELECT `url`, `nick` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", $addr);
+       $r = q("SELECT `url`, `nick`, `network` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", $addr);
 
        // Fallback
        if (!$r)
                return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid;
 
+       // Friendica contacts are often detected as Diaspora contacts in the "fcontact" table
+       // So we try another way as well.
+       $s = q("SELECT `network` FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($r[0]["url"])));
+       if ($s)
+               $r[0]["network"] = $s[0]["network"];
+
+       if ($r[0]["network"] == NETWORK_DFRN)
+               return(str_replace("/profile/".$r[0]["nick"]."/", "/display/".$guid, $r[0]["url"]."/"));
+
        if (diaspora_is_redmatrix($r[0]["url"]))
                return $r[0]["url"]."/?f=&mid=".$guid;
 
@@ -1105,16 +1114,17 @@ function diaspora_reshare($importer,$xml,$msg) {
 
        $orig_author = notags(unxmlify($xml->root_diaspora_id));
        $orig_guid = notags(unxmlify($xml->root_guid));
+       $orig_url = $a->get_baseurl()."/display/".$orig_guid;
 
        $create_original_post = false;
 
        // Do we already have this item?
-       $r = q("SELECT `body`, `tag`, `app`, `created`, `author-link`, `plink` FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
+       $r = q("SELECT `body`, `tag`, `app`, `created`, `plink`, `object`, `object-type`, `uri` FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
                dbesc($orig_guid),
                dbesc(NETWORK_DIASPORA)
        );
        if(count($r)) {
-               logger('reshared message '.$orig_guid." reshared by ".$guid.' already exists on system: '.$orig_url);
+               logger('reshared message '.$orig_guid." reshared by ".$guid.' already exists on system.');
 
                // Maybe it is already a reshared item?
                // Then refetch the content, since there can be many side effects with reshared posts from other networks or reshares from reshares
@@ -1126,9 +1136,9 @@ function diaspora_reshare($importer,$xml,$msg) {
                        $str_tags = $r[0]["tag"];
                        $app = $r[0]["app"];
                        $orig_created = $r[0]["created"];
-                       $orig_author = $r[0]["author-link"];
+                       $orig_plink = $r[0]["plink"];
+                       $orig_uri = $r[0]["uri"];
                        $create_original_post = ($body != "");
-                       $orig_url = $a->get_baseurl()."/display/".$orig_guid;
                        $object = $r[0]["object"];
                        $objecttype = $r[0]["object-type"];
                }
@@ -1139,8 +1149,6 @@ function diaspora_reshare($importer,$xml,$msg) {
                $str_tags = "";
                $app = "";
 
-               $orig_url = 'https://'.substr($orig_author,strpos($orig_author,'@')+1).'/posts/'.$orig_guid;
-
                $server = 'https://'.substr($orig_author,strpos($orig_author,'@')+1);
                logger('1st try: reshared message '.$orig_guid." reshared by ".$guid.' will be fetched from original server: '.$server);
                $item = diaspora_fetch_message($orig_guid, $server);
@@ -1168,13 +1176,16 @@ function diaspora_reshare($importer,$xml,$msg) {
                        $orig_created = $item["created"];
                        $orig_author = $item["author"];
                        $orig_guid = $item["guid"];
+                       $orig_plink = diaspora_plink($orig_author, $orig_guid);
+                       $orig_uri = $orig_author.':'.$orig_guid;
                        $create_original_post = ($body != "");
-                       $orig_url = $a->get_baseurl()."/display/".$orig_guid;
                        $object = $item["object"];
                        $objecttype = $item["object-type"];
                }
        }
 
+       $plink = diaspora_plink($diaspora_handle, $guid);
+
        $person = find_diaspora_person_by_handle($orig_author);
 
        $created = unxmlify($xml->created_at);
@@ -1182,8 +1193,6 @@ function diaspora_reshare($importer,$xml,$msg) {
 
        $datarray = array();
 
-       $plink = diaspora_plink($diaspora_handle, $guid);
-
        $datarray['uid'] = $importer['uid'];
        $datarray['contact-id'] = $contact['id'];
        $datarray['wall'] = 0;
@@ -1230,9 +1239,9 @@ function diaspora_reshare($importer,$xml,$msg) {
                $datarray2['uid'] = 0;
                $datarray2['contact-id'] = get_contact($person['url'], 0);
                $datarray2['guid'] = $orig_guid;
-               $datarray2['uri'] = $datarray2['parent-uri'] = $orig_author.':'.$orig_guid;
+               $datarray2['uri'] = $orig_uri;
                $datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = $datarray2['commented'] = $datarray2['received'] = datetime_convert('UTC','UTC',$orig_created);
-               $datarray2['plink'] = diaspora_plink($orig_author, $orig_guid);
+               $datarray2['plink'] = $orig_plink;
 
                $datarray2['author-name'] = $person['name'];
                $datarray2['author-link'] = $person['url'];
index 85d02ab60d55ef4a1eba1e3c392ed38c7c001bab..58db71d479cb9898b9bd410a36efd0accf7f27a4 100644 (file)
@@ -1351,9 +1351,22 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                dbesc($arr['uri']),
                intval($arr['uid'])
        );
+
        if($r && count($r)) {
-               logger('item-store: duplicate item ignored. ' . print_r($arr,true));
+               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;
+               }
        }
 
        // Is this item available in the global items (with uid=0)?