]> git.mxchange.org Git - friendica.git/commitdiff
Remove "fcontact" from suggestions
authorMichael <heluecht@pirati.ca>
Sun, 17 Oct 2021 20:19:02 +0000 (20:19 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 17 Oct 2021 20:19:02 +0000 (20:19 +0000)
database.sql
doc/database/db_intro.md
mod/ping.php
src/Model/FContact.php
src/Navigation/Notifications/Factory/Introduction.php
src/Protocol/DFRN.php
static/dbstructure.config.php
update.php

index b26a9d57ccdb5618bb678e90310f8cfa4d1fd535..793aae3863a7d4c05e7936b4a22f43ba4e38635a 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.12-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1438
+-- DB_UPDATE_VERSION 1439
 -- ------------------------------------------
 
 
@@ -711,8 +711,9 @@ CREATE TABLE IF NOT EXISTS `inbox-status` (
 CREATE TABLE IF NOT EXISTS `intro` (
        `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
        `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
-       `fid` int unsigned COMMENT '',
+       `fid` int unsigned COMMENT 'deprecated',
        `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
+       `suggest-cid` int unsigned COMMENT 'Suggested contact',
        `knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
        `duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
        `note` text COMMENT '',
@@ -724,7 +725,8 @@ CREATE TABLE IF NOT EXISTS `intro` (
         INDEX `contact-id` (`contact-id`),
         INDEX `uid` (`uid`),
        FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
-       FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+       FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+       FOREIGN KEY (`suggest-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
 
 --
index 426d8579ddb00cf181eb8a1ce5c2815d03c71025..1040402e58de460afe2d73e9bd6690dab8f8d224 100644 (file)
@@ -6,19 +6,20 @@ Table intro
 Fields
 ------
 
-| Field      | Description   | Type               | Null | Key | Default             | Extra          |
-| ---------- | ------------- | ------------------ | ---- | --- | ------------------- | -------------- |
-| id         | sequential ID | int unsigned       | NO   | PRI | NULL                | auto_increment |
-| uid        | User id       | mediumint unsigned | NO   |     | 0                   |                |
-| fid        |               | int unsigned       | YES  |     | NULL                |                |
-| contact-id |               | int unsigned       | NO   |     | 0                   |                |
-| knowyou    |               | boolean            | NO   |     | 0                   |                |
-| duplex     |               | boolean            | NO   |     | 0                   |                |
-| note       |               | text               | YES  |     | NULL                |                |
-| hash       |               | varchar(255)       | NO   |     |                     |                |
-| datetime   |               | datetime           | NO   |     | 0001-01-01 00:00:00 |                |
-| blocked    |               | boolean            | NO   |     | 1                   |                |
-| ignore     |               | boolean            | NO   |     | 0                   |                |
+| Field       | Description       | Type               | Null | Key | Default             | Extra          |
+| ----------- | ----------------- | ------------------ | ---- | --- | ------------------- | -------------- |
+| id          | sequential ID     | int unsigned       | NO   | PRI | NULL                | auto_increment |
+| uid         | User id           | mediumint unsigned | NO   |     | 0                   |                |
+| fid         | deprecated        | int unsigned       | YES  |     | NULL                |                |
+| contact-id  |                   | int unsigned       | NO   |     | 0                   |                |
+| suggest-cid | Suggested contact | int unsigned       | YES  |     | NULL                |                |
+| knowyou     |                   | boolean            | NO   |     | 0                   |                |
+| duplex      |                   | boolean            | NO   |     | 0                   |                |
+| note        |                   | text               | YES  |     | NULL                |                |
+| hash        |                   | varchar(255)       | NO   |     |                     |                |
+| datetime    |                   | datetime           | NO   |     | 0001-01-01 00:00:00 |                |
+| blocked     |                   | boolean            | NO   |     | 1                   |                |
+| ignore      |                   | boolean            | NO   |     | 0                   |                |
 
 Indexes
 ------------
@@ -36,5 +37,6 @@ Foreign Keys
 |-------|--------------|--------------|
 | uid | [user](help/database/db_user) | uid |
 | contact-id | [contact](help/database/db_contact) | id |
+| suggest-cid | [contact](help/database/db_contact) | id |
 
 Return to [database documentation](help/database)
index 1b4cfb3332a8c29151b3d866bfe50834aa9b8d5b..3abb2f37a326d7098adeaf5783f076999c339ca5 100644 (file)
@@ -177,8 +177,8 @@ function ping_init(App $a)
 
                $intros1 = DBA::toArray(DBA::p(
                        "SELECT  `intro`.`id`, `intro`.`datetime`,
-                       `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`
-                       FROM `intro` INNER JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
+                       `contact`.`name`, `contact`.`url`, `contact`.`photo`
+                       FROM `intro` INNER JOIN `contact` ON `intro`.`suggest-cid` = `contact`.`id`
                        WHERE `intro`.`uid` = ? AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`fid` != 0",
                        local_user()
                ));
index 1c5c186e6994adec3f171ac979092378663f0626..006a37a608510b3d3453a8ffb0ab4504d25ae94a 100644 (file)
@@ -24,9 +24,7 @@ namespace Friendica\Model;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
-use Friendica\DI;
 use Friendica\Network\Probe;
-use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
@@ -128,63 +126,4 @@ class FContact
 
                return null;
        }
-
-       /**
-        * Suggest a given contact to a given user from a given contact
-        *
-        * @param integer $uid
-        * @param integer $cid
-        * @param integer $from_cid
-        * @return bool   Was the adding successful?
-        */
-       public static function addSuggestion(int $uid, int $cid, int $from_cid, string $note = '')
-       {
-               $owner = User::getOwnerDataById($uid);
-               $contact = Contact::getById($cid);
-               $from_contact = Contact::getById($from_cid);
-
-               if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($contact['url']), 'uid' => $uid])) {
-                       return false;
-               }
-
-               $fcontact = self::getByURL($contact['url'], null, $contact['network']);
-               if (empty($fcontact)) {
-                       Logger::warning('FContact had not been found', ['fcontact' => $contact['url']]);
-                       return false;
-               }
-
-               $fid = $fcontact['id'];
-
-               // Quit if we already have an introduction for this person
-               if (DBA::exists('intro', ['uid' => $uid, 'fid' => $fid])) {
-                       return false;
-               }
-
-               $suggest = [];
-               $suggest['uid'] = $uid;
-               $suggest['cid'] = $from_cid;
-               $suggest['url'] = $contact['url'];
-               $suggest['name'] = $contact['name'];
-               $suggest['photo'] = $contact['photo'];
-               $suggest['request'] = $contact['request'];
-               $suggest['title'] = '';
-               $suggest['body'] = $note;
-
-               $hash = Strings::getRandomHex();
-               $fields = ['uid' => $suggest['uid'], 'fid' => $fid, 'contact-id' => $suggest['cid'],
-                       'note' => $suggest['body'], 'hash' => $hash, 'datetime' => DateTimeFormat::utcNow(), 'blocked' => false];
-               DBA::insert('intro', $fields);
-
-               notification([
-                       'type'  => Notification\Type::SUGGEST,
-                       'otype' => Notification\ObjectType::INTRO,
-                       'verb'  => Activity::REQ_FRIEND,
-                       'uid'   => $owner['uid'],
-                       'cid'   => $from_contact['uid'],
-                       'item'  => $suggest,
-                       'link'  => DI::baseUrl().'/notifications/intros',
-               ]);
-
-               return true;
-       }
 }
