mirror of
https://github.com/friendica/friendica
synced 2025-04-24 12:30:10 +00:00
Move notification to the new paradigm
This commit is contained in:
parent
bc0734e0f1
commit
7a2d5f6a8e
16 changed files with 175 additions and 420 deletions
|
@ -28,6 +28,8 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Object\Api\Mastodon\Notification;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
||||
/**
|
||||
|
@ -46,10 +48,12 @@ class Notifications extends BaseApi
|
|||
|
||||
if (!empty($parameters['id'])) {
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('notification', ['id' => $id, 'uid' => $uid])) {
|
||||
try {
|
||||
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
|
||||
System::jsonExit(DI::mstdnNotification()->createFromNotification($notification));
|
||||
} catch (\Exception $e) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
System::jsonExit(DI::mstdnNotification()->createFromNotificationId($id));
|
||||
}
|
||||
|
||||
$request = self::getRequest([
|
||||
|
@ -63,7 +67,7 @@ class Notifications extends BaseApi
|
|||
'count' => 0, // Unknown parameter
|
||||
]);
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => $request['limit']];
|
||||
$params = ['order' => ['id' => true]];
|
||||
|
||||
$condition = ['uid' => $uid, 'seen' => false];
|
||||
|
||||
|
@ -115,36 +119,26 @@ class Notifications extends BaseApi
|
|||
Verb::getID(Activity::POST), Post\UserNotification::TYPE_SHARED]);
|
||||
}
|
||||
|
||||
if (!empty($request['max_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` < ?", $request['max_id']]);
|
||||
}
|
||||
$mstdnNotifications = [];
|
||||
|
||||
if (!empty($request['since_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $request['since_id']]);
|
||||
}
|
||||
$Notifications = DI::notification()->selectByBoundaries(
|
||||
$condition,
|
||||
$params,
|
||||
$request['min_id'] ?? null,
|
||||
$request['min_id'] ?? $request['since_id'] ?? null,
|
||||
$request['limit']
|
||||
);
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $request['min_id']]);
|
||||
|
||||
$params['order'] = ['id'];
|
||||
}
|
||||
|
||||
$notifications = [];
|
||||
|
||||
$notify = DBA::select('notification', ['id'], $condition, $params);
|
||||
while ($notification = DBA::fetch($notify)) {
|
||||
self::setBoundaries($notification['id']);
|
||||
$entry = DI::mstdnNotification()->createFromNotificationId($notification['id']);
|
||||
if (!empty($entry)) {
|
||||
$notifications[] = $entry;
|
||||
foreach($Notifications as $Notification) {
|
||||
try {
|
||||
$mstdnNotifications[] = DI::mstdnNotification()->createFromNotification($Notification);
|
||||
self::setBoundaries($Notification->id);
|
||||
} catch (\Exception $e) {
|
||||
// Skip this notification
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
array_reverse($notifications);
|
||||
}
|
||||
|
||||
self::setLinkHeader();
|
||||
System::jsonExit($notifications);
|
||||
System::jsonExit($mstdnNotifications);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
namespace Friendica\Module\Api\Mastodon\Notifications;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +35,7 @@ class Clear extends BaseApi
|
|||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
DBA::update('notification', ['seen' => true], ['uid' => $uid]);
|
||||
DI::notification()->setAllSeenForUser($uid);
|
||||
|
||||
System::jsonExit([]);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/notifications/
|
||||
|
@ -40,7 +41,9 @@ class Dismiss extends BaseApi
|
|||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
DBA::update('notification', ['seen' => true], ['uid' => $uid, 'id' => $parameters['id']]);
|
||||
$Notification = DI::notification()->selectOneForUser($uid, $parameters['id']);
|
||||
$Notification->setSeen();
|
||||
DI::notification()->save($Notification);
|
||||
|
||||
System::jsonExit([]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue