Revert "Replace Module::init() with Constructors"

This commit is contained in:
Hypolite Petovan 2021-11-19 07:23:23 -05:00 committed by GitHub
parent 0b6e0566d7
commit 89d6c89b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 921 additions and 1225 deletions

View file

@ -21,17 +21,14 @@
namespace Friendica\Module\Notifications;
use Friendica\App\Arguments;
use Friendica\App\Mode;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Text\BBCode;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Module\BaseNotifications;
use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
use Friendica\Navigation\Notifications\ValueObject\Introduction;
/**
@ -39,34 +36,21 @@ use Friendica\Navigation\Notifications\ValueObject\Introduction;
*/
class Introductions extends BaseNotifications
{
/** @var IntroductionFactory */
protected $notificationIntro;
/** @var Mode */
protected $mode;
public function __construct(Mode $mode, IntroductionFactory $notificationIntro, Arguments $args, L10n $l10n, array $parameters = [])
{
parent::__construct($args, $l10n, $parameters);
$this->notificationIntro = $notificationIntro;
$this->mode = $mode;
}
/**
* @inheritDoc
*/
public function getNotifications()
public static function getNotifications()
{
$id = (int)$this->args->get(2, 0);
$all = $this->args->get(2) == 'all';
$id = (int)DI::args()->get(2, 0);
$all = DI::args()->get(2) == 'all';
$notifications = [
'ident' => 'introductions',
'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id),
'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
];
return [
'header' => $this->t('Notifications'),
'header' => DI::l10n()->t('Notifications'),
'notifications' => $notifications,
];
}
@ -75,12 +59,12 @@ class Introductions extends BaseNotifications
{
Nav::setSelected('introductions');
$all = $this->args->get(2) == 'all';
$all = DI::args()->get(2) == 'all';
$notificationContent = [];
$notificationNoContent = '';
$notificationResult = $this->getNotifications();
$notificationResult = self::getNotifications();
$notifications = $notificationResult['notifications'] ?? [];
$notificationHeader = $notificationResult['header'] ?? '';
@ -90,7 +74,7 @@ class Introductions extends BaseNotifications
// The link to switch between ignored and normal connection requests
$notificationShowLink = [
'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')),
'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')),
];
$owner = User::getOwnerDataById(local_user());
@ -106,10 +90,10 @@ class Introductions extends BaseNotifications
case 'friend_suggestion':
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
'$type' => $Introduction->getLabel(),
'$str_notification_type' => $this->t('Notification type:'),
'$str_notification_type' => DI::l10n()->t('Notification type:'),
'$str_type' => $Introduction->getType(),
'$intro_id' => $Introduction->getIntroId(),
'$lbl_madeby' => $this->t('Suggested by:'),
'$lbl_madeby' => DI::l10n()->t('Suggested by:'),
'$madeby' => $Introduction->getMadeBy(),
'$madeby_url' => $Introduction->getMadeByUrl(),
'$madeby_zrl' => $Introduction->getMadeByZrl(),
@ -120,22 +104,22 @@ class Introductions extends BaseNotifications
'$dfrn_url' => $owner['url'],
'$url' => $Introduction->getUrl(),
'$zrl' => $Introduction->getZrl(),
'$lbl_url' => $this->t('Profile URL'),
'$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $Introduction->getAddr(),
'$action' => 'follow',
'$approve' => $this->t('Approve'),
'$approve' => DI::l10n()->t('Approve'),
'$note' => $Introduction->getNote(),
'$ignore' => $this->t('Ignore'),
'$discard' => $this->t('Discard'),
'$is_mobile' => $this->mode->isMobile(),
'$ignore' => DI::l10n()->t('Ignore'),
'$discard' => DI::l10n()->t('Discard'),
'$is_mobile' => DI::mode()->isMobile(),
]);
break;
// Normal connection requests
default:
if ($Introduction->getNetwork() === Protocol::DFRN) {
$lbl_knowyou = $this->t('Claims to be known to you: ');
$knowyou = ($Introduction->getKnowYou() ? $this->t('Yes') : $this->t('No'));
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
$knowyou = ($Introduction->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
} else {
$lbl_knowyou = '';
$knowyou = '';
@ -143,12 +127,12 @@ class Introductions extends BaseNotifications
$convertedName = BBCode::convert($Introduction->getName());
$helptext = $this->t('Shall your connection be bidirectional or not?');
$helptext2 = $this->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);
$helptext3 = $this->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName);
$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);
$helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName);
$friend = ['duplex', $this->t('Friend'), '1', $helptext2, true];
$follower = ['duplex', $this->t('Subscriber'), '0', $helptext3, false];
$friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true];
$follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false];
$action = 'follow_confirm';
@ -161,7 +145,7 @@ class Introductions extends BaseNotifications
$header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
if ($Introduction->getNetwork() != Protocol::DIASPORA) {
$discard = $this->t('Discard');
$discard = DI::l10n()->t('Discard');
} else {
$discard = '';
}
@ -169,7 +153,7 @@ class Introductions extends BaseNotifications
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$type' => $Introduction->getLabel(),
'$header' => $header,
'$str_notification_type' => $this->t('Notification type:'),
'$str_notification_type' => DI::l10n()->t('Notification type:'),
'$str_type' => $Introduction->getType(),
'$dfrn_id' => $Introduction->getDfrnId(),
'$uid' => $Introduction->getUid(),
@ -178,39 +162,39 @@ class Introductions extends BaseNotifications
'$photo' => $Introduction->getPhoto(),
'$fullname' => $Introduction->getName(),
'$location' => $Introduction->getLocation(),
'$lbl_location' => $this->t('Location:'),
'$lbl_location' => DI::l10n()->t('Location:'),
'$about' => $Introduction->getAbout(),
'$lbl_about' => $this->t('About:'),
'$lbl_about' => DI::l10n()->t('About:'),
'$keywords' => $Introduction->getKeywords(),
'$lbl_keywords' => $this->t('Tags:'),
'$hidden' => ['hidden', $this->t('Hide this contact from others'), $Introduction->isHidden(), ''],
'$lbl_keywords' => DI::l10n()->t('Tags:'),
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $Introduction->isHidden(), ''],
'$lbl_connection_type' => $helptext,
'$friend' => $friend,
'$follower' => $follower,
'$url' => $Introduction->getUrl(),
'$zrl' => $Introduction->getZrl(),
'$lbl_url' => $this->t('Profile URL'),
'$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $Introduction->getAddr(),
'$lbl_knowyou' => $lbl_knowyou,
'$lbl_network' => $this->t('Network:'),
'$lbl_network' => DI::l10n()->t('Network:'),
'$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
'$knowyou' => $knowyou,
'$approve' => $this->t('Approve'),
'$approve' => DI::l10n()->t('Approve'),
'$note' => $Introduction->getNote(),
'$ignore' => $this->t('Ignore'),
'$ignore' => DI::l10n()->t('Ignore'),
'$discard' => $discard,
'$action' => $action,
'$is_mobile' => $this->mode->isMobile(),
'$is_mobile' => DI::mode()->isMobile(),
]);
break;
}
}
if (count($notifications['notifications']) == 0) {
notice($this->t('No introductions.'));
$notificationNoContent = $this->t('No more %s notifications.', $notifications['ident']);
notice(DI::l10n()->t('No introductions.'));
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
}
return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
}
}

