]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
prevent duplicate likes
[friendica.git] / include / items.php
index a1254e165ac9cbc162e4da590cb61eb04339ed9d..fdff6b642fa33139681f4aa48c7e4f087ffed721 100755 (executable)
@@ -1595,6 +1595,14 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -1747,6 +1755,18 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                $datarray['parent-uri'] = $item_id;
                                $datarray['uid'] = $importer['uid'];
                                $datarray['contact-id'] = $contact['id'];
+
+                               if(x($datarray,'owner-link') && strlen($datarray['owner-link']) && (! link_compare($datarray['owner-link'],$contact['url']))) {
+                                       // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, 
+                                       // but otherwise there's a possible data mixup on the sender's system.
+                                       // the tgroup delivery code called from item_store will correct it if it's a forum,
+                                       // but we're going to unconditionally correct it here so that the post will always be owned by our contact. 
+                                       logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
+                                       $datarray['owner-name']   = $contact['name'];
+                                       $datarray['owner-link']   = $contact['url'];
+                                       $datarray['owner-avatar'] = $contact['thumb'];
+                               }
+
                                $r = item_store($datarray);
                                continue;
 
@@ -2136,6 +2156,14 @@ function local_delivery($importer,$data) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                        $datarray['last-child'] = 0;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -2285,6 +2313,15 @@ function local_delivery($importer,$data) {
                                if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
+
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -2439,6 +2476,18 @@ function local_delivery($importer,$data) {
                        $datarray['parent-uri'] = $item_id;
                        $datarray['uid'] = $importer['importer_uid'];
                        $datarray['contact-id'] = $importer['id'];
+
+                       if(x($datarray,'owner-link') && strlen($datarray['owner-link']) && (! link_compare($datarray['owner-link'],$importer['url']))) {
+                               // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, 
+                               // but otherwise there's a possible data mixup on the sender's system.
+                               // the tgroup delivery code called from item_store will correct it if it's a forum,
+                               // but we're going to unconditionally correct it here so that the post will always be owned by our contact. 
+                               logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
+                               $datarray['owner-name']   = $importer['senderName'];
+                               $datarray['owner-link']   = $importer['url'];
+                               $datarray['owner-avatar'] = $importer['thumb'];
+                       }
+
                        $r = item_store($datarray);
                        continue;
                }