Merge pull request #12067 from Quix0r/cleanup/type-hints-002
Cleanup: missing type-hints, double-quotes, reformatted array
This commit is contained in:
commit
0c4ebce391
6 changed files with 117 additions and 98 deletions
|
@ -141,6 +141,7 @@ class Item
|
||||||
Activity::FOLLOW,
|
Activity::FOLLOW,
|
||||||
Activity::ANNOUNCE];
|
Activity::ANNOUNCE];
|
||||||
|
|
||||||
|
// Privacy levels
|
||||||
const PUBLIC = 0;
|
const PUBLIC = 0;
|
||||||
const PRIVATE = 1;
|
const PRIVATE = 1;
|
||||||
const UNLISTED = 2;
|
const UNLISTED = 2;
|
||||||
|
|
|
@ -26,9 +26,7 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Database\DBStructure;
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Item;
|
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
|
||||||
class Post
|
class Post
|
||||||
|
|
|
@ -585,18 +585,12 @@ class Post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy values/set defaults
|
||||||
$result['total_comments_num'] = $this->isToplevel() ? $total_children : 0;
|
$result['total_comments_num'] = $this->isToplevel() ? $total_children : 0;
|
||||||
|
|
||||||
$result['private'] = $item['private'];
|
$result['private'] = $item['private'];
|
||||||
$result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
|
$result['toplevel'] = ($this->isToplevel() ? 'toplevel_item' : '');
|
||||||
|
$result['flatten'] = !$this->isThreaded();
|
||||||
if ($this->isThreaded()) {
|
$result['threaded'] = $this->isThreaded();
|
||||||
$result['flatten'] = false;
|
|
||||||
$result['threaded'] = true;
|
|
||||||
} else {
|
|
||||||
$result['flatten'] = true;
|
|
||||||
$result['threaded'] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -618,33 +612,32 @@ class Post
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a child item
|
* Add a child post
|
||||||
*
|
*
|
||||||
* @param Post $item The child item to add
|
* @param Post $item The child post to add
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Post|bool Last Post object or bool on any error
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function addChild(Post $item)
|
public function addChild(Post $item)
|
||||||
{
|
{
|
||||||
$item_id = $item->getId();
|
if (!$item->getId()) {
|
||||||
if (!$item_id) {
|
Logger::fatal('Post object has no id', ['post' => $item]);
|
||||||
Logger::info('[ERROR] Post::addChild : Item has no ID!!');
|
|
||||||
return false;
|
return false;
|
||||||
} elseif ($this->getChild($item->getId())) {
|
} elseif ($this->getChild($item->getId())) {
|
||||||
Logger::info('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').');
|
Logger::warning('Post object already exists', ['post' => $item]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity = DI::activity();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only add what will be displayed
|
* Only add what will be displayed
|
||||||
*/
|
*/
|
||||||
if ($item->getDataValue('network') === Protocol::MAIL && DI::userSession()->getLocalUserId() != $item->getDataValue('uid')) {
|
if ($item->getDataValue('network') === Protocol::MAIL && DI::userSession()->getLocalUserId() != $item->getDataValue('uid')) {
|
||||||
|
Logger::warning('Post object does not belong to local user', ['post' => $item, 'local_user' => $local_user]);
|
||||||
return false;
|
return false;
|
||||||
} elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
|
} elseif (DI::activity()->match($item->getDataValue('verb'), Activity::LIKE) ||
|
||||||
$activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
|
DI::activity()->match($item->getDataValue('verb'), Activity::DISLIKE)) {
|
||||||
|
Logger::warning('Post objects is a like/dislike', ['post' => $item]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +651,7 @@ class Post
|
||||||
* Get a child by its ID
|
* Get a child by its ID
|
||||||
*
|
*
|
||||||
* @param integer $id The child id
|
* @param integer $id The child id
|
||||||
* @return mixed
|
* @return Thread|null Thread or NULL if not found
|
||||||
*/
|
*/
|
||||||
public function getChild(int $id)
|
public function getChild(int $id)
|
||||||
{
|
{
|
||||||
|
@ -747,6 +740,7 @@ class Post
|
||||||
* Set conversation thread
|
* Set conversation thread
|
||||||
*
|
*
|
||||||
* @param Thread|null $thread
|
* @param Thread|null $thread
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setThread(Thread $thread = null)
|
public function setThread(Thread $thread = null)
|
||||||
|
@ -785,6 +779,7 @@ class Post
|
||||||
* Get a data value
|
* Get a data value
|
||||||
*
|
*
|
||||||
* @param string $name key
|
* @param string $name key
|
||||||
|
*
|
||||||
* @return mixed value on success, false on failure
|
* @return mixed value on success, false on failure
|
||||||
*/
|
*/
|
||||||
public function getDataValue(string $name)
|
public function getDataValue(string $name)
|
||||||
|
@ -798,13 +793,14 @@ class Post
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set template
|
* Set template by name
|
||||||
*
|
*
|
||||||
* @param string $name Template name
|
* @param string $name Template name
|
||||||
* @return bool If template was set
|
*
|
||||||
|
* @return void
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
private function setTemplate(string $name): bool
|
private function setTemplate(string $name)
|
||||||
{
|
{
|
||||||
if (empty($this->available_templates[$name])) {
|
if (empty($this->available_templates[$name])) {
|
||||||
// Throw exception
|
// Throw exception
|
||||||
|
@ -812,8 +808,6 @@ class Post
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->template = $this->available_templates[$name];
|
$this->template = $this->available_templates[$name];
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -939,6 +933,7 @@ class Post
|
||||||
* Get the comment box
|
* Get the comment box
|
||||||
*
|
*
|
||||||
* @param string $indent Indent value
|
* @param string $indent Indent value
|
||||||
|
*
|
||||||
* @return mixed The comment box string (empty if no comment box), false on failure
|
* @return mixed The comment box string (empty if no comment box), false on failure
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @todo return false is nowhere in this method?
|
* @todo return false is nowhere in this method?
|
||||||
|
|
|
@ -246,6 +246,8 @@ class Delivery
|
||||||
*
|
*
|
||||||
* @param string $cmd Command
|
* @param string $cmd Command
|
||||||
* @param array $item Item array
|
* @param array $item Item array
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setFailedQueue(string $cmd, array $item)
|
private static function setFailedQueue(string $cmd, array $item)
|
||||||
{
|
{
|
||||||
|
@ -268,6 +270,8 @@ class Delivery
|
||||||
* @param boolean $top_level Is it a thread starter?
|
* @param boolean $top_level Is it a thread starter?
|
||||||
* @param boolean $followup Is it an answer to a remote post?
|
* @param boolean $followup Is it an answer to a remote post?
|
||||||
* @param int|null $server_protocol The protocol of the server
|
* @param int|null $server_protocol The protocol of the server
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
|
@ -303,8 +307,8 @@ class Delivery
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
// Only add the parent when we don't delete other items.
|
// Only add the parent when we don't delete other items.
|
||||||
if (($target_item['id'] == $item['id']) || ($cmd != self::DELETION)) {
|
if (($target_item['id'] == $item['id']) || ($cmd != self::DELETION)) {
|
||||||
$item["entry:comment-allow"] = true;
|
$item['entry:comment-allow'] = true;
|
||||||
$item["entry:cid"] = ($top_level ? $contact['id'] : 0);
|
$item['entry:cid'] = ($top_level ? $contact['id'] : 0);
|
||||||
$msgitems[] = $item;
|
$msgitems[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +316,7 @@ class Delivery
|
||||||
$atom = DFRN::entries($msgitems, $owner);
|
$atom = DFRN::entries($msgitems, $owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::debug('Notifier entry: ' . $contact["url"] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom);
|
Logger::debug('Notifier entry: ' . $contact['url'] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom);
|
||||||
|
|
||||||
$protocol = Post\DeliveryData::DFRN;
|
$protocol = Post\DeliveryData::DFRN;
|
||||||
|
|
||||||
|
@ -326,7 +330,7 @@ class Delivery
|
||||||
|
|
||||||
// We never spool failed relay deliveries
|
// We never spool failed relay deliveries
|
||||||
if ($public_dfrn) {
|
if ($public_dfrn) {
|
||||||
Logger::info('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status);
|
Logger::info('Relay delivery to ' . $contact['url'] . ' with guid ' . $target_item['guid'] . ' returns ' . $deliver_status);
|
||||||
|
|
||||||
if ($cmd == Delivery::POST) {
|
if ($cmd == Delivery::POST) {
|
||||||
if (($deliver_status >= 200) && ($deliver_status <= 299)) {
|
if (($deliver_status >= 200) && ($deliver_status <= 299)) {
|
||||||
|
@ -383,6 +387,8 @@ class Delivery
|
||||||
* @param boolean $public_message Is the content public?
|
* @param boolean $public_message Is the content public?
|
||||||
* @param boolean $top_level Is it a thread starter?
|
* @param boolean $top_level Is it a thread starter?
|
||||||
* @param boolean $followup Is it an answer to a remote post?
|
* @param boolean $followup Is it an answer to a remote post?
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
|
@ -477,6 +483,7 @@ class Delivery
|
||||||
* @param array $owner Owner record of the sender
|
* @param array $owner Owner record of the sender
|
||||||
* @param array $target_item Item record of the content
|
* @param array $target_item Item record of the content
|
||||||
* @param array $thr_parent Item record of the direct parent in the thread
|
* @param array $thr_parent Item record of the direct parent in the thread
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
|
|
|
@ -173,7 +173,7 @@ class Notifier
|
||||||
$parent = $items[0];
|
$parent = $items[0];
|
||||||
|
|
||||||
$fields = ['network', 'author-id', 'author-link', 'author-network', 'owner-id'];
|
$fields = ['network', 'author-id', 'author-link', 'author-network', 'owner-id'];
|
||||||
$condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]];
|
$condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']];
|
||||||
$thr_parent = Post::selectFirst($fields, $condition);
|
$thr_parent = Post::selectFirst($fields, $condition);
|
||||||
if (empty($thr_parent)) {
|
if (empty($thr_parent)) {
|
||||||
$thr_parent = $parent;
|
$thr_parent = $parent;
|
||||||
|
@ -376,27 +376,27 @@ class Notifier
|
||||||
if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
|
if (($thr_parent && ($thr_parent['network'] == Protocol::OSTATUS)) || ($parent['network'] == Protocol::OSTATUS)) {
|
||||||
$diaspora_delivery = false;
|
$diaspora_delivery = false;
|
||||||
|
|
||||||
Logger::info('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent['author-id']." - Owner: ".$thr_parent['owner-id']);
|
Logger::info('Some parent is OStatus for ' . $target_item['guid'] . ' - Author: ' . $thr_parent['author-id'] . ' - Owner: ' . $thr_parent['owner-id']);
|
||||||
|
|
||||||
// Send a salmon to the parent author
|
// Send a salmon to the parent author
|
||||||
$probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
|
$probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
|
||||||
if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
|
if (DBA::isResult($probed_contact) && !empty($probed_contact['notify'])) {
|
||||||
Logger::notice('Notify parent author', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]);
|
Logger::notice('Notify parent author', ['url' => $probed_contact['url'], 'notify' => $probed_contact['notify']]);
|
||||||
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
|
$url_recipients[$probed_contact['notify']] = $probed_contact['notify'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a salmon to the parent owner
|
// Send a salmon to the parent owner
|
||||||
$probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
|
$probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
|
||||||
if (DBA::isResult($probed_contact) && !empty($probed_contact["notify"])) {
|
if (DBA::isResult($probed_contact) && !empty($probed_contact['notify'])) {
|
||||||
Logger::notice('Notify parent owner', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]);
|
Logger::notice('Notify parent owner', ['url' => $probed_contact['url'], 'notify' => $probed_contact['notify']]);
|
||||||
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
|
$url_recipients[$probed_contact['notify']] = $probed_contact['notify'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a salmon notification to every person we mentioned in the post
|
// Send a salmon notification to every person we mentioned in the post
|
||||||
foreach (Tag::getByURIId($target_item['uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]) as $tag) {
|
foreach (Tag::getByURIId($target_item['uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]) as $tag) {
|
||||||
$probed_contact = Contact::getByURL($tag['url']);
|
$probed_contact = Contact::getByURL($tag['url']);
|
||||||
if (!empty($probed_contact['notify'])) {
|
if (!empty($probed_contact['notify'])) {
|
||||||
Logger::notice('Notify mentioned user', ['url' => $probed_contact["url"], 'notify' => $probed_contact["notify"]]);
|
Logger::notice('Notify mentioned user', ['url' => $probed_contact['url'], 'notify' => $probed_contact['notify']]);
|
||||||
$url_recipients[$probed_contact['notify']] = $probed_contact['notify'];
|
$url_recipients[$probed_contact['notify']] = $probed_contact['notify'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,11 +497,12 @@ class Notifier
|
||||||
* @param array $contacts
|
* @param array $contacts
|
||||||
* @param array $ap_contacts
|
* @param array $ap_contacts
|
||||||
* @param array $conversants
|
* @param array $conversants
|
||||||
* @return int
|
*
|
||||||
|
* @return int Count of delivery queue
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = [])
|
private static function delivery(string $cmd, int $post_uriid, int $sender_uid, array $target_item, array $thr_parent, array $owner, bool $batch_delivery, bool $in_batch, array $contacts, array $ap_contacts, array $conversants = []): int
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
$a = DI::app();
|
||||||
$delivery_queue_count = 0;
|
$delivery_queue_count = 0;
|
||||||
|
@ -591,11 +592,12 @@ class Notifier
|
||||||
* @param array $url_recipients
|
* @param array $url_recipients
|
||||||
* @param bool $public_message
|
* @param bool $public_message
|
||||||
* @param bool $push_notify
|
* @param bool $push_notify
|
||||||
* @return int
|
*
|
||||||
|
* @return int Count of sent Salmon notifications
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private static function deliverOStatus(int $target_id, array $target_item, array $owner, array $url_recipients, bool $public_message, bool $push_notify)
|
private static function deliverOStatus(int $target_id, array $target_item, array $owner, array $url_recipients, bool $public_message, bool $push_notify): int
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
$a = DI::app();
|
||||||
$delivery_queue_count = 0;
|
$delivery_queue_count = 0;
|
||||||
|
@ -616,7 +618,7 @@ class Notifier
|
||||||
|
|
||||||
// Notify PuSH subscribers (Used for OStatus distribution of regular posts)
|
// Notify PuSH subscribers (Used for OStatus distribution of regular posts)
|
||||||
if ($push_notify) {
|
if ($push_notify) {
|
||||||
Logger::info('Activating internal PuSH', ['item' => $target_id]);
|
Logger::info('Activating internal PuSH', ['uid' => $owner['uid']]);
|
||||||
|
|
||||||
// Handling the pubsubhubbub requests
|
// Handling the pubsubhubbub requests
|
||||||
PushSubscriber::publishFeed($owner['uid'], $a->getQueueValue('priority'));
|
PushSubscriber::publishFeed($owner['uid'], $a->getQueueValue('priority'));
|
||||||
|
@ -631,9 +633,10 @@ class Notifier
|
||||||
* @param array $contact Receiver of the post
|
* @param array $contact Receiver of the post
|
||||||
* @param array $item The post
|
* @param array $item The post
|
||||||
* @param array $thr_parent The thread parent
|
* @param array $thr_parent The thread parent
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function skipActivityPubForDiaspora(array $contact, array $item, array $thr_parent)
|
private static function skipActivityPubForDiaspora(array $contact, array $item, array $thr_parent): bool
|
||||||
{
|
{
|
||||||
// No skipping needs to be done when delivery isn't done to Diaspora
|
// No skipping needs to be done when delivery isn't done to Diaspora
|
||||||
if ($contact['network'] != Protocol::DIASPORA) {
|
if ($contact['network'] != Protocol::DIASPORA) {
|
||||||
|
@ -661,11 +664,12 @@ class Notifier
|
||||||
* @param string $cmd Notifier command
|
* @param string $cmd Notifier command
|
||||||
* @param array $owner Sender of the post
|
* @param array $owner Sender of the post
|
||||||
* @param string $network Receiver network
|
* @param string $network Receiver network
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
private static function isRemovalActivity($cmd, $owner, $network)
|
private static function isRemovalActivity(string $cmd, array $owner, string $network): bool
|
||||||
{
|
{
|
||||||
return ($cmd == Delivery::DELETION) && $owner['account_removed'] && in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA]);
|
return ($cmd == Delivery::DELETION) && $owner['account_removed'] && in_array($network, [Protocol::ACTIVITYPUB, Protocol::DIASPORA]);
|
||||||
}
|
}
|
||||||
|
@ -674,11 +678,12 @@ class Notifier
|
||||||
* @param int $self_user_id
|
* @param int $self_user_id
|
||||||
* @param int $priority The priority the Notifier queue item was created with
|
* @param int $priority The priority the Notifier queue item was created with
|
||||||
* @param string $created The date the Notifier queue item was created on
|
* @param string $created The date the Notifier queue item was created on
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
private static function notifySelfRemoval($self_user_id, $priority, $created)
|
private static function notifySelfRemoval(int $self_user_id, int $priority, string $created): bool
|
||||||
{
|
{
|
||||||
$owner = User::getOwnerDataById($self_user_id);
|
$owner = User::getOwnerDataById($self_user_id);
|
||||||
if (empty($self_user_id) || empty($owner)) {
|
if (empty($self_user_id) || empty($owner)) {
|
||||||
|
@ -713,11 +718,13 @@ class Notifier
|
||||||
* @param array $thr_parent
|
* @param array $thr_parent
|
||||||
* @param int $priority The priority the Notifier queue item was created with
|
* @param int $priority The priority the Notifier queue item was created with
|
||||||
* @param string $created The date the Notifier queue item was created on
|
* @param string $created The date the Notifier queue item was created on
|
||||||
|
*
|
||||||
* @return array 'count' => The number of delivery tasks created, 'contacts' => their contact ids
|
* @return array 'count' => The number of delivery tasks created, 'contacts' => their contact ids
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
|
* @todo Unused parameter $owner
|
||||||
*/
|
*/
|
||||||
private static function activityPubDelivery($cmd, array $target_item, array $parent, array $thr_parent, $priority, $created, $owner)
|
private static function activityPubDelivery($cmd, array $target_item, array $parent, array $thr_parent, int $priority, string $created, $owner): array
|
||||||
{
|
{
|
||||||
// Don't deliver via AP when the starting post isn't from a federated network
|
// Don't deliver via AP when the starting post isn't from a federated network
|
||||||
if (!in_array($parent['network'], Protocol::FEDERATED)) {
|
if (!in_array($parent['network'], Protocol::FEDERATED)) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ class OnePoll
|
||||||
{
|
{
|
||||||
public static function execute(int $contact_id = 0, string $command = '')
|
public static function execute(int $contact_id = 0, string $command = '')
|
||||||
{
|
{
|
||||||
Logger::notice('Start polling/probing contact', ['id' => $contact_id]);
|
Logger::notice('Start polling/probing contact', ['id' => $contact_id, 'command' => $command]);
|
||||||
|
|
||||||
$force = ($command == 'force');
|
$force = ($command == 'force');
|
||||||
|
|
||||||
|
@ -119,6 +119,7 @@ class OnePoll
|
||||||
*
|
*
|
||||||
* @param array $contact The personal contact entry
|
* @param array $contact The personal contact entry
|
||||||
* @param array $fields The fields that are updated
|
* @param array $fields The fields that are updated
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
|
@ -148,7 +149,7 @@ class OnePoll
|
||||||
* @return bool Success
|
* @return bool Success
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function pollFeed(array $contact, $importer)
|
private static function pollFeed(array $contact, array $importer): bool
|
||||||
{
|
{
|
||||||
// Are we allowed to import from this person?
|
// Are we allowed to import from this person?
|
||||||
if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
|
if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
|
||||||
|
@ -187,9 +188,11 @@ class OnePoll
|
||||||
* @param array $contact The personal contact entry
|
* @param array $contact The personal contact entry
|
||||||
* @param integer $importer_uid The UID of the importer
|
* @param integer $importer_uid The UID of the importer
|
||||||
* @param string $updated The updated date
|
* @param string $updated The updated date
|
||||||
|
*
|
||||||
|
* @return bool Success
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function pollMail(array $contact, $importer_uid, $updated)
|
private static function pollMail(array $contact, int $importer_uid, string $updated): bool
|
||||||
{
|
{
|
||||||
Logger::info('Fetching mails', ['addr' => $contact['addr']]);
|
Logger::info('Fetching mails', ['addr' => $contact['addr']]);
|
||||||
|
|
||||||
|
@ -242,25 +245,25 @@ class OnePoll
|
||||||
foreach ($msgs as $msg_uid => $meta) {
|
foreach ($msgs as $msg_uid => $meta) {
|
||||||
Logger::info('Parsing mail', ['message-uid' => $msg_uid]);
|
Logger::info('Parsing mail', ['message-uid' => $msg_uid]);
|
||||||
|
|
||||||
$datarray = [];
|
$datarray = [
|
||||||
$datarray['uid'] = $importer_uid;
|
'uid' => $importer_uid,
|
||||||
$datarray['contact-id'] = $contact['id'];
|
'contact-id' => $contact['id'],
|
||||||
$datarray['verb'] = Activity::POST;
|
'verb' => Activity::POST,
|
||||||
$datarray['object-type'] = Activity\ObjectType::NOTE;
|
'object-type' => Activity\ObjectType::NOTE,
|
||||||
$datarray['network'] = Protocol::MAIL;
|
'network' => Protocol::MAIL,
|
||||||
$datarray['protocol'] = Conversation::PARCEL_IMAP;
|
'protocol' => Conversation::PARCEL_IMAP,
|
||||||
$datarray['direction'] = Conversation::PULL;
|
'direction' => Conversation::PULL,
|
||||||
|
];
|
||||||
|
$datarray['thr-parent'] = $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>'));
|
||||||
|
|
||||||
// $meta = Email::messageMeta($mbox, $msg_uid);
|
// $meta = Email::messageMeta($mbox, $msg_uid);
|
||||||
|
|
||||||
$datarray['thr-parent'] = $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>'));
|
|
||||||
|
|
||||||
// Have we seen it before?
|
// Have we seen it before?
|
||||||
$fields = ['deleted', 'id'];
|
$fields = ['deleted', 'id'];
|
||||||
$condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
|
$condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
|
||||||
$item = Post::selectFirst($fields, $condition);
|
$item = Post::selectFirst($fields, $condition);
|
||||||
if (DBA::isResult($item)) {
|
if (DBA::isResult($item)) {
|
||||||
Logger::info("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri']);
|
Logger::info('Mail: Seen before ' . $msg_uid . ' for ' . $mailconf['user'] . ' UID: ' . $importer_uid . ' URI: ' . $datarray['uri']);
|
||||||
|
|
||||||
// Only delete when mails aren't automatically moved or deleted
|
// Only delete when mails aren't automatically moved or deleted
|
||||||
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
|
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
|
||||||
|
@ -271,20 +274,23 @@ class OnePoll
|
||||||
|
|
||||||
switch ($mailconf['action']) {
|
switch ($mailconf['action']) {
|
||||||
case 0:
|
case 0:
|
||||||
Logger::info("Mail: Seen before ".$msg_uid." for ".$mailconf['user'].". Doing nothing.");
|
Logger::info('Mail: Seen before ' . $msg_uid . ' for ' . $mailconf['user'] . '. Doing nothing.');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
Logger::notice("Mail: Deleting ".$msg_uid." for ".$mailconf['user']);
|
Logger::notice('Mail: Deleting ' . $msg_uid . ' for ' . $mailconf['user']);
|
||||||
imap_delete($mbox, $msg_uid, FT_UID);
|
imap_delete($mbox, $msg_uid, FT_UID);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
Logger::notice("Mail: Mark as seen ".$msg_uid." for ".$mailconf['user']);
|
Logger::notice('Mail: Mark as seen ' . $msg_uid . ' for ' . $mailconf['user']);
|
||||||
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
Logger::notice("Mail: Moving ".$msg_uid." to ".$mailconf['movetofolder']." for ".$mailconf['user']);
|
Logger::notice('Mail: Moving ' . $msg_uid . ' to ' . $mailconf['movetofolder'] . ' for ' . $mailconf['user']);
|
||||||
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
||||||
if ($mailconf['movetofolder'] != "") {
|
if ($mailconf['movetofolder'] != '') {
|
||||||
imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
|
imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -329,12 +335,12 @@ class OnePoll
|
||||||
$datarray['created'] = DateTimeFormat::utc($meta->date);
|
$datarray['created'] = DateTimeFormat::utc($meta->date);
|
||||||
|
|
||||||
// Is it a reply?
|
// Is it a reply?
|
||||||
$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") ||
|
$reply = ((substr(strtolower($datarray['title']), 0, 3) == 're:') ||
|
||||||
(substr(strtolower($datarray['title']), 0, 3) == "re-") ||
|
(substr(strtolower($datarray['title']), 0, 3) == 're-') ||
|
||||||
($raw_refs != ""));
|
($raw_refs != ''));
|
||||||
|
|
||||||
// Remove Reply-signs in the subject
|
// Remove Reply-signs in the subject
|
||||||
$datarray['title'] = self::RemoveReply($datarray['title']);
|
$datarray['title'] = self::removeReply($datarray['title']);
|
||||||
|
|
||||||
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
||||||
if (empty($datarray['thr-parent']) && $reply) {
|
if (empty($datarray['thr-parent']) && $reply) {
|
||||||
|
@ -376,11 +382,11 @@ class OnePoll
|
||||||
}
|
}
|
||||||
|
|
||||||
$datarray['author-name'] = $fromname;
|
$datarray['author-name'] = $fromname;
|
||||||
$datarray['author-link'] = "mailto:".$frommail;
|
$datarray['author-link'] = 'mailto:' . $frommail;
|
||||||
$datarray['author-avatar'] = $contact['photo'];
|
$datarray['author-avatar'] = $contact['photo'];
|
||||||
|
|
||||||
$datarray['owner-name'] = $contact['name'];
|
$datarray['owner-name'] = $contact['name'];
|
||||||
$datarray['owner-link'] = "mailto:".$contact['addr'];
|
$datarray['owner-link'] = 'mailto:' . $contact['addr'];
|
||||||
$datarray['owner-avatar'] = $contact['photo'];
|
$datarray['owner-avatar'] = $contact['photo'];
|
||||||
|
|
||||||
if (empty($datarray['thr-parent']) || ($datarray['thr-parent'] === $datarray['uri'])) {
|
if (empty($datarray['thr-parent']) || ($datarray['thr-parent'] === $datarray['uri'])) {
|
||||||
|
@ -398,26 +404,29 @@ class OnePoll
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::notice("Mail: Importing ".$msg_uid." for ".$mailconf['user']);
|
Logger::notice('Mail: Importing ' . $msg_uid . ' for ' . $mailconf['user']);
|
||||||
|
|
||||||
Item::insert($datarray);
|
Item::insert($datarray);
|
||||||
|
|
||||||
switch ($mailconf['action']) {
|
switch ($mailconf['action']) {
|
||||||
case 0:
|
case 0:
|
||||||
Logger::info("Mail: Seen before ".$msg_uid." for ".$mailconf['user'].". Doing nothing.");
|
Logger::info('Mail: Seen before ' . $msg_uid . ' for ' . $mailconf['user'] . '. Doing nothing.');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
Logger::notice("Mail: Deleting ".$msg_uid." for ".$mailconf['user']);
|
Logger::notice('Mail: Deleting ' . $msg_uid . ' for ' . $mailconf['user']);
|
||||||
imap_delete($mbox, $msg_uid, FT_UID);
|
imap_delete($mbox, $msg_uid, FT_UID);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
Logger::notice("Mail: Mark as seen ".$msg_uid." for ".$mailconf['user']);
|
Logger::notice('Mail: Mark as seen ' . $msg_uid . ' for ' . $mailconf['user']);
|
||||||
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
Logger::notice("Mail: Moving ".$msg_uid." to ".$mailconf['movetofolder']." for ".$mailconf['user']);
|
Logger::notice('Mail: Moving ' . $msg_uid . ' to ' . $mailconf['movetofolder'] . ' for ' . $mailconf['user']);
|
||||||
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
|
||||||
if ($mailconf['movetofolder'] != "") {
|
if ($mailconf['movetofolder'] != '') {
|
||||||
imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
|
imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -435,9 +444,9 @@ class OnePoll
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function RemoveReply($subject)
|
private static function removeReply(string $subject): string
|
||||||
{
|
{
|
||||||
while (in_array(strtolower(substr($subject, 0, 3)), ["re:", "aw:"])) {
|
while (in_array(strtolower(substr($subject, 0, 3)), ['re:', 'aw:'])) {
|
||||||
$subject = trim(substr($subject, 4));
|
$subject = trim(substr($subject, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,9 +458,11 @@ class OnePoll
|
||||||
* @param array $importer
|
* @param array $importer
|
||||||
* @param array $contact
|
* @param array $contact
|
||||||
* @param string $hubmode
|
* @param string $hubmode
|
||||||
|
*
|
||||||
|
* @return bool Success
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
private static function subscribeToHub(string $url, array $importer, array $contact, string $hubmode = 'subscribe')
|
private static function subscribeToHub(string $url, array $importer, array $contact, string $hubmode = 'subscribe'): bool
|
||||||
{
|
{
|
||||||
$push_url = DI::baseUrl() . '/pubsub/' . $importer['nick'] . '/' . $contact['id'];
|
$push_url = DI::baseUrl() . '/pubsub/' . $importer['nick'] . '/' . $contact['id'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue