mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 04:15:15 +02:00
Remove "fcontact" from suggestions
This commit is contained in:
parent
b0bb95bb0d
commit
f1d3f60499
8 changed files with 96 additions and 87 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue