private function composeUserbar() { view()->composer('layouts.partials.userbar', function ($view) { $user = Auth::user(); $notifications = Notification::with('type')->where('user_id', Auth::id())->where('status', 'pending')->latest()->get(); $messages = Message::where('user_id', Auth::id())->where('status', 'pending')->latest()->get(); $view->with(['user' => $user, 'notifications' => $notifications, 'messages' => $messages]); }); }
/** * Display the message history. * * @return \Illuminate\Http\Response */ public function showmessages() { $input = Request::all(); $conv1 = Conversation::where('id', Input::get('conversation_id'))->first(); $conv2 = Conversation::where('user1_id', '=', $conv1->user2_id)->where('user2_id', '=', $conv1->user1_id)->first(); $messages1 = Message::where('conversation_id', $conv1->id)->get(); $messages2 = Message::where('conversation_id', $conv2->id)->get(); $messages = $messages1->merge($messages2); $data['user1_id'] = $conv1->user1_id; $data['user2_id'] = $conv1->user2_id; $data['user1_accountname'] = $conv1->user1_accountname; $data['user2_accountname'] = $conv1->user2_accountname; $data['conversation_id'] = $conv1->id; $data['conversation2_id'] = $conv2->id; $data['messages'] = $messages->sortBy('created_at')->values(); return json_encode($data); }
/** * Show the Peace index screen to the user. * * @return Response */ public function lists(Request $request) { //Validate the Request $this->validate($request, ['id' => 'required']); $messages = Message::where('sender_id', '=', Auth::user()->id)->Where('receiver_id', '=', $request->id)->orWhere('receiver_id', '=', Auth::user()->id)->Where('sender_id', '=', $request->id)->orderBy('created_at')->get(); foreach ($messages as $message) { //If Sender is loged in user if ($message->sender->id === Auth::user()->id) { //Message to the right echo "<div class='direct-chat-msg right'>\n\t\t \t<div class='direct-chat-info clearfix'>\n\t\t <span class='direct-chat-name pull-right'>" . $message->sender->name . "</span>\n\t\t <span class='direct-chat-timestamp pull-left'>" . $message->sendAt() . "</span>\n\t\t\t\t\t\t</div><!-- /.direct-chat-info -->\n\t\t <img class='direct-chat-img' src='" . $message->sender->avatar . "' alt='sender image'><!-- /.direct-chat-img -->\n\t\t <div class='direct-chat-text'>\n\t\t \t" . htmlentities($message->message) . "\n\t\t </div><!-- /.direct-chat-text -->\n\t\t\t\t </div><!-- /.direct-chat-msg -->"; } else { //Message. Default to the left echo "<div class='direct-chat-msg'>\n\t\t \t<div class='direct-chat-info clearfix'>\n\t\t <span class='direct-chat-name pull-left'>" . $message->sender->name . "</span>\n\t\t <span class='direct-chat-timestamp pull-right'>" . $message->sendAt() . "</span>\n\t\t\t\t\t\t</div><!-- /.direct-chat-info -->\n\t\t <img class='direct-chat-img' src='" . $message->sender->avatar . "' alt='sender image'><!-- /.direct-chat-img -->\n\t\t <div class='direct-chat-text'>\n\t\t \t" . htmlentities($message->message) . "\n\t\t </div><!-- /.direct-chat-text -->\n\t\t\t\t </div><!-- /.direct-chat-msg -->"; $message->is_read = 1; $message->save(); } } }
public function testCreateInboundImage() { $factory = new MessageFactory(); $attributes = ['ToUserName' => 'toUser', 'FromUserName' => 'fromUser', 'CreateTime' => 1456355029, 'MsgType' => 'image', 'PicUrl' => 'an image url', 'MediaId' => 123, 'MsgId' => 111111]; $factory->create($attributes, 'inbound'); $m = Message::where('msgType', 'image')->first(); $this->assertNotNull($m); $this->assertInstanceOf('App\\Models\\Inbound', $m->messageable); $this->assertEquals($attributes['MsgType'], $m->msgType); $this->assertEquals($attributes['MsgId'], $m->messageable->msgId); $content = $m->messageable->content; $this->assertEquals($attributes['PicUrl'], $content['PicUrl']); $this->assertEquals($attributes['MediaId'], $content['MediaId']); $this->assertEquals(2, count($content)); }
public function chat($partner_id = 0) { return Message::where('receiver_id', '=', $partner_id)->where('sender_id', '=', $this->id)->orWhere('sender_id', '=', $partner_id)->where('receiver_id', '=', $this->id)->orderBy('updated_at', 'DESC')->get(); }
public static function getThreadKeysByEmail($email) { return Message::where('email', '=', $email)->select(array('thread_key'))->get(); }
public function getConversation($from, $to, $number) { $channel = $this->getChannel($from, $to); $messages = Message::where("TID", $channel)->take($number)->orderBy('created_at', 'desc')->get(); return $messages; }
/** * If this is a unique message. For event message, we could * use the combination of fromUser and createTime. * * @retun bool */ public function unique() { return 1 === Message::where('fromUserName', $this->message->fromUserName)->where('createTime', $this->message->createTime)->get()->count(); }