New apps, version and all notification count and read issue solved. #2yrpaz9
This commit is contained in:
@ -27,12 +27,25 @@ class Notifications extends Component
|
||||
return view('livewire.menu.notifications');
|
||||
}
|
||||
|
||||
public function markRead($notification_id)
|
||||
public function markRead($type, $notification_id, $message = true)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
switch ($type) {
|
||||
case 'updates':
|
||||
$this->markUpdateRead($notification_id);
|
||||
break;
|
||||
case 'new-apps':
|
||||
$this->markNewAppRead($notification_id);
|
||||
break;
|
||||
default:
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
if (! $message) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = isset($data['file_name']) ?: trans('general.export');
|
||||
|
||||
@ -44,10 +57,10 @@ class Notifications extends Component
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = user()->unreadNotifications;
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
$this->markRead($notification->type, $notification->id, false);
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
@ -56,6 +69,25 @@ class Notifications extends Component
|
||||
]);
|
||||
}
|
||||
|
||||
public function markUpdateRead($notification_id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function markNewAppRead($notification_id)
|
||||
{
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
if ($notification->id == $notification_id) {
|
||||
setting()->set('notifications.' . $notification->notifiable_id . '.' . $notification->data['alias'], '1');
|
||||
|
||||
setting()->save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getNotifications(): array
|
||||
{
|
||||
$notifications = new \stdClass();
|
||||
|
@ -65,7 +65,8 @@ class ShowInNotifications
|
||||
$new->notifiable_id = user()->id;
|
||||
$new->data = [
|
||||
'title' => $new_app->name,
|
||||
'description' => $new_app->alias,
|
||||
'description' => '', // $new_app->message,
|
||||
'alias' => $new_app->alias,
|
||||
];
|
||||
$new->created_at = $new_app->started_at->date;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace App\View\Components\Layouts\Admin;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
use App\Utilities\Versions;
|
||||
use App\Events\Menu\NotificationsCreated;
|
||||
|
||||
class Menu extends Component
|
||||
{
|
||||
@ -21,10 +21,7 @@ class Menu extends Component
|
||||
{
|
||||
$this->companies = $this->getCompanies();
|
||||
|
||||
$version_update = Versions::getUpdates();
|
||||
|
||||
$this->notification_count = user()->unreadNotifications->count();
|
||||
$this->notification_count += count($version_update);
|
||||
$this->notification_count = $this->getNotificationCount();
|
||||
|
||||
return view('components.layouts.admin.menu');
|
||||
}
|
||||
@ -39,4 +36,16 @@ class Menu extends Component
|
||||
|
||||
return $companies;
|
||||
}
|
||||
|
||||
public function getNotificationCount()
|
||||
{
|
||||
// Get nofitications
|
||||
$notifications = new \stdClass();
|
||||
$notifications->notifications = [];
|
||||
$notifications->keyword = '';
|
||||
|
||||
event(new NotificationsCreated($notifications));
|
||||
|
||||
return $notifications->notifications->count();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user