public function actionSend()
 {
     if (Yii::$app->request->post("recipient_id")) {
         $recipient_id = Yii::$app->request->post("recipient_id");
         $text = Yii::$app->request->post("message");
         $sender_id = Yii::$app->request->post("sender_id");
         $recipientUser = Salamiuser::find()->where(['id' => $recipient_id])->one();
         $senderUser = Salamiuser::find()->where(['id' => $sender_id])->one();
         $message = new Messages();
         $message->sender_id = $senderUser->id;
         $message->recipient_id = $recipientUser->id;
         $message->text = $text;
         $message->state = "new";
         $saved = $message->save();
         $data = array('user_ids' => array($recipientUser->facebook_id), 'notification' => array("alert" => $text, "android" => array('payload' => array("sender" => $senderUser->facebook_id))));
         $ionicAppId = "70f2a984";
         $ionicApiSecret = "ec4839bfb9ea2daa2271b0149a0c18003a3672178f4e6485";
         $url = "https://push.ionic.io/api/v1/push";
         $content = json_encode($data);
         $curl = new curl\Curl();
         $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl->setOption(CURLOPT_POSTFIELDS, $content);
         $curl->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: ' . $ionicAppId, 'Content-Length: ' . strlen($content), 'Authorization: Basic ' . base64_encode($ionicApiSecret)));
         $response = $curl->post('https://push.ionic.io/api/v1/push');
         return $response;
     }
     return '{"error": "Invalid request parameters"}';
 }
 public function actionConversations()
 {
     try {
         $results1 = Messages::find()->select(['`salami_user`.`name`', '`salami_user`.`profile_picture`', '`salami_user`.`id`', '`messages`.`text`', '`messages`.`created_at`', '`messages`.`state`', '`messages`.`recipient_id`'])->leftJoin('salami_user', '`messages`.`recipient_id` = `salami_user`.`id`')->where(['sender_id' => $_GET['user_id']])->orderBy(['created_at' => SORT_DESC])->distinct(['`salami_user`.`id`'])->asArray()->all();
         $results2 = Messages::find()->select(['`salami_user`.`name`', '`salami_user`.`profile_picture`', '`salami_user`.`id`', '`messages`.`text`', '`messages`.`created_at`', '`messages`.`state`', '`messages`.`recipient_id`'])->leftJoin('salami_user', '`messages`.`sender_id` = `salami_user`.`id`')->where(['recipient_id' => $_GET['user_id']])->orderBy(['created_at' => SORT_DESC])->distinct(['`salami_user`.`id`'])->asArray()->all();
         return array_merge($results1, $results2);
     } catch (Exception $ex) {
         throw new \yii\web\HttpException(500, 'Internal server error');
     }
     return [];
 }