]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge pull request #10478 from annando/notice
[friendica.git] / src / Model / Contact.php
index 92f3a48bf53e73263f60324c33b61dcd8cad3ac9..0184861c3c2d8403750bb075d5c69a03781cd43c 100644 (file)
@@ -185,6 +185,8 @@ class Contact
                        $fields['gsid'] = GServer::getID($fields['baseurl'], true);
                }
 
+               $fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
+
                if (empty($fields['created'])) {
                        $fields['created'] = DateTimeFormat::utcNow();
                }
@@ -1070,12 +1072,12 @@ class Contact
                        return 0;
                }
 
-               $contact = self::getByURL($url, false, ['id', 'network'], $uid);
+               $contact = self::getByURL($url, false, ['id', 'network', 'uri-id'], $uid);
 
                if (!empty($contact)) {
                        $contact_id = $contact["id"];
 
-                       if (empty($update)) {
+                       if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) {
                                Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]);
                                return $contact_id;
                        }
@@ -2021,7 +2023,7 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
+               $fields = ['uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
                        'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
                        'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
@@ -2050,6 +2052,9 @@ class Contact
                $uid = $contact['uid'];
                unset($contact['uid']);
 
+               $uriid = $contact['uri-id'];
+               unset($contact['uri-id']);
+
                $pubkey = $contact['pubkey'];
                unset($contact['pubkey']);
 
@@ -2103,6 +2108,7 @@ class Contact
                }
 
                $update = false;
+               $guid = $ret['guid'] ?? '';
 
                // make sure to not overwrite existing values with blank entries except some technical fields
                $keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
@@ -2122,6 +2128,10 @@ class Contact
                        unset($ret['last-item']);
                }
 
+               if (empty($uriid)) {
+                       $update = true;
+               }
+
                if (!empty($ret['photo']) && ($ret['network'] != Protocol::FEED)) {
                        self::updateAvatar($id, $ret['photo'], $update);
                }
@@ -2144,9 +2154,15 @@ class Contact
                        return true;
                }
 
-               $ret['nurl'] = Strings::normaliseLink($ret['url']);
+               if (empty($guid)) {
+                       $ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
+               } else {
+                       $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
+               }
+
+               $ret['nurl']    = Strings::normaliseLink($ret['url']);
                $ret['updated'] = $updated;
-               $ret['failed'] = false;
+               $ret['failed']  = false;
 
                // Only fill the pubkey if it had been empty before. We have to prevent identity theft.
                if (empty($pubkey) && !empty($new_pubkey)) {