|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class MessageController extends \BaseController { |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Display a listing of messages. |
|
7
|
|
|
* |
|
8
|
|
|
* @return Response |
|
9
|
|
|
*/ |
|
10
|
|
|
public function index() { |
|
11
|
|
|
|
|
12
|
|
|
$conversation = Conversation::where('name', Input::get('conversation'))->first(); |
|
|
|
|
|
|
13
|
|
|
$messages = Message::where('conversation_id', $conversation->id)->orderBy('created_at')->get(); |
|
14
|
|
|
|
|
15
|
|
|
return View::make('templates/messages')->with('messages', $messages)->render(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Store a newly created message in storage. |
|
20
|
|
|
* |
|
21
|
|
|
* @return Response |
|
22
|
|
|
*/ |
|
23
|
|
|
public function send_message() { |
|
24
|
|
|
$isPersonalSet=Input::get('isPersonalFlag'); |
|
25
|
|
|
$rules = array('body' => 'required'); |
|
26
|
|
|
$validator = Validator::make(Input::all(), $rules); |
|
27
|
|
|
|
|
28
|
|
|
if($validator->fails()) { |
|
29
|
|
|
return Response::json([ |
|
|
|
|
|
|
30
|
|
|
'success' => false, |
|
31
|
|
|
'result' => $validator->messages() |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$params = array( |
|
|
|
|
|
|
38
|
|
|
'channel_id' => Input::get('channelId'), |
|
39
|
|
|
'body' => Input::get('body'), |
|
40
|
|
|
'user_id' => Input::get('user_id') |
|
41
|
|
|
|
|
42
|
|
|
); |
|
43
|
|
|
//decode team id |
|
44
|
|
|
$team_decoded_id = DB::table('team_channels')->where('team_channel_id', Input::get('channelId'))->first(); |
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* Get the id of the last inserted message |
|
48
|
|
|
*/ |
|
49
|
|
|
if (strpos(Input::get('body'), '<img') !== false) { |
|
50
|
|
|
$lastId= DB::table('messages')->insertGetId( |
|
51
|
|
|
['message' => strip_tags( Input::get('body'),'<img></img><img /><p></p><br/><br><span></span></code><code><table><td></td><tr></tr><a></a>')] |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
else{ |
|
55
|
|
|
$lastId= DB::table('messages')->insertGetId( |
|
56
|
|
|
['message' => strip_tags(preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', Input::get('body')),'<img></img><img /><p></p><br/><br><span></span></code><code><table><td></td><tr></tr><a></a>')] |
|
57
|
|
|
);} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* if personal flag is set to true insert into personal conversations |
|
62
|
|
|
* |
|
63
|
|
|
*/ |
|
64
|
|
|
if($isPersonalSet){ |
|
65
|
|
|
$teamChannelId=explode("_",Input::get('channelId')); |
|
66
|
|
|
|
|
67
|
|
|
DB::table('personal_conversations')->insert( |
|
68
|
|
|
['team_channel_id' => $teamChannelId[1], 'to_user_id' => Input::get('toUserId'),'from_user_id' => Auth::user()->id,'message_id' => $lastId,'read_status'=>1] |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
else{ |
|
72
|
|
|
DB::table('team_conversations')->insert( |
|
73
|
|
|
['team_channel_id' => Input::get('channelId'), 'user_id' => Input::get('userId'),'message_id' => $lastId] |
|
74
|
|
|
); |
|
75
|
|
|
$this->insertIntoTeamConversationReadStatus(Input::get('channelId'),$lastId); |
|
76
|
|
|
} |
|
77
|
|
|
// Publish Data To Redis |
|
78
|
|
|
|
|
79
|
|
|
if($isPersonalSet){ |
|
80
|
|
|
$data = array( |
|
81
|
|
|
'room' => Input::get('channelId'), |
|
82
|
|
|
'message' => array( 'body' => Input::get('body'),'to_channel_id'=>Auth::user()->id."_".$teamChannelId[1], 'user_id' => Auth::user()->id,'first_name'=> Session::get('firstName'),'last_name'=> Session::get('lastName'),'profile_pic'=> Session::get('profilePic'),'message_id'=>$lastId ,'to_user_id'=>Input::get('toUserId')) |
|
|
|
|
|
|
83
|
|
|
); |
|
84
|
|
|
Event::fire(ChatMessagesEventHandler::EVENT, array(json_encode($data))); |
|
85
|
|
|
} |
|
86
|
|
|
else{ |
|
87
|
|
|
$data = array( |
|
88
|
|
|
'room' => Input::get('channelId'), |
|
89
|
|
|
'message' => array( 'body' => Input::get('body'), 'user_id' => Input::get('userId'),'first_name'=> Session::get('firstName'),'last_name'=> Session::get('lastName'),'profile_pic'=> Session::get('profilePic'),'team_encoded_id'=> Input::get('channelId'),'team_decoded_id'=> $team_decoded_id['id'],'message_id'=>$lastId) |
|
90
|
|
|
); |
|
91
|
|
|
Event::fire(ChatConversationsEventHandler::EVENT, array(json_encode($data))); |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
return Response::json([ |
|
|
|
|
|
|
95
|
|
|
'success' => true, |
|
96
|
|
|
'result' => $data |
|
97
|
|
|
]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
function insertIntoTeamConversationReadStatus($channelId,$messageId){ |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
$teamId = DB::table('team_channels') |
|
103
|
|
|
->select('id') |
|
104
|
|
|
|
|
105
|
|
|
->where('team_channel_id', '=', $channelId)->first(); |
|
106
|
|
|
$teamMembers = DB::table('users') |
|
107
|
|
|
->select('users.first_name', 'users.id', 'users.last_name') |
|
108
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id') |
|
109
|
|
|
->where('team_channel_users.team_channel_name_id', '=', $teamId['id'])->get(); |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
foreach ($teamMembers as $memeber) { |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
if ($memeber['id'] != Session::get('userId')) |
|
116
|
|
|
DB::table('team_conversations_read_status')->insert( |
|
117
|
|
|
['team_channel_id' => $teamId['id'], 'message_id' => $messageId,'user_id' => $memeber['id']] |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
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