public function closeConversation($thread_id)
 {
     $online_user = OnlineUsers::where('thread_id', $thread_id)->first();
     $closed_conversation = new ClosedConversations();
     $closed_conversation->user_id = $online_user->user_id;
     $closed_conversation->thread_id = $online_user->thread_id;
     $closed_conversation->operator_id = $online_user->operator_id > 0 ? $online_user->operator_id : Auth::user()->id;
     $closed_conversation->company_id = $online_user->company_id;
     $closed_conversation->department_id = $online_user->department_id;
     $closed_conversation->requested_on = $online_user->requested_on;
     $closed_conversation->started_on = $online_user->started_on > 0 ? $online_user->started_on : \Carbon\Carbon::now();
     $closed_conversation->token = $online_user->token;
     $closed_conversation->ended_on = \Carbon\Carbon::now();
     $closed_conversation->save();
     RecentActivities::createActivity("Online Conversation <a href='/conversations/closed'>ID:" . $closed_conversation->id . "</a> closed by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name);
     OnlineUsers::where('thread_id', $thread_id)->delete();
     Session::flash('success_msg', trans('msgs.conversation_closed_success'));
     return Redirect::to('/conversations/all');
 }
 public function end()
 {
     if (!Input::has('thread_id')) {
         return "";
     }
     $online_user = OnlineUsers::where('thread_id', Input::get('thread_id'))->first();
     $closed_conversation = new ClosedConversations();
     $closed_conversation->user_id = $online_user->user_id;
     $closed_conversation->thread_id = $online_user->thread_id;
     $closed_conversation->operator_id = $online_user->operator_id > 0 ? $online_user->operator_id : 0;
     $closed_conversation->company_id = $online_user->company_id;
     $closed_conversation->department_id = $online_user->department_id;
     $closed_conversation->requested_on = $online_user->requested_on;
     $closed_conversation->started_on = $online_user->started_on > 0 ? $online_user->started_on : \Carbon\Carbon::now();
     $closed_conversation->token = $online_user->token;
     $closed_conversation->ended_on = \Carbon\Carbon::now();
     $closed_conversation->save();
     RecentActivities::createActivity("Chat Conversation closed <a href='/conversations/read/" . $closed_conversation->id . "'>ID:" . $closed_conversation->id . "</a> by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name);
     OnlineUsers::where('thread_id', Input::get('thread_id'))->delete();
 }