Merge pull request #10885 from annando/fcontact-suggest
Remove "fcontact" from suggestions
This commit is contained in:
commit
1274fe6f9b
8 changed files with 96 additions and 87 deletions
|
@ -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='';
|
||||
|
||||
--
|
||||
|
|
|
@ -7,11 +7,12 @@ 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 | |
|
||||
| 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 | |
|
||||
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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" => ""],
|
||||
|
|
15
update.php
15
update.php
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue