Пример #1
0
 public function getAction()
 {
     if (empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
         error404();
     }
     $model = new MailModel();
     $hash = post('__hash');
     $dialog = getSession($hash);
     $messages = '';
     if (!$dialog['did']) {
         $response['error'] = 'There is no dialogue';
         echo json_encode($response);
         exit;
     }
     $data['countMsg' . $dialog['pos']] = '0';
     $model->update('dialog', $data, "`id` = '" . $dialog['did'] . "'");
     $lastMessageID = getSession('mail_last_message' . $dialog['did'], false);
     $mailList = $model->getMessages($dialog['did'], 'ASC', $lastMessageID);
     if ($mailList) {
         foreach ($mailList as $value) {
             //$objVal = (object)$value;
             $messages .= '<div class="chat_message">' . '<div class="chat_img"><a href="' . url($value['uid']) . '" target="_blank"><img src="' . getAvatar($value['uid'], 's') . '"></a></div>' . '<div class="chat_text">' . '<div><span class="chat_nickname">' . $value['name'] . '</span> <span class="chat_time">' . printTime($value['time']) . '</span></div>' . '<div>' . $value['message'] . '</div>' . '</div>' . '</div>';
             setSession('mail_last_message' . $dialog['did'], $value['id']);
         }
     }
     unset($chatList);
     $response['error'] = 0;
     $response['target_a']['#dialog'] = $messages;
     echo json_encode($response);
     exit;
 }