当前位置: 首页>>代码示例>>PHP>>正文


PHP Chat::getLastMessage方法代码示例

本文整理汇总了PHP中Chat::getLastMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Chat::getLastMessage方法的具体用法?PHP Chat::getLastMessage怎么用?PHP Chat::getLastMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chat的用法示例。


在下文中一共展示了Chat::getLastMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getList

 /**
  * Display a listing of chats.
  *
  * @param int|null $lastChatId Last chat ID
  * @param int $size Response size
  * @return Response
  */
 public function getList($lastChatId = null, $size = 20)
 {
     $list = array();
     $ids = array();
     ChatMember::where('user_id', Auth::user()->id)->get()->each(function ($member) use(&$ids) {
         $ids[] = $member->chat_id;
     });
     if (count($ids) > 0) {
         $size = (int) $size > 0 ? (int) $size : 20;
         $unread = array();
         MessageUnread::whereRaw('user_id = ? and message_id not in (select b.message_id from messages_removed b where b.chat_id = chat_id)', array(Auth::user()->id))->get()->each(function ($message) use(&$unread) {
             $unread[] = $message->chat_id;
         });
         $query = 'select * from chats a where a.id in (' . implode(', ', $ids) . ') ' . (($lastChatId = (int) $lastChatId) > 0 ? 'and a.id < ' . $lastChatId . ' ' : '') . 'and (select count(b.id) from messages b where b.chat_id=a.id ' . 'and b.id not in (select c.message_id from messages_removed c where c.chat_id = a.id) ' . 'and b.id > coalesce((select d.message_id from chats_cleared d where d.user_id = ' . Auth::user()->id . ' and d.chat_id = a.id), 0)) > 0 ' . 'order by a.timestamp desc limit ' . $size;
         $result = DB::select($query);
         foreach ($result as $array) {
             $chat = new Chat((array) $array);
             $data = array('chat_id' => $chat->id, 'owner_id' => $chat->owner_id, 'topic' => $chat->topic, 'timestamp' => $chat->getTimestamp(), 'users' => $chat->getUsersArray());
             if (in_array($chat->id, $unread)) {
                 $data['unread'] = true;
             }
             if (!is_null($lastMessage = $chat->getLastMessage())) {
                 $data['last_message'] = $lastMessage->getAsArray();
             }
             $list[] = $data;
         }
     }
     return $this->respond($list);
 }
开发者ID:SenhorBardell,项目名称:yol,代码行数:36,代码来源:ChatsController.php

示例2: getLastMessage

 public function getLastMessage()
 {
     $conn = Connection::getInstance("read");
     if ($chats = $this->getChatsID()) {
         $max = 0;
         foreach ($chats as $chat_id) {
             $chat = new Chat($chat_id);
             if ($m = $chat->getLastMessage()) {
                 //print_r($m);
                 $tstamp = strtotime($m['time']);
                 if ($tstamp > $max) {
                     //echo $tstamp . " ";
                     $max = $tstamp;
                     $latest_message = $m;
                 }
             }
         }
         return $latest_message;
     } else {
         return false;
     }
 }
开发者ID:sheyooo,项目名称:testify,代码行数:22,代码来源:User.php

示例3: foreach

                foreach ($messages as $id) {
                    $message = new Message($id);
                    $sender = new User($message->getSenderID());
                    $time = strtotime($message->getTime());
                    $new_message .= "\n                        <div id=\"{$id}\" class=\"animated fadeIn chatbox-user right\">\n                            <a href=\"javascript:;\" class=\"chat-avatar pull-right\"> \n                                <img src=\"img/faceless.jpg\" class=\"img-circle\" title=\"user name\" alt=\"\">\n                            </a>\n\n                            <div class=\"message\">\n                                <div class=\"panel\">\n                                    <div class=\"panel-heading\">\n                                        {$sender->getFullName()}\n                                    </div>\n\n                                    <div class=\"panel-body\">\n                                        <p>{$message->getMessage()}</p>\n                                    </div>\n                                </div>\n\n                                <small class=\"chat-time\">\n                                <i class=\"ti-time mr5\"></i>\n                                <span data-livestamp=\"{$time}\"></span>\n                                <i class=\"ti-check text-success\"></i>\n                                </small>\n\n                            </div>\n                        </div>";
                }
                echo $new_message;
            }
        } elseif (Tools::valuePost("action") == "send_chat") {
            /*SEND NEW CHAT MESSAGE TO THE SERVER*/
            if (!empty(Tools::valuePost("message"))) {
                echo $chat->sendMessage($user->getID(), Tools::valuePost("message"));
            }
        }
    } elseif (Tools::valuePost("action") == "notification") {
        /*CHECK NEW CHAT MESSAGES FROM THE SERVER*/
        $chats = $user->checkMessages();
        if ($chats) {
            $count = count($chats);
            foreach ($chats as $id) {
                $chat = new Chat($id);
                $message_row = $chat->getLastMessage();
                $sender = new User($message_row['from_user_id']);
                $time = strtotime($message_row['time']);
                $end_product[] = array("count" => $count, "id" => $id, "notifications" => "New message", "name" => $sender->getFullname(), "img" => $sender->getProfilePictureURL(), "timestamp" => $time, "message" => $message_row['message'], "url" => "message.php?chat_id={$id}");
            }
            $end_product = json_encode($end_product);
            echo $end_product;
        }
    }
}
开发者ID:sheyooo,项目名称:gradeaccess,代码行数:31,代码来源:ajax_chat.php


注:本文中的Chat::getLastMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。