Files
easystream/api/notification_preferences.php
Krystie f50b493df2 feat: Add comprehensive notification system with email support
- Create notification management system with VNotifications class
- Build notification API endpoints (get, mark read, delete, preferences)
- Implement notification bell UI widget with real-time polling
- Add email queue system with digest support (instant/hourly/daily/weekly)
- Create notification trigger helpers for common events
- Add fine-grained user preference controls
- Implement cron script for email processing and cleanup
- Document setup and usage in docs/NOTIFICATIONS.md

Features:
- In-app notifications with dropdown
- Email delivery with batching
- 6 notification types (comment, like, subscribe, upload, mention, system)
- User preference controls per notification type
- Lightweight polling (30s interval)
- Auto-cleanup of old notifications (90 days)
- Production-ready with proper error handling
2026-03-30 17:11:08 -07:00

61 lines
1.5 KiB
PHP

<?php
/**
* Notification Preferences API
*
* GET /api/notification_preferences.php - Get user preferences
* POST /api/notification_preferences.php - Update preferences
*/
require_once dirname(__DIR__) . '/f_core/config.boot.php';
require_once dirname(__DIR__) . '/f_core/f_classes/class.notifications.php';
header('Content-Type: application/json');
// Require authentication
session_start();
if (empty($_SESSION['user_id'])) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => 'Authentication required']);
exit;
}
$usr_id = $_SESSION['user_id'];
$notifications = new VNotifications();
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
// Get preferences
$prefs = $notifications->getPreferences($usr_id);
echo json_encode([
'success' => true,
'data' => $prefs
]);
} elseif ($method === 'POST') {
// Update preferences
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
// Try form data
$input = $_POST;
}
$result = $notifications->updatePreferences($usr_id, $input);
if ($result) {
echo json_encode([
'success' => true,
'data' => $notifications->getPreferences($usr_id)
]);
} else {
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Failed to update preferences']);
}
} else {
http_response_code(405);
echo json_encode(['success' => false, 'error' => 'Method not allowed']);
}