Ejemplo n.º 1
0
 /**
  * Ñîçäàíèå íîâîãî ñîîáùåíèÿ
  * @param $message
  * @param $recipient, id ïîëó÷àòåëÿ
  * @return ChatMessage
  */
 public static function createNew($message, $recipient)
 {
     $cm = new ChatMessage();
     $cm->message = $message;
     $cm->recipient_id = $recipient;
     $cm->sender_id = Yii::$app->user->identity->id;
     $cm->status = self::STATUS_NEW;
     $cm->save();
     return $cm;
 }
Ejemplo n.º 2
0
 /**
  * Сообщения отмечаются как прочитанные
  */
 public function actionReadTalkMessages()
 {
     $sender = $_POST['sender_id'];
     $unreadMessages = ChatMessage::find()->where(['sender_id' => $sender, 'recipient_id' => Yii::$app->user->identity->id])->all();
     foreach ($unreadMessages as $um) {
         $um->status = ChatMessage::STATUS_READ;
         $um->save();
     }
 }
Ejemplo n.º 3
0
 /**
  * Общее количество непрочитанных сообщений
  */
 public function getUnreadMessageCount()
 {
     $count = ChatMessage::find()->where(['recipient_id' => $this->id, 'status' => ChatMessage::STATUS_NEW])->andWhere('sender_id <> ' . $this->id)->count();
     return $count;
 }