]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact.php
Added post update to remove duplicated contacts
[friendica.git] / src / Module / Contact.php
index dfa0b0659c097493ae7c88521b12e4d7ada9d406..198496a0eb61f6bf055f4e765eed30743d52b419 100644 (file)
@@ -176,54 +176,16 @@ class Contact extends BaseModule
 
        private static function updateContactFromProbe($contact_id)
        {
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
+               $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
                if (!DBA::isResult($contact)) {
                        return;
                }
 
-               $uid = $contact['uid'];
-
-               $data = Probe::uri($contact['url'], '', 0, false);
-
-               // 'Feed' or 'Unknown' is mostly a sign of communication problems
-               if ((in_array($data['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($data['network'] != $contact['network'])) {
-                       return;
-               }
-
-               $updatefields = ['name', 'nick', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
-               $fields = [];
-
-               if ($data['network'] == Protocol::OSTATUS) {
-                       $result = Model\Contact::createFromProbe($uid, $data['url'], false);
-
-                       if ($result['success']) {
-                               $fields['subhub'] = true;
-                       }
-               }
-
-               foreach ($updatefields AS $field) {
-                       if (!empty($data[$field])) {
-                               $fields[$field] = $data[$field];
-                       }
-               }
-
-               $fields['nurl'] = Strings::normaliseLink($data['url']);
-
-               if (!empty($data['priority'])) {
-                       $fields['priority'] = intval($data['priority']);
-               }
-
-               if (empty($fields)) {
-                       return;
-               }
-
-               DBA::update('contact', $fields, ['id' => $contact_id, 'uid' => local_user()]);
-
                // Update the entry in the contact table
-               Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
+               Model\Contact::updateFromProbe($contact_id, '', true);
 
                // Update the entry in the gcontact table
-               Model\GContact::updateFromProbe($data['url']);
+               Model\GContact::updateFromProbe($contact['url']);
        }
 
        private static function blockContact($contact_id)
@@ -668,19 +630,19 @@ class Contact extends BaseModule
 
                switch ($type) {
                        case 'blocked':
-                               $sql_extra = " AND `blocked` = 1";
+                               $sql_extra = " AND `blocked`";
                                break;
                        case 'hidden':
-                               $sql_extra = " AND `hidden` = 1 AND `blocked` = 0";
+                               $sql_extra = " AND `hidden` AND NOT `blocked`";
                                break;
                        case 'ignored':
-                               $sql_extra = " AND `readonly` = 1 AND `blocked` = 0";
+                               $sql_extra = " AND `readonly` AND NOT `blocked`";
                                break;
                        case 'archived':
-                               $sql_extra = " AND `archive` = 1 AND `blocked` = 0";
+                               $sql_extra = " AND `archive` AND NOT `blocked`";
                                break;
                        default:
-                               $sql_extra = " AND `blocked` = 0";
+                               $sql_extra = " AND NOT `archive` AND NOT `blocked`";
                }
 
                $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
@@ -984,24 +946,26 @@ class Contact extends BaseModule
                $dir_icon = '';
                $alt_text = '';
 
-               switch ($rr['rel']) {
-                       case Model\Contact::FRIEND:
-                               $dir_icon = 'images/lrarrow.gif';
-                               $alt_text = L10n::t('Mutual Friendship');
-                               break;
+               if (!empty($rr['uid']) && !empty($rr['rel'])) {
+                       switch ($rr['rel']) {
+                               case Model\Contact::FRIEND:
+                                       $dir_icon = 'images/lrarrow.gif';
+                                       $alt_text = L10n::t('Mutual Friendship');
+                                       break;
 
-                       case Model\Contact::FOLLOWER;
-                               $dir_icon = 'images/larrow.gif';
-                               $alt_text = L10n::t('is a fan of yours');
-                               break;
+                               case Model\Contact::FOLLOWER;
+                                       $dir_icon = 'images/larrow.gif';
+                                       $alt_text = L10n::t('is a fan of yours');
+                                       break;
 
-                       case Model\Contact::SHARING;
-                               $dir_icon = 'images/rarrow.gif';
-                               $alt_text = L10n::t('you are a fan of');
-                               break;
+                               case Model\Contact::SHARING;
+                                       $dir_icon = 'images/rarrow.gif';
+                                       $alt_text = L10n::t('you are a fan of');
+                                       break;
 
-                       default:
-                               break;
+                               default:
+                                       break;
+                       }
                }
 
                $url = Model\Contact::magicLink($rr['url']);