index 0baf0385c679ac7fca34878d5e841055932f3e19..916ddff67a6f04dcc8259d6fb1ec29521e507e96 100644 (file)
@@ -98,14 +98,13 @@ class Introduction extends BaseFactory
                $formattedIntroductions = [];
 
                try {
-                       /// @todo Fetch contact details by "Contact::getByUrl" instead of queries to contact and fcontact
                        $stmtNotifications = $this->dba->p(
                                "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
-                               `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
-                               `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`
+                               `sugggest-contact`.`name` AS `fname`, `sugggest-contact`.`url` AS `furl`, `sugggest-contact`.`addr` AS `faddr`,
+                               `sugggest-contact`.`photo` AS `fphoto`, `sugggest-contact`.`request` AS `frequest`
                        FROM `intro`
                                LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
-                               LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
+                               LEFT JOIN `contact` AS `sugggest-contact` ON `intro`.`suggest-cid` = `sugggest-contact`.`id`
                        WHERE `intro`.`uid` = ? $sql_extra
                        LIMIT ?, ?",
                                $_SESSION['uid'],
@@ -121,7 +120,7 @@ class Introduction extends BaseFactory
                        // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
                                // We have to distinguish between these two because they use different data.
                                // Contact suggestions
-                               if ($intro['fid'] ?? '') {
+                               if ($intro['suggest-cid'] ?? '') {
                                        if (empty($intro['furl'])) {
                                                continue;
                                        }
index d73eabc2d277036ab340ba5cc83f2bd35bfdaf59..081b7f2a3748ed29fa8c45a1473abaf533d76495 100644 (file)
@@ -1330,7 +1330,58 @@ class DFRN
                $cid = Contact::getIdForURL($url);
                $note = $xpath->evaluate('string(dfrn:note[1]/text())', $suggestion);
 
-               return FContact::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
+               return self::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
+       }
+
+       /**
+        * Suggest a given contact to a given user from a given contact
+        *
+        * @param integer $uid
+        * @param integer $cid
+        * @param integer $from_cid
+        * @return bool   Was the adding successful?
+        */
+       private static function addSuggestion(int $uid, int $cid, int $from_cid, string $note = '')
+       {
+               $owner = User::getOwnerDataById($uid);
+               $contact = Contact::getById($cid);
+               $from_contact = Contact::getById($from_cid);
+
+               if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($contact['url']), 'uid' => $uid])) {
+                       return false;
+               }
+
+               // Quit if we already have an introduction for this person
+               if (DBA::exists('intro', ['uid' => $uid, 'suggest-cid' => $cid])) {
+                       return false;
+               }
+
+               $suggest = [];
+               $suggest['uid'] = $uid;
+               $suggest['cid'] = $from_cid;
+               $suggest['url'] = $contact['url'];
+               $suggest['name'] = $contact['name'];
+               $suggest['photo'] = $contact['photo'];
+               $suggest['request'] = $contact['request'];
+               $suggest['title'] = '';
+               $suggest['body'] = $note;
+
+               $hash = Strings::getRandomHex();
+               $fields = ['uid' => $suggest['uid'], 'suggest-cid' => $cid, 'contact-id' => $suggest['cid'],
+                       'note' => $suggest['body'], 'hash' => $hash, 'datetime' => DateTimeFormat::utcNow(), 'blocked' => false];
+               DBA::insert('intro', $fields);
+
+               notification([
+                       'type'  => Notification\Type::SUGGEST,
+                       'otype' => Notification\ObjectType::INTRO,
+                       'verb'  => Activity::REQ_FRIEND,
+                       'uid'   => $owner['uid'],
+                       'cid'   => $from_contact['uid'],
+                       'item'  => $suggest,
+                       'link'  => DI::baseUrl().'/notifications/intros',
+               ]);
+
+               return true;
        }
 
        /**
index e333c136f41423494b3ad0075804350c88ffe187..6f19865073014dd52a0a13242614c3d89432e6d0 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1438);
+       define('DB_UPDATE_VERSION', 1439);
 }
 
 return [
@@ -774,8 +774,9 @@ return [
                "fields" => [
                        "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
                        "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"],
-                       "fid" => ["type" => "int unsigned", "relation" => ["fcontact" => "id"], "comment" => ""],
+                       "fid" => ["type" => "int unsigned", "relation" => ["fcontact" => "id"], "comment" => "deprecated"],
                        "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""],
+                       "suggest-cid" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Suggested contact"],
                        "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "note" => ["type" => "text", "comment" => ""],
index 114401334401e8c514e28a0985258fe6a9402397..6a53c83f167959d2b95f5c5b18a0ab4c6e64da6b 100644 (file)
@@ -1013,3 +1013,18 @@ function update_1438()
        DBA::update('photo', ['photo-type' => Photo::CONTACT_AVATAR], ["NOT `profile` AND NOT `contact-id` IS NULL AND `contact-id` != ?", 0]);
        DBA::update('photo', ['photo-type' => Photo::DEFAULT], ["NOT `profile` AND (`contact-id` IS NULL OR `contact-id` = ?) AND `photo-type` IS NULL AND `album` != ?", 0, Photo::CONTACT_PHOTOS]);
 }
+
+function update_1439()
+{
+       $intros = DBA::select('intro', ['id', 'fid'], ["NOT `fid` IS NULL AND `fid` != ?", 0]);
+       while ($intro = DBA::fetch($intros)) {
+               $fcontact = DBA::selectFirst('fcontact', ['url'], ['id' => $intro['fid']]);
+               if (!empty($fcontact['url'])) {
+                       $id = Contact::getIdForURL($fcontact['url']);
+                       if (!empty($id)) {
+                               DBA::update('intro',['suggest-cid' => $id], ['id' => $intro['id']]);
+                       }
+               }
+       }
+       DBA::close($intros);
+}