/**
  * Leave a conversation
  *
  * @param $id
  * @return void
  */
 public function leaveConversation($id)
 {
     try {
         $thread = Thread::findOrFail($id);
         $thread->getParticipantFromUser(Auth::id());
     } catch (ModelNotFoundException $e) {
         Flash::error('The requested conversation does not exist.');
         return redirect('conversations');
     }
     $participant = $thread->getParticipantFromUser(Auth::id());
     $user = $participant->user;
     $thread->messages()->where('user_id', '=', $user->id)->delete();
     $participant->delete();
     if ($thread->participants()->count() == 0) {
         $thread->delete();
     }
     Flash::success('You have left the conversation.');
     return redirect('conversations');
 }
 /**
  * Shows a message thread
  *
  * @param $id
  * @return mixed
  */
 public function show($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         //            Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return response()->json(['success' => 'false', 'message' => 'The thread with ID: ' . $id . ' was not found.']);
     }
     // show current user in list if not a current participant
     // $users = User::whereNotIn('id', $thread->participantsUserIds())->get();
     // don't show the current user in list
     $currentUser = JWTAuth::parseToken()->authenticate();
     $userId = $currentUser->id;
     $user_has = $thread->participantsUserIds()->unique()->search($userId);
     if ($user_has !== false) {
         //check if current user is  a participant of the thread
         $ids = $thread->participantsUserIds();
         $temp2 = null;
         foreach ($ids as $id) {
             if ($id != $userId) {
                 $temp2 = $id;
             }
         }
         $thread->markAsRead($userId);
         return response()->json(['success' => true, 'message' => "Successful", 'messages' => $thread->messages, 'friend' => User::find($temp2), 'myself' => $currentUser]);
     } else {
         return response()->json(['success' => 'false', 'message' => 'You are not permitted to view this thread.']);
     }
 }
Example #3
0
 /**
  * Shows a message thread.
  *
  * @param $id
  * @return mixed
  */
 public function show($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     // don't show the current user in list
     $userId = Auth::user()->id;
     $users = User::whereNotIn('id', $thread->participantsUserIds($userId))->get();
     $thread->markAsRead($userId);
     return view('messenger.show', compact('thread', 'users'));
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //
     # Route Models
     $router->model('role', 'Fetch404\\Core\\Models\\Role');
     $router->model('user', 'Fetch404\\Core\\Models\\User');
     $router->model('news', 'Fetch404\\Core\\Models\\News');
     $router->model('tag', 'Fetch404\\Core\\Models\\Tag');
     $router->model('profile_post', 'Fetch404\\Core\\Models\\ProfilePost');
     $router->model('post', 'Fetch404\\Core\\Models\\Post');
     $router->model('topic', 'Fetch404\\Core\\Models\\Topic');
     $router->model('channel', 'Fetch404\\Core\\Models\\Channel');
     $router->model('category', 'Fetch404\\Core\\Models\\Category');
     $router->model('report', 'Fetch404\\Core\\Models\\Report');
     $router->model('conversation', 'Cmgmyr\\Messenger\\Models\\Thread');
     $router->bind('conversation', function ($value) {
         return Thread::findOrFail($value);
     });
 }
Example #5
0
 public function update(Request $request, $id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $thread->activateAllParticipants();
     // Message
     Message::create(['thread_id' => $thread->id, 'user_id' => Sentinel::getUser()->id, 'body' => $request->message]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Sentinel::getUser()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if ($request->has('recipients')) {
         $thread->addParticipants($request->recipients);
     }
     return redirect('messages/' . $id);
 }
Example #6
0
 /**
  * Adds a new message to a current thread
  *
  * @param $id
  * @return mixed
  */
 public function update($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $thread->activateAllParticipants();
     // Message
     $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::id(), 'body' => Input::get('message')]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants(Input::get('recipients'));
     }
     $this->oooPushIt($message);
     return redirect('messages/' . $id);
 }
 public function updateThread($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $thread->activateAllParticipants();
     // Message
     Message::create(['thread_id' => $thread->id, 'user_id' => Auth::id(), 'body' => Input::get('message')]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants(Input::get('recipients'));
     }
     $userId = Auth::user()->id;
     $users = \App\User::whereNotIn('id', $thread->participantsUserIds($userId))->get();
     return view('messages.show', ['page' => 'message', 'thread' => $thread, 'users' => $users]);
 }
    public function update($id)
    {
        $thread = Thread::findOrFail($id);

        $thread->activateAllParticipants();

        // Message
        Message::create(
            [
                'thread_id' => $thread->id,
                'user_id'   => $this->user->id,
                'body'      => Input::get('message'),
            ]
        );

        // Add replier as a participant
        $participant = Participant::firstOrCreate(
            [
                'thread_id' => $thread->id,
                'user_id'   => $this->user->id
            ]
        );
        $participant->last_read = new Carbon;
        $participant->save();
// Recipients
//if (Input::has('recipients')) {
//$thread->addParticipants(Input::get('recipients'));
//}
return Redirect::to('messages/' . $id);
    }
 public function getMessagesByThread($id)
 {
     $thread = Thread::findOrFail($id);
     $thread->markAsRead(Authorizer::getResourceOwnerId());
     return $thread->messages;
 }
Example #10
0
 /**
  * Adds a new message to a current thread
  *
  * @param $id
  * @return mixed
  */
 public function update(Request $request, $id)
 {
     $body = $request->input('message');
     $validator = Validator::make(['message' => $body], ['message' => 'required|min:20|max:4500'], ['message.required' => 'A message is required.', 'message.min' => 'Messages must be at least 20 characters long.', 'message.max' => 'Messages can be up to 4500 characters long.']);
     if ($validator->passes()) {
         try {
             $thread = Thread::findOrFail($id);
             $thread->getParticipantFromUser(Auth::id());
         } catch (ModelNotFoundException $e) {
             Flash::error('The requested conversation does not exist.');
             return redirect('conversations');
         }
         $thread->activateAllParticipants();
         // Message
         Message::create(['thread_id' => $thread->id, 'user_id' => Auth::id(), 'body' => Input::get('message')]);
         // Add replier as a participant
         $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
         $participant->last_read = new Carbon();
         $participant->save();
         foreach ($thread->participants as $threadParticipant) {
             if ($threadParticipant->user_id != Auth::id()) {
                 $threadParticipant->last_read = null;
                 $threadParticipant->save();
             }
         }
         return redirect('conversations/' . $id . ($thread->messagesPaginated->hasPages() ? '?page=' . $thread->lastPage : ''));
     } else {
         return redirect('conversations/' . $id)->withErrors($validator->messages())->withInput();
     }
 }
 /**
  * Adds a new message to a current thread
  *
  * Example URL: PUT /api/v1/messages/1?api_key=30ce6864e2589b01bc002b03aa6a7923
  *
  * @param $id
  * @return mixed
  */
 public function update($id)
 {
     $userId = $this->user->id;
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return $this->respondNotFound('Sorry, the message thread was not found.');
     }
     // @todo: run validation
     $thread->activateAllParticipants();
     // Message
     Message::create(['thread_id' => $thread->id, 'user_id' => $userId, 'body' => Input::get('message')]);
     // Add replier as a participant
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => $userId]);
     $participant->last_read = new Carbon();
     $participant->save();
     // Recipients
     if (Input::has('recipients')) {
         $thread->addParticipants(Input::get('recipients'));
     }
     return $this->respondWithSaved(['id' => $thread->id]);
 }