public function registerAssets() { $model = new PoprigunChatMessage(); $model->receiverId = Chat::decodeUserId($this->options['receiver_id']); $model->messageType = PoprigunChatMessage::MESSAGE_TO_USER; echo $this->renderFile($this->template, ['model' => $model, 'options' => $this->options]); }
/** * Validate receiver * * @param $attribute * @param $params */ public function valdateReceiver($attribute, $params) { if ($this->messageType == self::MESSAGE_TO_USER) { $this->receiverId = Chat::decodeUserId($this->receiverId); } elseif ($this->messageType == self::MESSAGE_TO_DIALOG) { $this->receiverId = Chat::decodeDialogId($this->receiverId); } else { $this->addError($attribute, 'Incorrect receiver'); } }
public function init() { parent::init(); }
public function getDialogsArray($dialogs) { $result = []; if (!empty($dialogs)) { foreach ($dialogs as $key => $dialog) { /** * @var $dialog PoprigunChatDialog */ $result[$key]['dialog_id'] = Chat::codeDialogId($dialog->id); $result[$key]['user_id'] = $dialog->author_id; $result[$key]['user_name'] = $dialog->userName; $result[$key]['new_count'] = $dialog->newCount; $result[$key]['image'] = $dialog->userAvatar; $lastMessages = $dialog->getMessages(1); $result[$key]['last_message'] = current(array_values($lastMessages)) ? current(array_values($lastMessages))->message : ''; } } return $result; }