mirror of
https://github.com/friendica/friendica
synced 2025-05-06 15:04:10 +02:00
Move Introduction to new depository paradigm
This commit is contained in:
parent
4c0e00fa4f
commit
a40f503fdd
14 changed files with 380 additions and 179 deletions
144
src/Model/Contact/Introduction.php
Normal file
144
src/Model/Contact/Introduction.php
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model\Contact;
|
||||
|
||||
use Friendica\Contact\Introduction\Entity;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
class Introduction
|
||||
{
|
||||
/**
|
||||
* Confirms a follow request and sends a notice to the remote contact.
|
||||
*
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function confirm(Entity\Introduction $introduction): void
|
||||
{
|
||||
DI::logger()->info('Confirming follower', ['cid' => $introduction->cid]);
|
||||
|
||||
$contact = Contact::selectFirst([], ['id' => $introduction->cid, 'uid' => $introduction->uid]);
|
||||
|
||||
if (!$contact) {
|
||||
throw new HTTPException\NotFoundException('Contact record not found.');
|
||||
}
|
||||
|
||||
$newRelation = $contact['rel'];
|
||||
$writable = $contact['writable'];
|
||||
|
||||
if (!empty($contact['protocol'])) {
|
||||
$protocol = $contact['protocol'];
|
||||
} else {
|
||||
$protocol = $contact['network'];
|
||||
}
|
||||
|
||||
if ($protocol == Protocol::ACTIVITYPUB) {
|
||||
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $contact['uid']);
|
||||
}
|
||||
|
||||
if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
|
||||
if ($introduction->duplex) {
|
||||
$newRelation = Contact::FRIEND;
|
||||
} else {
|
||||
$newRelation = Contact::FOLLOWER;
|
||||
}
|
||||
|
||||
if ($newRelation != Contact::FOLLOWER) {
|
||||
$writable = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'name-date' => DateTimeFormat::utcNow(),
|
||||
'uri-date' => DateTimeFormat::utcNow(),
|
||||
'blocked' => false,
|
||||
'pending' => false,
|
||||
'protocol' => $protocol,
|
||||
'writable' => $writable,
|
||||
'hidden' => $hidden ?? $contact['hidden'],
|
||||
'rel' => $newRelation,
|
||||
];
|
||||
Contact::update($fields, ['id' => $contact['id']]);
|
||||
|
||||
array_merge($contact, $fields);
|
||||
|
||||
if ($newRelation == Contact::FRIEND) {
|
||||
if ($protocol == Protocol::DIASPORA) {
|
||||
$ret = Diaspora::sendShare(User::getById($contact['uid']), $contact);
|
||||
DI::logger()->info('share returns', ['return' => $ret]);
|
||||
} elseif ($protocol == Protocol::ACTIVITYPUB) {
|
||||
ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $contact['uid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards the introduction and sends a rejection message to AP contacts.
|
||||
*
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function discard(Entity\Introduction $introduction): void
|
||||
{
|
||||
// If it is a friend suggestion, the contact is not a new friend but an existing friend
|
||||
// that should not be deleted.
|
||||
if (!$introduction->fid) {
|
||||
// When the contact entry had been created just for that intro, we want to get rid of it now
|
||||
$condition = [
|
||||
'id' => $introduction->cid,
|
||||
'uid' => $introduction->uid,
|
||||
'self' => false,
|
||||
'pending' => true,
|
||||
'rel' => [0, Contact::FOLLOWER]];
|
||||
if (DI::dba()->exists('contact', $condition)) {
|
||||
Contact::remove($introduction->cid);
|
||||
} else {
|
||||
Contact::update(['pending' => false], ['id' => $introduction->cid]);
|
||||
}
|
||||
}
|
||||
|
||||
$contact = Contact::selectFirst([], ['id' => $introduction->cid, 'uid' => $introduction->uid]);
|
||||
if (!empty($contact)) {
|
||||
if (!empty($contact['protocol'])) {
|
||||
$protocol = $contact['protocol'];
|
||||
} else {
|
||||
$protocol = $contact['network'];
|
||||
}
|
||||
|
||||
if ($protocol == Protocol::ACTIVITYPUB) {
|
||||
ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $contact['uid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue