diff --git a/application/controllers/Main.php b/application/controllers/Main.php index e4e8a6a..eb91f19 100644 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -132,9 +132,12 @@ exit; } + $count = (int) $this->input->post('count'); + $offset = (int) $this->input->post('offset'); + $returnData = ['status' => 'success', 'notifications' => []]; - $notifications = $this->NotificationModel->getUserNotifications($_SESSION['user']['ID']); + $notifications = $this->NotificationModel->getUserNotifications($_SESSION['user']['ID'], $count, $count * $offset); $returnData['notifications'] = $notifications; echo json_encode($returnData); diff --git a/application/models/NotificationModel.php b/application/models/NotificationModel.php index f9f794a..3104e89 100644 --- a/application/models/NotificationModel.php +++ b/application/models/NotificationModel.php @@ -62,7 +62,6 @@ } return $result; -// Mark as read } private function add(Notification $notification) { @@ -115,6 +114,9 @@ case 'admin.feedback': $items[] = new \Notification\Admin\NewFeedbackNotification($item); break; + case 'admin.reportedPost': + $items[] = new \Notification\Users\PostReportNotification($item); + break; } } $groups[] = new NotificationGroup($items, $group['count']); diff --git a/application/models/notifications/NotificationGroup.php b/application/models/notifications/NotificationGroup.php index a2e3c42..d452aa9 100644 --- a/application/models/notifications/NotificationGroup.php +++ b/application/models/notifications/NotificationGroup.php @@ -23,7 +23,7 @@ public function __get($attribute) { - return $this->notifications[0]->{$attribute}; + return !empty($this->notifications) ? $this->notifications[0]->{$attribute} : null; } public function __call($name, $arguments) diff --git a/application/views/header.php b/application/views/header.php index 445e547..83b7097 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -90,7 +90,9 @@ diff --git a/assets/js/main.js b/assets/js/main.js index 6ceec40..79d1801 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -291,18 +291,23 @@ $('#notificationMenuButton').click(() => { if (data.success) { loadNotificationsAsync(); } - }, - error: console.log + } }); }); +const notificationCount = 5; +let notificationOffset = 0; + function loadNotificationsAsync() { $.ajax({ url: '/Main/getNotifications', method: 'POST', + data: { + count: notificationCount, + offset: notificationOffset + }, beforeSend: () => { - $('#notificationMenu').prepend('
'); - $('#notificationMenu').find('.list-group').empty(); + $('#notificationMenu').find('.fa').removeClass('fa-frown text-danger').addClass('fa-spin fa-cog'); }, success: (data) => { $('#notificationMenu').find('.text-center').remove(); @@ -325,9 +330,12 @@ function loadNotificationsAsync() { $('#notificationCount').text(unread.length); } } + notificationOffset++; } }, - error: console.log + error: () => { + $('#notificationMenu').find('.fa').removeClass('fa-spin fa-cog').addClass('fa-frown text-danger'); + } }); } diff --git a/assets/js/post-item.js b/assets/js/post-item.js index a72dc72..5d71adf 100644 --- a/assets/js/post-item.js +++ b/assets/js/post-item.js @@ -1,5 +1,4 @@ function showFullPost(uuid, username) { - console.log(uuid, username); let defaultUrl = window.location.pathname; if(window.location.pathname.indexOf('user') === -1) defaultUrl += window.location.search; @@ -7,8 +6,9 @@ function showFullPost(uuid, username) { $.ajax({ url: "/user/single_post_data/" + username + "/" + uuid, beforeSend: () => { - const origin = encodeURI(btoa(window.location.href)); + const origin = encodeURI(btoa(window.location.href.split('/post')[0])); window.history.pushState('', '', '/user/' + username + '/post/' + uuid + '?o=' + origin); + $('body').append(`