Exemplo n.º 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getChatUserRel()
 {
     return $this->hasMany(PoprigunChatUserRel::className(), ['message_id' => 'id']);
 }
Exemplo n.º 2
0
 /**
  * Delete dialog/delete dialog messages (change status)
  *
  * @param integer $dialogId
  * @param integer|null $userId
  * @return int
  */
 public static function deleteDialog($dialogId, $userId = null)
 {
     $userId = $userId ? $userId : Yii::$app->user->id;
     $messageIds = PoprigunChatMessage::find()->select([PoprigunChatMessage::tableName() . '.id', PoprigunChatUser::tableName() . '.id as chat_user_id'])->innerJoinWith('chatUserRel')->innerJoinWith('chatUserRel.chatUser')->andWhere([PoprigunChatMessage::tableName() . '.dialog_id' => $dialogId])->andWhere([PoprigunChatUser::tableName() . '.user_id' => $userId])->asArray()->all();
     if (empty($messageIds)) {
         return false;
     }
     return PoprigunChatUserRel::updateAll(['status' => PoprigunChatUserRel::STATUS_DELETED], ['message_id' => ArrayHelper::map($messageIds, 'id', 'id'), 'chat_user_id' => ArrayHelper::map($messageIds, 'chat_user_id', 'chat_user_id')]);
 }
Exemplo n.º 3
0
 /**
  * Delete message (change status)
  *
  * @param $messageId
  * @return array
  */
 public function actionDeleteMessage($messageId)
 {
     return ['status' => PoprigunChatUserRel::deleteMessage(Chat::decodeUserId($messageId)) ? 'success' : 'error'];
 }