1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//use LaravelRealtimeChat\Repositories\Conversation\ConversationRepository; |
4
|
|
|
//use LaravelRealtimeChat\Repositories\User\UserRepository; |
5
|
|
|
|
6
|
|
|
class ConversationController extends \BaseController { |
7
|
|
|
|
8
|
|
|
// /** |
9
|
|
|
// * @var LaravelRealtimeChat\Repositories\Conversation\ConversationRepository |
10
|
|
|
// */ |
11
|
|
|
// private $conversationRepository; |
12
|
|
|
// |
13
|
|
|
// /** |
14
|
|
|
// * @var LaravelRealtimeChat\Repositories\User\UserRepository |
15
|
|
|
// */ |
16
|
|
|
// private $userRepository; |
17
|
|
|
// |
18
|
|
|
// public function __construct(ConversationRepository $conversationRepository, UserRepository $userRepository) { |
19
|
|
|
// $this->conversationRepository = $conversationRepository; |
20
|
|
|
// $this->userRepository = $userRepository; |
21
|
|
|
// } |
22
|
|
|
// |
23
|
|
|
// /** |
24
|
|
|
// * Display a listing of conversations. |
25
|
|
|
// * |
26
|
|
|
// * @return Response |
27
|
|
|
// */ |
28
|
|
|
// public function index() { |
29
|
|
|
// $viewData = array(); |
30
|
|
|
// |
31
|
|
|
// $users = $this->userRepository->getAllExcept(Auth::user()->id); |
32
|
|
|
// |
33
|
|
|
// foreach ($users as $key => $user) { |
34
|
|
|
// $viewData['recipients'][$user->id] = $user->username; |
35
|
|
|
// } |
36
|
|
|
// |
37
|
|
|
// $viewData['current_conversation'] = $this->conversationRepository->getByName(Input::get('conversation')); |
38
|
|
|
// $viewData['conversations'] = Auth::user()->conversations()->get(); |
39
|
|
|
// |
40
|
|
|
// return View::make('templates/conversations', $viewData); |
41
|
|
|
// } |
42
|
|
|
|
43
|
|
|
public function conversations() { |
44
|
|
|
$channelId = Input::get('channelId'); |
|
|
|
|
45
|
|
|
$teamName = DB::table('team_channels') |
46
|
|
|
->select('channel_view_name') |
47
|
|
|
->where('team_channel_id', '=', $channelId)->first(); |
48
|
|
|
$messages = DB::table('messages') |
49
|
|
|
->select('messages.message', 'messages.id', 'messages.created_at', 'users.first_name', 'users.last_name', 'users.profile_pic', 'users.id as user_id') |
50
|
|
|
->leftJoin('team_conversations', 'messages.id', '=', 'team_conversations.message_id') |
51
|
|
|
->leftJoin('users', 'users.id', '=', 'team_conversations.user_id') |
52
|
|
|
->where('team_conversations.team_channel_id', '=', $channelId)->orderBy('messages.id', 'desc')->take(10)->get(); |
53
|
|
|
// print_r($messages); |
54
|
|
|
$messages = array_reverse($messages); |
55
|
|
|
$data = array("messages" => $messages, "channelId" => $channelId, "teamName" => $teamName['channel_view_name']); |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
return View::make('templates/messages')->with('data', $data); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function personal_conversations() { |
62
|
|
|
// \Debugbar::enable(); |
63
|
|
|
$userData = Input::get('channelId'); |
64
|
|
|
$data = explode("_", $userData); |
65
|
|
|
$to_user_id = $data[0]; |
66
|
|
|
$teamChannelId = $data[1]; |
67
|
|
|
/** |
68
|
|
|
* Get the to_user details |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
$toUserDetails = DB::table('users') |
72
|
|
|
->select('id', 'first_name', 'last_name', 'profile_pic') |
73
|
|
|
->where('id', '=', $to_user_id)->first(); |
74
|
|
|
$messages = DB::table('messages') |
75
|
|
|
->select('messages.message', 'messages.id', 'messages.created_at', 'personal_conversations.to_user_id', 'personal_conversations.from_user_id') |
76
|
|
|
->leftJoin('personal_conversations', 'messages.id', '=', 'personal_conversations.message_id') |
77
|
|
|
->whereIn('personal_conversations.to_user_id', array(Auth::user()->id, $to_user_id)) |
78
|
|
|
->whereIn('personal_conversations.from_user_id', array(Auth::user()->id, $to_user_id)) |
79
|
|
|
->where('personal_conversations.team_channel_id', '=', $teamChannelId)->orderBy('messages.id', 'desc')->take(10)->get(); |
80
|
|
|
$messages = array_reverse($messages); |
81
|
|
|
$queries = DB::getQueryLog(); |
82
|
|
|
$last_query = end($queries); |
|
|
|
|
83
|
|
|
$data = array("messages" => $messages, "channelId" => $teamChannelId, "toUserDetails" => $toUserDetails); |
84
|
|
|
// |
85
|
|
|
// |
86
|
|
|
return View::make('templates/messages')->with('data', $data); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Store a newly created conversation in storage. |
91
|
|
|
* |
92
|
|
|
* @return Response |
93
|
|
|
*/ |
94
|
|
|
public function store() { |
95
|
|
|
|
96
|
|
|
$rules = array( |
97
|
|
|
'users' => 'required|array', |
98
|
|
|
'body' => 'required' |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$validator = Validator::make(Input::only('users', 'body'), $rules); |
102
|
|
|
|
103
|
|
|
if ($validator->fails()) { |
104
|
|
|
return Response::json([ |
|
|
|
|
105
|
|
|
'success' => false, |
106
|
|
|
'result' => $validator->messages() |
107
|
|
|
]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// Create Conversation |
111
|
|
|
$params = array( |
112
|
|
|
'created_at' => new DateTime, |
113
|
|
|
'name' => str_random(30), |
114
|
|
|
'author_id' => Auth::user()->id |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$conversation = Conversation::create($params); |
118
|
|
|
|
119
|
|
|
$conversation->users()->attach(Input::get('users')); |
120
|
|
|
$conversation->users()->attach(array(Auth::user()->id)); |
121
|
|
|
|
122
|
|
|
// Create Message |
123
|
|
|
$params = array( |
124
|
|
|
'conversation_id' => $conversation->id, |
125
|
|
|
'body' => Input::get('body'), |
126
|
|
|
'user_id' => Auth::user()->id, |
127
|
|
|
'created_at' => new DateTime |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$message = Message::create($params); |
131
|
|
|
|
132
|
|
|
// Create Message Notifications |
133
|
|
|
$messages_notifications = array(); |
134
|
|
|
|
135
|
|
|
foreach (Input::get('users') as $user_id) { |
136
|
|
|
array_push($messages_notifications, new MessageNotification(array('user_id' => $user_id, 'read' => false, 'conversation_id' => $conversation->id))); |
|
|
|
|
137
|
|
|
|
138
|
|
|
// Publish Data To Redis |
139
|
|
|
$data = array( |
140
|
|
|
'room' => $user_id, |
141
|
|
|
'message' => array('conversation_id' => $conversation->id) |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
Event::fire(ChatConversationsEventHandler::EVENT, array(json_encode($data))); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$message->messages_notifications()->saveMany($messages_notifications); |
148
|
|
|
|
149
|
|
|
return Redirect::route('chat.index', array('conversation', $conversation->name)); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
function get_snippet_code() { |
|
|
|
|
153
|
|
|
$msgId = Input::get('snipetId'); |
154
|
|
|
$messages = DB::table('messages') |
155
|
|
|
->select('messages.message') |
156
|
|
|
->where('messages.id', '=', $msgId)->first(); |
157
|
|
|
return $messages['message']; |
158
|
|
|
// return View::make('templates/snippet/snippet_view_modal.blade')->with('snippetData', $snippetData); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths