return self::$dice->create(Factory\Api\Twitter\User::class);
}
- /**
- * @return Factory\Notification\Introduction
- */
- public static function notificationIntro()
+ public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
{
- return self::$dice->create(Factory\Notification\Introduction::class);
+ return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
}
//
+++ /dev/null
-<?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\Factory\Notification;
-
-use Exception;
-use Friendica\App;
-use Friendica\App\BaseURL;
-use Friendica\BaseFactory;
-use Friendica\Content\Text\BBCode;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig\IPConfig;
-use Friendica\Core\Protocol;
-use Friendica\Core\Session\ISession;
-use Friendica\Database\Database;
-use Friendica\Model\Contact;
-use Friendica\Module\BaseNotifications;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Object\Notification;
-use Friendica\Util\Proxy;
-use Psr\Log\LoggerInterface;
-
-/**
- * Factory for creating notification objects based on introductions
- * Currently, there are two main types of introduction based notifications:
- * - Friend suggestion
- * - Friend/Follower request
- */
-class Introduction extends BaseFactory
-{
- /** @var Database */
- private $dba;
- /** @var BaseURL */
- private $baseUrl;
- /** @var L10n */
- private $l10n;
- /** @var IPConfig */
- private $pConfig;
- /** @var ISession */
- private $session;
- /** @var string */
- private $nick;
-
- public function __construct(LoggerInterface $logger, Database $dba, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
- {
- parent::__construct($logger);
-
- $this->dba = $dba;
- $this->baseUrl = $baseUrl;
- $this->l10n = $l10n;
- $this->pConfig = $pConfig;
- $this->session = $session;
- $this->nick = $app->getLoggedInUserNickname() ?? '';
- }
-
- /**
- * Get introductions
- *
- * @param bool $all If false only include introductions into the query
- * which aren't marked as ignored
- * @param int $start Start the query at this point
- * @param int $limit Maximum number of query results
- * @param int $id When set, only the introduction with this id is displayed
- *
- * @return Notification\Introduction[]
- */
- public function getList(bool $all = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT, int $id = 0)
- {
- $sql_extra = "";
-
- if (empty($id)) {
- if (!$all) {
- $sql_extra = " AND NOT `ignore` ";
- }
-
- $sql_extra .= " AND NOT `intro`.`blocked` ";
- } else {
- $sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
- }
-
- $formattedNotifications = [];
-
- 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`
- FROM `intro`
- LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
- LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
- WHERE `intro`.`uid` = ? $sql_extra
- LIMIT ?, ?",
- $_SESSION['uid'],
- $start,
- $limit
- );
-
- while ($notification = $this->dba->fetch($stmtNotifications)) {
- if (empty($notification['url'])) {
- continue;
- }
-
- // 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 ($notification['fid'] ?? '') {
- if (empty($notification['furl'])) {
- continue;
- }
- $return_addr = bin2hex($this->nick . '@' .
- $this->baseUrl->getHostName() .
- (($this->baseUrl->getURLPath()) ? '/' . $this->baseUrl->getURLPath() : ''));
-
- $formattedNotifications[] = new Notification\Introduction([
- 'label' => 'friend_suggestion',
- 'str_type' => $this->l10n->t('Friend Suggestion'),
- 'intro_id' => $notification['intro_id'],
- 'madeby' => $notification['name'],
- 'madeby_url' => $notification['url'],
- 'madeby_zrl' => Contact::magicLink($notification['url']),
- 'madeby_addr' => $notification['addr'],
- 'contact_id' => $notification['contact-id'],
- 'photo' => Contact::getAvatarUrlForUrl($notification['furl'], 0, Proxy::SIZE_SMALL),
- 'name' => $notification['fname'],
- 'url' => $notification['furl'],
- 'zrl' => Contact::magicLink($notification['furl']),
- 'hidden' => $notification['hidden'] == 1,
- 'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
- 'note' => $notification['note'],
- 'request' => $notification['frequest'] . '?addr=' . $return_addr]);
-
- // Normal connection requests
- } else {
- // Don't show these data until you are connected. Diaspora is doing the same.
- if ($notification['network'] === Protocol::DIASPORA) {
- $notification['location'] = "";
- $notification['about'] = "";
- }
-
- $formattedNotifications[] = new Notification\Introduction([
- 'label' => (($notification['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
- 'str_type' => (($notification['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
- 'dfrn_id' => $notification['issued-id'],
- 'uid' => $this->session->get('uid'),
- 'intro_id' => $notification['intro_id'],
- 'contact_id' => $notification['contact-id'],
- 'photo' => Contact::getPhoto($notification),
- 'name' => $notification['name'],
- 'location' => BBCode::convert($notification['location'], false),
- 'about' => BBCode::convert($notification['about'], false),
- 'keywords' => $notification['keywords'],
- 'hidden' => $notification['hidden'] == 1,
- 'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
- 'url' => $notification['url'],
- 'zrl' => Contact::magicLink($notification['url']),
- 'addr' => $notification['addr'],
- 'network' => $notification['network'],
- 'knowyou' => $notification['knowyou'],
- 'note' => $notification['note'],
- ]);
- }
- }
- } catch (Exception $e) {
- $this->logger->warning('Select failed.', ['uid' => $_SESSION['uid'], 'exception' => $e]);
- }
-
- return $formattedNotifications;
- }
-}
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Module\BaseNotifications;
-use Friendica\Object\Notification\Introduction;
+use Friendica\Navigation\Notifications\ValueObject\Introduction;
/**
* Prints notifications about introduction
// Loop through all introduction notifications.This creates an array with the output html for each
// introduction
- /** @var Introduction $notification */
- foreach ($notifications['notifications'] as $notification) {
+ /** @var Introduction $Introduction */
+ foreach ($notifications['notifications'] as $Introduction) {
// 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.
- switch ($notification->getLabel()) {
+ switch ($Introduction->getLabel()) {
case 'friend_suggestion':
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
- '$type' => $notification->getLabel(),
+ '$type' => $Introduction->getLabel(),
'$str_notification_type' => DI::l10n()->t('Notification type:'),
- '$str_type' => $notification->getType(),
- '$intro_id' => $notification->getIntroId(),
+ '$str_type' => $Introduction->getType(),
+ '$intro_id' => $Introduction->getIntroId(),
'$lbl_madeby' => DI::l10n()->t('Suggested by:'),
- '$madeby' => $notification->getMadeBy(),
- '$madeby_url' => $notification->getMadeByUrl(),
- '$madeby_zrl' => $notification->getMadeByZrl(),
- '$madeby_addr' => $notification->getMadeByAddr(),
- '$contact_id' => $notification->getContactId(),
- '$photo' => $notification->getPhoto(),
- '$fullname' => $notification->getName(),
+ '$madeby' => $Introduction->getMadeBy(),
+ '$madeby_url' => $Introduction->getMadeByUrl(),
+ '$madeby_zrl' => $Introduction->getMadeByZrl(),
+ '$madeby_addr' => $Introduction->getMadeByAddr(),
+ '$contact_id' => $Introduction->getContactId(),
+ '$photo' => $Introduction->getPhoto(),
+ '$fullname' => $Introduction->getName(),
'$dfrn_url' => $owner['url'],
- '$url' => $notification->getUrl(),
- '$zrl' => $notification->getZrl(),
+ '$url' => $Introduction->getUrl(),
+ '$zrl' => $Introduction->getZrl(),
'$lbl_url' => DI::l10n()->t('Profile URL'),
- '$addr' => $notification->getAddr(),
+ '$addr' => $Introduction->getAddr(),
'$action' => 'follow',
'$approve' => DI::l10n()->t('Approve'),
- '$note' => $notification->getNote(),
+ '$note' => $Introduction->getNote(),
'$ignore' => DI::l10n()->t('Ignore'),
'$discard' => DI::l10n()->t('Discard'),
'$is_mobile' => DI::mode()->isMobile(),
// Normal connection requests
default:
- if ($notification->getNetwork() === Protocol::DFRN) {
+ if ($Introduction->getNetwork() === Protocol::DFRN) {
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
- $knowyou = ($notification->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
+ $knowyou = ($Introduction->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
} else {
$lbl_knowyou = '';
$knowyou = '';
}
- $convertedName = BBCode::convert($notification->getName());
+ $convertedName = BBCode::convert($Introduction->getName());
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
$action = 'follow_confirm';
- $header = $notification->getName();
+ $header = $Introduction->getName();
- if ($notification->getAddr() != '') {
- $header .= ' <' . $notification->getAddr() . '>';
+ if ($Introduction->getAddr() != '') {
+ $header .= ' <' . $Introduction->getAddr() . '>';
}
- $header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
+ $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
- if ($notification->getNetwork() != Protocol::DIASPORA) {
+ if ($Introduction->getNetwork() != Protocol::DIASPORA) {
$discard = DI::l10n()->t('Discard');
} else {
$discard = '';
}
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
- '$type' => $notification->getLabel(),
+ '$type' => $Introduction->getLabel(),
'$header' => $header,
'$str_notification_type' => DI::l10n()->t('Notification type:'),
- '$str_type' => $notification->getType(),
- '$dfrn_id' => $notification->getDfrnId(),
- '$uid' => $notification->getUid(),
- '$intro_id' => $notification->getIntroId(),
- '$contact_id' => $notification->getContactId(),
- '$photo' => $notification->getPhoto(),
- '$fullname' => $notification->getName(),
- '$location' => $notification->getLocation(),
+ '$str_type' => $Introduction->getType(),
+ '$dfrn_id' => $Introduction->getDfrnId(),
+ '$uid' => $Introduction->getUid(),
+ '$intro_id' => $Introduction->getIntroId(),
+ '$contact_id' => $Introduction->getContactId(),
+ '$photo' => $Introduction->getPhoto(),
+ '$fullname' => $Introduction->getName(),
+ '$location' => $Introduction->getLocation(),
'$lbl_location' => DI::l10n()->t('Location:'),
- '$about' => $notification->getAbout(),
+ '$about' => $Introduction->getAbout(),
'$lbl_about' => DI::l10n()->t('About:'),
- '$keywords' => $notification->getKeywords(),
+ '$keywords' => $Introduction->getKeywords(),
'$lbl_keywords' => DI::l10n()->t('Tags:'),
- '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
+ '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $Introduction->isHidden(), ''],
'$lbl_connection_type' => $helptext,
'$friend' => $friend,
'$follower' => $follower,
- '$url' => $notification->getUrl(),
- '$zrl' => $notification->getZrl(),
+ '$url' => $Introduction->getUrl(),
+ '$zrl' => $Introduction->getZrl(),
'$lbl_url' => DI::l10n()->t('Profile URL'),
- '$addr' => $notification->getAddr(),
+ '$addr' => $Introduction->getAddr(),
'$lbl_knowyou' => $lbl_knowyou,
'$lbl_network' => DI::l10n()->t('Network:'),
- '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
+ '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
'$knowyou' => $knowyou,
'$approve' => DI::l10n()->t('Approve'),
- '$note' => $notification->getNote(),
+ '$note' => $Introduction->getNote(),
'$ignore' => DI::l10n()->t('Ignore'),
'$discard' => $discard,
'$action' => $action,
+++ /dev/null
-<?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\Object\Notification;
-
-/**
- * A view-only object for printing introduction notifications to the frontend
- */
-class Introduction implements \JsonSerializable
-{
- /** @var string */
- private $label = '';
- /** @var string */
- private $type = '';
- /** @var integer */
- private $intro_id = -1;
- /** @var string */
- private $madeBy = '';
- /** @var string */
- private $madeByUrl = '';
- /** @var string */
- private $madeByZrl = '';
- /** @var string */
- private $madeByAddr = '';
- /** @var integer */
- private $contactId = -1;
- /** @var string */
- private $photo = '';
- /** @var string */
- private $name = '';
- /** @var string */
- private $url = '';
- /** @var string */
- private $zrl = '';
- /** @var boolean */
- private $hidden = false;
- /** @var integer */
- private $postNewFriend = -1;
- /** @var boolean */
- private $knowYou = false;
- /** @var string */
- private $note = '';
- /** @var string */
- private $request = '';
- /** @var int */
- private $dfrnId = -1;
- /** @var string */
- private $addr = '';
- /** @var string */
- private $network = '';
- /** @var int */
- private $uid = -1;
- /** @var string */
- private $keywords = '';
- /** @var string */
- private $location = '';
- /** @var string */
- private $about = '';
-
- /**
- * @return string
- */
- public function getLabel()
- {
- return $this->label;
- }
-
- /**
- * @return string
- */
- public function getType()
- {
- return $this->type;
- }
-
- /**
- * @return int
- */
- public function getIntroId()
- {
- return $this->intro_id;
- }
-
- /**
- * @return string
- */
- public function getMadeBy()
- {
- return $this->madeBy;
- }
-
- /**
- * @return string
- */
- public function getMadeByUrl()
- {
- return $this->madeByUrl;
- }
-
- /**
- * @return string
- */
- public function getMadeByZrl()
- {
- return $this->madeByZrl;
- }
-
- /**
- * @return string
- */
- public function getMadeByAddr()
- {
- return $this->madeByAddr;
- }
-
- /**
- * @return int
- */
- public function getContactId()
- {
- return $this->contactId;
- }
-
- /**
- * @return string
- */
- public function getPhoto()
- {
- return $this->photo;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * @return string
- */
- public function getUrl()
- {
- return $this->url;
- }
-
- /**
- * @return string
- */
- public function getZrl()
- {
- return $this->zrl;
- }
-
- /**
- * @return bool
- */
- public function isHidden()
- {
- return $this->hidden;
- }
-
- /**
- * @return int
- */
- public function getPostNewFriend()
- {
- return $this->postNewFriend;
- }
-
- /**
- * @return string
- */
- public function getKnowYou()
- {
- return $this->knowYou;
- }
-
- /**
- * @return string
- */
- public function getNote()
- {
- return $this->note;
- }
-
- /**
- * @return string
- */
- public function getRequest()
- {
- return $this->request;
- }
-
- /**
- * @return string
- */
- public function getDfrnId()
- {
- return $this->dfrnId;
- }
-
- /**
- * @return string
- */
- public function getAddr()
- {
- return $this->addr;
- }
-
- /**
- * @return string
- */
- public function getNetwork()
- {
- return $this->network;
- }
-
- /**
- * @return int
- */
- public function getUid()
- {
- return $this->uid;
- }
-
- /**
- * @return string
- */
- public function getKeywords()
- {
- return $this->keywords;
- }
-
- /**
- * @return string
- */
- public function getLocation()
- {
- return $this->location;
- }
-
- /**
- * @return string
- */
- public function getAbout()
- {
- return $this->about;
- }
-
- public function __construct(array $data = [])
- {
- $this->label = $data['label'] ?? '';
- $this->type = $data['str_type'] ?? '';
- $this->intro_id = $data['intro_id'] ?? -1;
- $this->madeBy = $data['madeBy'] ?? '';
- $this->madeByUrl = $data['madeByUrl'] ?? '';
- $this->madeByZrl = $data['madeByZrl'] ?? '';
- $this->madeByAddr = $data['madeByAddr'] ?? '';
- $this->contactId = $data['contactId'] ?? '';
- $this->photo = $data['photo'] ?? '';
- $this->name = $data['name'] ?? '';
- $this->url = $data['url'] ?? '';
- $this->zrl = $data['zrl'] ?? '';
- $this->hidden = $data['hidden'] ?? false;
- $this->postNewFriend = $data['postNewFriend'] ?? '';
- $this->knowYou = $data['knowYou'] ?? false;
- $this->note = $data['note'] ?? '';
- $this->request = $data['request'] ?? '';
- $this->dfrnId = -1;
- $this->addr = $data['addr'] ?? '';
- $this->network = $data['network'] ?? '';
- $this->uid = $data['uid'] ?? -1;
- $this->keywords = $data['keywords'] ?? '';
- $this->location = $data['location'] ?? '';
- $this->about = $data['about'] ?? '';
- }
-
- /**
- * @inheritDoc
- */
- public function jsonSerialize()
- {
- return $this->toArray();
- }
-
- /**
- * @return array
- */
- public function toArray()
- {
- return get_object_vars($this);
- }
-}