2 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Logger;
8 use Friendica\Core\Protocol;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Protocol\Diaspora;
12 use Friendica\Protocol\ActivityPub;
13 use Friendica\Util\DateTimeFormat;
15 class FollowConfirm extends BaseModule
17 public static function post()
23 notice(L10n::t('Permission denied.') . EOL);
27 $intro_id = intval(defaults($_POST, 'intro_id' , 0));
28 $duplex = intval(defaults($_POST, 'duplex' , 0));
29 $cid = intval(defaults($_POST, 'contact_id', 0));
30 $hidden = intval(defaults($_POST, 'hidden' , 0));
33 notice(L10n::t('No given contact.') . EOL);
37 Logger::log('Confirming follower with contact_id: ' . $cid);
39 $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'uid' => $uid]);
40 if (!DBA::isResult($contact)) {
41 Logger::log('Contact not found in DB.');
42 notice(L10n::t('Contact not found.') . EOL);
46 $relation = $contact['rel'];
47 $new_relation = $contact['rel'];
48 $writable = $contact['writable'];
50 if (!empty($contact['protocol'])) {
51 $protocol = $contact['protocol'];
53 $protocol = $contact['network'];
56 if ($protocol == Protocol::ACTIVITYPUB) {
57 ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
60 if (in_array($protocol, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
62 $new_relation = Contact::FRIEND;
64 $new_relation = Contact::FOLLOWER;
67 if ($new_relation != Contact::FOLLOWER) {
72 $fields = ['name-date' => DateTimeFormat::utcNow(),
73 'uri-date' => DateTimeFormat::utcNow(),
74 'blocked' => false, 'pending' => false, 'protocol' => $protocol,
75 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
76 DBA::update('contact', $fields, ['id' => $cid]);
78 if ($new_relation == Contact::FRIEND) {
79 if ($protocol == Protocol::DIASPORA) {
80 $user = DBA::selectFirst('user', [], ['uid' => $uid]);
81 $contact = DBA::select('contact', [], ['id' => $cid]);
82 $ret = Diaspora::sendShare($user, $contact);
83 Logger::log('share returns: ' . $ret);
84 } elseif ($protocol == Protocol::ACTIVITYPUB) {
85 ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
89 DBA::delete('intro', ['id' => $intro_id]);
91 $a->internalRedirect('contact/' . intval($cid));