Esempio n. 1
0
 protected function data(JsonApiRequest $request, Document $document)
 {
     $actor = $request->actor;
     $actor->reports_read_time = time();
     $actor->save();
     return Report::whereVisibleTo($actor)->with($request->include)->latest('reports.time')->groupBy('post_id')->get();
 }
Esempio n. 2
0
 public function addAttributes(ApiAttributes $event)
 {
     if ($event->serializer instanceof ForumSerializer) {
         $event->attributes['canViewReports'] = $event->actor->hasPermissionLike('discussion.viewReports');
         if ($event->attributes['canViewReports']) {
             $query = Report::whereVisibleTo($event->actor);
             if ($time = $event->actor->reports_read_time) {
                 $query->where('reports.time', '>', $time);
             }
             $event->attributes['unreadReportsCount'] = $query->distinct('reports.post_id')->count();
         }
     }
     if ($event->serializer instanceof PostSerializer) {
         $event->attributes['canReport'] = $event->model->can($event->actor, 'report');
     }
 }