<commit_before><?php namespace Strimoid\Http\Controllers;

use Auth;
use Response;
use Strimoid\Models\Notification;

class NotificationController extends BaseController
{
    public function showJSONList($count)
    {
        if ($count > 50 || $count < 0) {
            $count = 50;
        }

        $notifications = Notification::target(['user_id' => Auth::id()])
            ->orderBy('created_at', 'desc')
            ->take($count)->get();

        $list = [];

        foreach ($notifications as $notification) {
            $list[] = [
                'id'       => $notification->hashId(),
                'title'    => $notification->title,
                'time'     => $notification->getLocalTime(),
                'time_ago' => $notification->created_at->diffForHumans(),
                'type'     => $notification->getTypeDescription(),
                'url'      => $notification->getURL(),
                'img'      => $notification->getThumbnailPath(),
            ];
        }

        return Response::json(['notifications' => $list]);
    }

    public function showJSONCount()
    {
        $newNotificationsCount = Notification::target(['user_id' => Auth::id(), 'read' => false]);

        $results['new'] = intval($newNotificationsCount);

        return Response::json($results);
    }

    public function showList()
    {
        $notifications = Notification::target(['user_id' => Auth::id()])
            ->orderBy('created_at', 'desc')->paginate(30);

        return view('notifications.list', ['notifications' => $notifications]);
    }

    public function markAllAsRead()
    {
        Notification::target(['user_id' => Auth::id(), 'read' => false])->update(['_targets.$.read' => true]);

        return Response::json(['status' => 'ok']);
    }

    public function registerGCM()
    {<commit_msg>Fix marking notifications as read<commit_after><?php namespace Strimoid\Http\Controllers;

use Auth;
use Response;
use Strimoid\Models\Notification;
use Strimoid\Models\NotificationTarget;

class NotificationController extends BaseController
{
    public function showJSONList($count)
    {
        if ($count > 50 || $count < 0) {
            $count = 50;
        }

        $notifications = Notification::target(['user_id' => Auth::id()])
            ->orderBy('created_at', 'desc')
            ->take($count)->get();

        $list = [];

        foreach ($notifications as $notification) {
            $list[] = [
                'id'       => $notification->hashId(),
                'title'    => $notification->title,
                'time'     => $notification->getLocalTime(),
                'time_ago' => $notification->created_at->diffForHumans(),
                'type'     => $notification->getTypeDescription(),
                'url'      => $notification->getURL(),
                'img'      => $notification->getThumbnailPath(),
            ];
        }

        return Response::json(['notifications' => $list]);
    }

    public function showJSONCount()
    {
        $newNotificationsCount = Notification::target(['user_id' => Auth::id(), 'read' => false]);

        $results['new'] = intval($newNotificationsCount);

        return Response::json($results);
    }

    public function showList()
    {
        $notifications = Notification::target(['user_id' => Auth::id()])
            ->orderBy('created_at', 'desc')->paginate(30);

        return view('notifications.list', ['notifications' => $notifications]);
    }

    public function markAllAsRead()
    {
        NotificationTarget::where('user_id', Auth::id())
            ->where('read', false)
            ->update(['read' => true]);

        return Response::json(['status' => 'ok']);
    }

    public function registerGCM()
    {
{'fraction_non_alphanumeric': 0.16493471889155342, 'fraction_numerical': 0.0037303490540900614, 'mean_word_length': 2.336888888888889, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3946619', 'n_tokens_mistral': 1048, 'n_tokens_neox': 988, 'n_words': 187}