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 []; }
public function actionHistory() { if (!empty($_GET)) { try { $query = Messages::find()->where(['sender_id' => $_GET['user_id'], 'recipient_id' => $_GET['buddy_id']])->orWhere(['recipient_id' => $_GET['user_id'], 'sender_id' => $_GET['buddy_id']])->orderBy('created_at'); } catch (Exception $ex) { throw new \yii\web\HttpException(500, 'Internal server error'); } return $query->all(); } else { throw new \yii\web\HttpException(400, 'There are no query string'); } }