View file

@ -21,13 +21,13 @@
namespace Friendica\Module\Notifications;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseNotifications;
use Friendica\Navigation\Notifications\Collection\FormattedNotifications;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Prints all notification types except introduction:
@ -38,56 +38,42 @@ use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
*/
class Notifications extends BaseNotifications
{
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
protected $formattedNotificationFactory;
/** @var BaseURL */
protected $baseUrl;
public function __construct(BaseURL $baseUrl, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, Arguments $args, L10n $l10n, array $parameters = [])
{
parent::__construct($args, $l10n, $parameters);
$this->formattedNotificationFactory = $formattedNotificationFactory;
$this->baseUrl = $baseUrl;
}
/**
* {@inheritDoc}
*/
public function getNotifications()
public static function getNotifications()
{
$notificationHeader = '';
$notifications = [];
$factory = $this->formattedNotificationFactory;
$factory = DI::formattedNotificationFactory();
if (($this->args->get(1) == 'network')) {
$notificationHeader = $this->t('Network Notifications');
if ((DI::args()->get(1) == 'network')) {
$notificationHeader = DI::l10n()->t('Network Notifications');
$notifications = [
'ident' => FormattedNotification::NETWORK,
'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
} elseif (($this->args->get(1) == 'system')) {
$notificationHeader = $this->t('System Notifications');
} elseif ((DI::args()->get(1) == 'system')) {
$notificationHeader = DI::l10n()->t('System Notifications');
$notifications = [
'ident' => FormattedNotification::SYSTEM,
'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
} elseif (($this->args->get(1) == 'personal')) {
$notificationHeader = $this->t('Personal Notifications');
} elseif ((DI::args()->get(1) == 'personal')) {
$notificationHeader = DI::l10n()->t('Personal Notifications');
$notifications = [
'ident' => FormattedNotification::PERSONAL,
'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
} elseif (($this->args->get(1) == 'home')) {
$notificationHeader = $this->t('Home Notifications');
} elseif ((DI::args()->get(1) == 'home')) {
$notificationHeader = DI::l10n()->t('Home Notifications');
$notifications = [
'ident' => FormattedNotification::HOME,
'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
} else {
$this->baseUrl->redirect('notifications');
DI::baseUrl()->redirect('notifications');
}
return [
@ -103,7 +89,7 @@ class Notifications extends BaseNotifications
$notificationContent = [];
$notificationNoContent = '';
$notificationResult = $this->getNotifications();
$notificationResult = self::getNotifications();
$notifications = $notificationResult['notifications'] ?? [];
$notificationHeader = $notificationResult['header'] ?? '';
@ -132,14 +118,14 @@ class Notifications extends BaseNotifications
]);
}
} else {
$notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']);
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']);
}
$notificationShowLink = [
'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')),
'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
];
return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
}
}