/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     $data_sent = ApiMessage::where('sent_id', $input['user_id'])->groupBy('receiver_id')->lists('receiver_id');
     $data_recived = ApiMessage::where('receiver_id', $input['user_id'])->groupBy('sent_id')->lists('sent_id');
     $total = array_diff($data_recived, $data_sent);
     $result = array_merge($total, $data_sent);
     if ($result) {
         foreach ($result as $key => $value) {
             $msg = Common::queryCommonMessage($input, $value);
             $msg = $msg->orderBy('created_at', 'desc')->first();
             $block = BlackList::where('user_id', $input['user_id'])->where('black_id', $value)->first();
             if ($msg) {
                 if ($block) {
                     $blockUser = true;
                 } else {
                     $blockUser = false;
                 }
                 $data[] = array('id' => $msg->id, 'chat_avatar' => url(USER_AVATAR . '/' . $value . '/' . User::find($value)->avatar), 'chat_id' => $value, 'chat_name' => User::find($value)->username, 'message' => $msg->message, 'status' => $msg->status, 'created_at' => date('Y-m-d', strtotime($msg->created_at)), 'block' => $blockUser);
             } else {
                 $data = null;
             }
         }
     } else {
         $data = null;
     }
     return Common::returnData(200, SUCCESS, $input['user_id'], $sessionId, $data);
 }
Beispiel #2
0
 public static function queryCommonMessage($input, $value)
 {
     $data = ApiMessage::where(function ($query) use($input, $value) {
         $query->where('sent_id', $input['user_id'])->where('receiver_id', $value);
     })->orWhere(function ($query) use($input, $value) {
         $query->where('receiver_id', $input['user_id'])->where('sent_id', $value);
     })->whereNull('deleted_at');
     return $data;
 }