/** * Show conversation * * @param int $id * @param Request $request * @return $this */ public function show($id, Request $request) { $this->breadcrumb->push('Wiadomości prywatne', route('user.pm')); $pm = $this->pm->find($id, ['user_id', 'root_id', 'id']); if (!$pm) { return redirect()->route('user.pm'); } if ($pm->user_id !== auth()->user()->id) { abort(500); } $talk = $this->pm->talk(auth()->user()->id, $pm->root_id, 10, $request->query('offset', 0)); $parser = app()->make('Parser\\Pm'); foreach ($talk as &$row) { $row['text'] = $parser->parse($row['text']); // we have to mark this message as read if (!$row['read_at'] && $row['folder'] == \Coyote\Pm::INBOX) { $this->pm->markAsRead($row['id']); } // IF we have unread alert that is connected with that message... then we also have to mark it as read if (auth()->user()->alerts_unread) { $this->alert->markAsReadByUrl(auth()->user()->id, route('user.pm.show', [$row['id']], false)); } } if ($request->ajax()) { return view('user.pm.infinite')->with('talk', $talk); } return parent::view('user.pm.show')->with(compact('pm', 'talk')); }
/** * Marks one or more alerts as read * * @param null|int $id */ public function markAsRead($id = null) { if ($id) { $this->alert->update(['is_marked' => true], $id); } else { if (auth()->user()->alerts_unread) { $this->alert->where('user_id', auth()->user() > id)->where('read_at', 'IS', null)->update(['read_at' => Carbon::now()]); } $this->alert->where('user_id', auth()->user()->id)->update(['is_marked' => true]); } }