]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Fix expected implementation of JsonLD::fetchElementArray
[friendica.git] / src / Model / Contact.php
index e997bffdef95a5dee31c178b12cf57ab09a9ae28..67b9c903831f04abb46f2fbb71add565aefd85d8 100644 (file)
@@ -91,6 +91,8 @@ class Contact
         * @}
         */
 
+       const LOCK_INSERT = 'contact-insert';
+
        /**
         * Account types
         *
@@ -752,7 +754,6 @@ class Contact
                        $item['title'] = '';
                        $item['guid'] = '';
                        $item['uri-id'] = 0;
-                       $item['attach'] = '';
                        $slap = OStatus::salmon($item, $user);
 
                        if (!empty($contact['notify'])) {
@@ -942,9 +943,9 @@ class Contact
                $unfollow_link = '';
                if (!$contact['self'] && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
                        if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
-                               $unfollow_link = 'unfollow?url=' . urlencode($contact['url']);
+                               $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1';
                        } elseif(!$contact['pending']) {
-                               $follow_link = 'follow?url=' . urlencode($contact['url']);
+                               $follow_link = 'follow?url=' . urlencode($contact['url']) . '&auto=1';
                        }
                }
 
@@ -1125,19 +1126,23 @@ class Contact
                        $condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
 
                        // Before inserting we do check if the entry does exist now.
-                       DBA::lock('contact');
-                       $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
-                       if (DBA::isResult($contact)) {
-                               $contact_id = $contact['id'];
-                               Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
-                       } else {
-                               DBA::insert('contact', $fields);
-                               $contact_id = DBA::lastInsertId();
-                               if ($contact_id) {
-                                       Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                       if (DI::lock()->acquire(self::LOCK_INSERT, 0)) {
+                               $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
+                               if (DBA::isResult($contact)) {
+                                       $contact_id = $contact['id'];
+                                       Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                               } else {
+                                       DBA::insert('contact', $fields);
+                                       $contact_id = DBA::lastInsertId();
+                                       if ($contact_id) {
+                                               Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                                       }
                                }
+                               DI::lock()->release(self::LOCK_INSERT);
+                       } else {
+                               Logger::warning('Contact lock had not been acquired');
                        }
-                       DBA::unlock();
+
                        if (!$contact_id) {
                                Logger::info('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
                                return 0;
@@ -1247,25 +1252,27 @@ class Contact
         *
         * @param string $contact_url Contact URL
         * @param bool   $thread_mode
-        * @param int    $update
+        * @param int    $update      Update mode 
+        * @param int    $parent      Item parent ID for the update mode
         * @return string posts in HTML
         * @throws \Exception
         */
-       public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0)
+       public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0, $parent = 0)
        {
-               return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update);
+               return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update, $parent);
        }
 
        /**
         * Returns posts from a given contact id
         *
-        * @param integer $cid
-        * @param bool    $thread_mode
-        * @param integer $update
+        * @param int  $cid         Contact ID
+        * @param bool $thread_mode
+        * @param int  $update      Update mode 
+        * @param int  $parent     Item parent ID for the update mode
         * @return string posts in HTML
         * @throws \Exception
         */
-       public static function getPostsFromId($cid, $thread_mode = false, $update = 0)
+       public static function getPostsFromId($cid, $thread_mode = false, $update = 0, $parent = 0)
        {
                $a = DI::app();
 
@@ -1290,9 +1297,13 @@ class Contact
                                $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
                }
 
-               $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
-               if (!empty($last_received)) {
-                       $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+               if (!empty($parent)) {
+                       $condition = DBA::mergeConditions($condition, ['parent' => $parent]);
+               } else {
+                       $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
+                       if (!empty($last_received)) {
+                               $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+                       }
                }
 
                if (DI::mode()->isMobile()) {
@@ -1335,7 +1346,7 @@ class Contact
 
                        $items = Item::inArray($r);
 
-                       $o .= conversation($a, $items, 'contact-posts', false);
+                       $o .= conversation($a, $items, 'contact-posts', $update);
                }
 
                if (!$update) {
@@ -2221,7 +2232,6 @@ class Contact
                                $item['title'] = '';
                                $item['guid'] = '';
                                $item['uri-id'] = 0;
-                               $item['attach'] = '';
 
                                $slap = OStatus::salmon($item, $owner);