mirror of
https://github.com/friendica/friendica
synced 2025-04-29 17:44:24 +02:00
ReWork Notification Model/Module/Object/Repository/Factory
- Introduce Repository for interaction with "notify" table - Introduce Factory for read-only notification objects (they're just loosely based on notification the table!) - Introduce Objects for type-safe usage at the presentation layer - Reworked Model, which is now fully based on the notify table, including generated fields (cache, ..)
This commit is contained in:
parent
230bb6dd53
commit
0850fb88dd
17 changed files with 1413 additions and 851 deletions
|
@ -5905,19 +5905,20 @@ function api_friendica_notification($type)
|
|||
if ($a->argc!==3) {
|
||||
throw new BadRequestException("Invalid argument count");
|
||||
}
|
||||
$notes = DI::notification()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50);
|
||||
|
||||
$notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]);
|
||||
|
||||
if ($type == "xml") {
|
||||
$xmlnotes = [];
|
||||
if (!empty($notes)) {
|
||||
foreach ($notes as $note) {
|
||||
$xmlnotes[] = ["@attributes" => $note];
|
||||
if (!empty($notifications)) {
|
||||
foreach ($notifications as $notification) {
|
||||
$xmlnotes[] = ["@attributes" => $notification->toArray()];
|
||||
}
|
||||
}
|
||||
|
||||
$notes = $xmlnotes;
|
||||
$notifications = $xmlnotes;
|
||||
}
|
||||
return api_format_data("notes", $type, ['note' => $notes]);
|
||||
return api_format_data("notes", $type, ['note' => $notifications->getArrayCopy()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5935,37 +5936,37 @@ function api_friendica_notification($type)
|
|||
*/
|
||||
function api_friendica_notification_seen($type)
|
||||
{
|
||||
$a = DI::app();
|
||||
$a = DI::app();
|
||||
$user_info = api_get_user($a);
|
||||
|
||||
if (api_user() === false || $user_info === false) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
if ($a->argc!==4) {
|
||||
if ($a->argc !== 4) {
|
||||
throw new BadRequestException("Invalid argument count");
|
||||
}
|
||||
|
||||
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
|
||||
|
||||
$nm = DI::notification();
|
||||
$note = $nm->getByID($id);
|
||||
if (is_null($note)) {
|
||||
throw new BadRequestException("Invalid argument");
|
||||
}
|
||||
try {
|
||||
$notification = DI::notification()->getByID($id);
|
||||
$notification->setSeen();
|
||||
|
||||
$nm->setSeen($note);
|
||||
if ($note['otype']=='item') {
|
||||
// would be really better with an ItemsManager and $im->getByID() :-P
|
||||
$item = Item::selectFirstForUser(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
|
||||
if (DBA::isResult($item)) {
|
||||
// we found the item, return it to the user
|
||||
$ret = api_format_items([$item], $user_info, false, $type);
|
||||
$data = ['status' => $ret];
|
||||
return api_format_data("status", $type, $data);
|
||||
if ($notification->otype == 'item') {
|
||||
// would be really better with an ItemsManager and $im->getByID() :-P
|
||||
$item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]);
|
||||
if (DBA::isResult($item)) {
|
||||
// we found the item, return it to the user
|
||||
$ret = api_format_items([$item], $user_info, false, $type);
|
||||
$data = ['status' => $ret];
|
||||
return api_format_data("status", $type, $data);
|
||||
}
|
||||
// the item can't be found, but we set the notification as seen, so we count this as a success
|
||||
}
|
||||
// the item can't be found, but we set the note as seen, so we count this as a success
|
||||
return api_format_data('result', $type, ['result' => "success"]);
|
||||
} catch (NotFoundException $e) {
|
||||
throw new BadRequestException('Invalid argument');
|
||||
}
|
||||
return api_format_data('result', $type, ['result' => "success"]);
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue