/**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $actor = $request->getAttribute('actor');
     $actor->flags_read_time = time();
     $actor->save();
     return Flag::whereVisibleTo($actor)->with($this->extractInclude($request))->latest('flags.time')->groupBy('post_id')->get();
 }
Пример #2
0
 protected function data(JsonApiRequest $request, Document $document)
 {
     $actor = $request->actor;
     $actor->flags_read_time = time();
     $actor->save();
     return Flag::whereVisibleTo($actor)->with($request->include)->latest('flags.time')->groupBy('post_id')->get();
 }
Пример #3
0
 public function addAttributes(ApiAttributes $event)
 {
     if ($event->serializer instanceof ForumSerializer) {
         $event->attributes['canViewFlags'] = $event->actor->hasPermissionLike('discussion.viewFlags');
         if ($event->attributes['canViewFlags']) {
             $query = Flag::whereVisibleTo($event->actor);
             if ($time = $event->actor->flags_read_time) {
                 $query->where('flags.time', '>', $time);
             }
             $event->attributes['unreadFlagsCount'] = $query->distinct('flags.post_id')->count();
         }
     }
     if ($event->serializer instanceof PostSerializer) {
         $event->attributes['canFlag'] = $event->model->can($event->actor, 'flag');
     }
 }
Пример #4
0
 /**
  * @param User $actor
  * @return int
  */
 protected function getNewFlagsCount(User $actor)
 {
     $query = Flag::whereVisibleTo($actor);
     if ($time = $actor->flags_read_time) {
         $query->where('flags.time', '>', $time);
     }
     return $query->distinct()->count('flags.post_id');
 }