mirror of
https://github.com/friendica/friendica
synced 2025-04-26 01:50:11 +00:00
Merge branch 'master' 2019.12 into develop
This commit is contained in:
commit
00756737b5
66 changed files with 70843 additions and 67948 deletions
|
@ -84,7 +84,7 @@ class APContact extends BaseObject
|
|||
public static function getByURL($url, $update = null)
|
||||
{
|
||||
if (empty($url)) {
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
|
||||
$fetched_contact = false;
|
||||
|
@ -110,7 +110,7 @@ class APContact extends BaseObject
|
|||
}
|
||||
|
||||
if (!is_null($update)) {
|
||||
return DBA::isResult($apcontact) ? $apcontact : false;
|
||||
return DBA::isResult($apcontact) ? $apcontact : [];
|
||||
}
|
||||
|
||||
if (DBA::isResult($apcontact)) {
|
||||
|
@ -203,6 +203,33 @@ class APContact extends BaseObject
|
|||
$apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
|
||||
}
|
||||
|
||||
if (!empty($apcontact['following'])) {
|
||||
$data = ActivityPub::fetchContent($apcontact['following']);
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['totalItems'])) {
|
||||
$apcontact['following_count'] = $data['totalItems'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($apcontact['followers'])) {
|
||||
$data = ActivityPub::fetchContent($apcontact['followers']);
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['totalItems'])) {
|
||||
$apcontact['followers_count'] = $data['totalItems'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($apcontact['outbox'])) {
|
||||
$data = ActivityPub::fetchContent($apcontact['outbox']);
|
||||
if (!empty($data)) {
|
||||
if (!empty($data['totalItems'])) {
|
||||
$apcontact['statuses_count'] = $data['totalItems'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To-Do
|
||||
|
||||
// Unhandled
|
||||
|
|
|
@ -1230,7 +1230,7 @@ class Contact extends BaseObject
|
|||
|
||||
$follow_link = '';
|
||||
$unfollow_link = '';
|
||||
if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
|
||||
if (!$contact['self'] && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
|
||||
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
|
||||
$unfollow_link = 'unfollow?url=' . urlencode($contact['url']);
|
||||
} elseif(!$contact['pending']) {
|
||||
|
|
|
@ -876,7 +876,11 @@ class GContact
|
|||
self::updateFromOutbox($outbox['first']['href'], $data);
|
||||
return;
|
||||
} elseif (!empty($outbox['first'])) {
|
||||
self::updateFromOutbox($outbox['first'], $data);
|
||||
if (is_string($outbox['first'])) {
|
||||
self::updateFromOutbox($outbox['first'], $data);
|
||||
} else {
|
||||
Logger::warning('Unexpected data', ['outbox' => $outbox]);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
$items = [];
|
||||
|
|
|
@ -549,7 +549,7 @@ class GServer
|
|||
$protocols[$protocol] = true;
|
||||
}
|
||||
|
||||
if (!empty($protocols['friendica'])) {
|
||||
if (!empty($protocols['dfrn'])) {
|
||||
$server['network'] = Protocol::DFRN;
|
||||
} elseif (!empty($protocols['activitypub'])) {
|
||||
$server['network'] = Protocol::ACTIVITYPUB;
|
||||
|
|
156
src/Model/Introduction.php
Normal file
156
src/Model/Introduction.php
Normal file
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\BaseModel;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @property int uid
|
||||
* @property int fid
|
||||
* @property int contact-id
|
||||
* @property bool knowyou
|
||||
* @property bool duplex
|
||||
* @property string note
|
||||
* @property string hash
|
||||
* @property string datetime
|
||||
* @property bool blocked
|
||||
* @property bool ignored
|
||||
*
|
||||
* @package Friendica\Model
|
||||
*/
|
||||
final class Introduction extends BaseModel
|
||||
{
|
||||
static $table_name = 'intro';
|
||||
|
||||
/**
|
||||
* Confirms a follow request and sends a notic to the remote contact.
|
||||
*
|
||||
* @param bool $duplex Is it a follow back?
|
||||
* @param bool|null $hidden Should this contact be hidden? null = no change
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
* @throws HTTPException\NotFoundException
|
||||
*/
|
||||
public function confirm(bool $duplex = false, bool $hidden = null)
|
||||
{
|
||||
$this->logger->info('Confirming follower', ['cid' => $this->{'contact-id'}]);
|
||||
|
||||
$contact = Contact::selectFirst([], ['id' => $this->{'contact-id'}, 'uid' => $this->uid]);
|
||||
|
||||
if (!$contact) {
|
||||
throw new HTTPException\NotFoundException('Contact record not found.');
|
||||
}
|
||||
|
||||
$new_relation = $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 ($duplex) {
|
||||
$new_relation = Contact::FRIEND;
|
||||
} else {
|
||||
$new_relation = Contact::FOLLOWER;
|
||||
}
|
||||
|
||||
if ($new_relation != 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' => $new_relation,
|
||||
];
|
||||
$this->dba->update('contact', $fields, ['id' => $contact['id']]);
|
||||
|
||||
array_merge($contact, $fields);
|
||||
|
||||
if ($new_relation == Contact::FRIEND) {
|
||||
if ($protocol == Protocol::DIASPORA) {
|
||||
$ret = Diaspora::sendShare(User::getById($contact['uid']), $contact);
|
||||
$this->logger->info('share returns', ['return' => $ret]);
|
||||
} elseif ($protocol == Protocol::ACTIVITYPUB) {
|
||||
ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $contact['uid']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Silently ignores the introduction, hides it from notifications and prevents the remote contact from submitting
|
||||
* additional follow requests.
|
||||
*
|
||||
* Chainable
|
||||
*
|
||||
* @return Introduction
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function ignore()
|
||||
{
|
||||
$this->dba->update('intro', ['ignore' => true], ['id' => $this->id]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards the introduction and sends a rejection message to AP contacts.
|
||||
*
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function discard()
|
||||
{
|
||||
// If it is a friend suggestion, the contact is not a new friend but an existing friend
|
||||
// that should not be deleted.
|
||||
if (!$this->fid) {
|
||||
// When the contact entry had been created just for that intro, we want to get rid of it now
|
||||
$condition = ['id' => $this->{'contact-id'}, 'uid' => $this->uid,
|
||||
'self' => false, 'pending' => true, 'rel' => [0, Contact::FOLLOWER]];
|
||||
if ($this->dba->exists('contact', $condition)) {
|
||||
Contact::remove($this->{'contact-id'});
|
||||
} else {
|
||||
$this->dba->update('contact', ['pending' => false], ['id' => $this->{'contact-id'}]);
|
||||
}
|
||||
}
|
||||
|
||||
$contact = Contact::selectFirst([], ['id' => $this->{'contact-id'}, 'uid' => $this->uid]);
|
||||
|
||||
if (!$contact) {
|
||||
throw new HTTPException\NotFoundException('Contact record not found.');
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
}
|
|
@ -2621,7 +2621,7 @@ class Item extends BaseObject
|
|||
"#$2", $item["body"]);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=') || $tag[1] == '#') {
|
||||
if ((strpos($tag, '#') !== 0) || strpos($tag, '[url=') || strlen($tag) < 2 || $tag[1] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue