mirror of
https://github.com/friendica/friendica
synced 2025-04-26 09:50:15 +00:00
UserSession class [5] - Refactor src/Module/ files with DI
This commit is contained in:
parent
a729f3255d
commit
eecc456e0c
78 changed files with 455 additions and 530 deletions
|
@ -30,7 +30,6 @@ use Friendica\Content\Text\BBCode;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseNotifications;
|
||||
|
@ -99,7 +98,7 @@ class Introductions extends BaseNotifications
|
|||
'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')),
|
||||
];
|
||||
|
||||
$owner = User::getOwnerDataById(Session::getLocalUser());
|
||||
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
|
||||
|
||||
// Loop through all introduction notifications.This creates an array with the output html for each
|
||||
// introduction
|
||||
|
|
|
@ -26,7 +26,6 @@ use Friendica\BaseModule;
|
|||
use Friendica\Contact\Introduction\Repository\Introduction;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
|
@ -73,14 +72,14 @@ class Notification extends BaseModule
|
|||
*/
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$request_id = $this->parameters['id'] ?? false;
|
||||
|
||||
if ($request_id) {
|
||||
$intro = $this->introductionRepo->selectOneById($request_id, Session::getLocalUser());
|
||||
$intro = $this->introductionRepo->selectOneById($request_id, DI::userSession()->getLocalUserId());
|
||||
|
||||
switch ($_POST['submit']) {
|
||||
case $this->l10n->t('Discard'):
|
||||
|
@ -104,14 +103,14 @@ class Notification extends BaseModule
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
|
||||
}
|
||||
|
||||
if ($this->args->get(1) === 'mark' && $this->args->get(2) === 'all') {
|
||||
try {
|
||||
$this->notificationRepo->setAllSeenForUser(Session::getLocalUser());
|
||||
$success = $this->notifyRepo->setAllSeenForUser(Session::getLocalUser());
|
||||
$this->notificationRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
|
||||
$success = $this->notifyRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning('set all seen failed.', ['exception' => $e]);
|
||||
$success = false;
|
||||
|
@ -132,7 +131,7 @@ class Notification extends BaseModule
|
|||
*/
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
DI::sysmsg()->addNotice($this->l10n->t('You must be logged in to show this page.'));
|
||||
return Login::form();
|
||||
}
|
||||
|
@ -151,11 +150,11 @@ class Notification extends BaseModule
|
|||
private function handleNotify(int $notifyId)
|
||||
{
|
||||
$Notify = $this->notifyRepo->selectOneById($notifyId);
|
||||
if ($Notify->uid !== Session::getLocalUser()) {
|
||||
if ($Notify->uid !== DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\ForbiddenException();
|
||||
}
|
||||
|
||||
if ($this->pconfig->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
|
||||
if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
|
||||
$Notify->setSeen();
|
||||
$this->notifyRepo->save($Notify);
|
||||
} else {
|
||||
|
@ -176,11 +175,11 @@ class Notification extends BaseModule
|
|||
private function handleNotification(int $notificationId)
|
||||
{
|
||||
$Notification = $this->notificationRepo->selectOneById($notificationId);
|
||||
if ($Notification->uid !== Session::getLocalUser()) {
|
||||
if ($Notification->uid !== DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\ForbiddenException();
|
||||
}
|
||||
|
||||
if ($this->pconfig->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
|
||||
if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
|
||||
$Notification->setSeen();
|
||||
$this->notificationRepo->save($Notification);
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,6 @@ use Friendica\Content\ForumManager;
|
|||
use Friendica\Core\Cache\Enum\Duration;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -91,18 +90,18 @@ class Ping extends BaseModule
|
|||
$today_birthday_count = 0;
|
||||
|
||||
|
||||
if (Session::getLocalUser()) {
|
||||
if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
|
||||
$notifications = $this->notificationRepo->selectDetailedForUser(Session::getLocalUser());
|
||||
if (DI::userSession()->getLocalUserId()) {
|
||||
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
|
||||
$notifications = $this->notificationRepo->selectDetailedForUser(DI::userSession()->getLocalUserId());
|
||||
} else {
|
||||
$notifications = $this->notificationRepo->selectDigestForUser(Session::getLocalUser());
|
||||
$notifications = $this->notificationRepo->selectDigestForUser(DI::userSession()->getLocalUserId());
|
||||
}
|
||||
|
||||
$condition = [
|
||||
"`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
|
||||
Session::getLocalUser(), Verb::getID(Activity::FOLLOW)
|
||||
DI::userSession()->getLocalUserId(), Verb::getID(Activity::FOLLOW)
|
||||
];
|
||||
$items = Post::selectForUser(Session::getLocalUser(), ['wall', 'uid', 'uri-id'], $condition, ['limit' => 1000]);
|
||||
$items = Post::selectForUser(DI::userSession()->getLocalUserId(), ['wall', 'uid', 'uri-id'], $condition, ['limit' => 1000]);
|
||||
if (DBA::isResult($items)) {
|
||||
$items_unseen = Post::toArray($items, false);
|
||||
$arr = ['items' => $items_unseen];
|
||||
|
@ -140,12 +139,12 @@ class Ping extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$intros = $this->introductionRepo->selectForUser(Session::getLocalUser());
|
||||
$intros = $this->introductionRepo->selectForUser(DI::userSession()->getLocalUserId());
|
||||
|
||||
$intro_count = $intros->count();
|
||||
|
||||
$myurl = DI::baseUrl() . '/profile/' . DI::app()->getLoggedInUserNickname();
|
||||
$mail_count = DBA::count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", Session::getLocalUser(), $myurl]);
|
||||
$mail_count = DBA::count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", DI::userSession()->getLocalUserId(), $myurl]);
|
||||
|
||||
if (intval(DI::config()->get('config', 'register_policy')) === Register::APPROVE && DI::app()->isSiteAdmin()) {
|
||||
$regs = \Friendica\Model\Register::getPending();
|
||||
|
@ -155,12 +154,12 @@ class Ping extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$cachekey = 'ping:events:' . Session::getLocalUser();
|
||||
$cachekey = 'ping:events:' . DI::userSession()->getLocalUserId();
|
||||
$ev = DI::cache()->get($cachekey);
|
||||
if (is_null($ev)) {
|
||||
$ev = DBA::selectToArray('event', ['type', 'start'],
|
||||
["`uid` = ? AND `start` < ? AND `finish` > ? AND NOT `ignore`",
|
||||
Session::getLocalUser(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utcNow()]);
|
||||
DI::userSession()->getLocalUserId(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utcNow()]);
|
||||
DI::cache()->set($cachekey, $ev, Duration::HOUR);
|
||||
}
|
||||
|
||||
|
@ -188,7 +187,7 @@ class Ping extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$owner = User::getOwnerDataById(Session::getLocalUser());
|
||||
$owner = User::getOwnerDataById(DI::userSession()->getLocalUserId());
|
||||
|
||||
$navNotifications = array_map(function (Entity\Notification $notification) use ($owner) {
|
||||
if (!DI::notify()->NotifyOnDesktop($notification)) {
|
||||
|
@ -215,7 +214,7 @@ class Ping extends BaseModule
|
|||
}
|
||||
|
||||
if (DBA::isResult($regs)) {
|
||||
if (count($regs) <= 1 || DI::pConfig()->get(Session::getLocalUser(), 'system', 'detailed_notif')) {
|
||||
if (count($regs) <= 1 || DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
|
||||
foreach ($regs as $reg) {
|
||||
$navNotifications[] = $this->formattedNavNotification->createFromParams(
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue