Skip to content

Commit 6734a22

Browse files
committed
Conversation search added
1 parent 130642a commit 6734a22

File tree

5 files changed

+103
-23
lines changed

5 files changed

+103
-23
lines changed

app/Http/Controllers/KchatController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function kchat(Request $request){
100100
->select('messages.id as mid','messages.created_at as date','messages.id as mid','messages.message', 'messages.type', 'messages.user_id', 'users.first_name', 'users.last_name', 'users.photo', 'lm.*')
101101
->orderBy('messages.id')
102102
->orderBy('conversations.id');
103-
103+
104104
if (session()->has('chat_id')){
105105
$tmp->where('messages.id','>', session()->get('chat_id'));
106106
}
@@ -115,4 +115,18 @@ function kchat(Request $request){
115115

116116
return json_encode($data);
117117
}
118+
119+
function getConvo(Request $request){
120+
121+
$tmp = DB::table('conversations')
122+
->select('conversations.id','conversations.conversation_name', 'conversations.photo', 'conversations.created_at')
123+
->rightJoin('participants', 'participants.conversation_id', '=', 'conversations.id')
124+
->where('participants.user_id', Auth()->user()->id)
125+
->where('conversations.conversation_name', 'like', '%'.$request->convo_like.'%')
126+
->get()
127+
->toArray();
128+
129+
return json_encode($tmp);
130+
131+
}
118132
}

public/js/kchat.msg.js

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ message = '';
33
typing = false;
44
OnLoadMsgs = true;
55
previous = false;
6+
conversation_like = '';
67

78
$(document).ready (function(){
89

@@ -141,6 +142,7 @@ $(document).ready (function(){
141142
}
142143
}
143144

145+
LoadMessage = true;
144146
// Define the function to make the AJAX call
145147
function KChatAjax(){
146148

@@ -167,26 +169,32 @@ $(document).ready (function(){
167169

168170
//console.log(Data);
169171

170-
$.ajax({
171-
type: "POST",
172-
url: '/messages',
173-
data: Data,
174-
success: function(messages){
175-
176-
messages = $.parseJSON(messages);
177-
178-
UpdateConversations(messages);
179-
180-
UpdateMessages(messages);
181-
182-
previous = false;
183-
184-
$('#loading').css('display','none');
185-
},
186-
error: function(result){
187-
188-
}
189-
});
172+
if(LoadMessage){
173+
LoadMessage = false;
174+
$.ajax({
175+
type: "POST",
176+
url: '/messages',
177+
data: Data,
178+
success: function(messages){
179+
180+
messages = $.parseJSON(messages);
181+
182+
UpdateConversations(messages);
183+
184+
UpdateMessages(messages);
185+
186+
previous = false;
187+
188+
$('#loading').css('display','none');
189+
190+
LoadMessage = true;
191+
},
192+
error: function(result){
193+
194+
}
195+
});
196+
}
197+
190198

191199
}
192200

@@ -233,5 +241,40 @@ $(document).ready (function(){
233241
$(this).css('display','none');
234242

235243
});
244+
245+
search_convo = true;
246+
247+
$("#convo_like").keyup(function() {
248+
249+
Search = {};
250+
251+
Search['_token'] = $('meta[name="csrf_token"]').attr('content');
252+
Search['convo_like'] = $(this).val();
253+
254+
if(search_convo){
255+
search_convo = false;
256+
$.ajax({
257+
type: "POST",
258+
url: '/getConvo',
259+
data: Search,
260+
success: function(results){
261+
search_convo = true;
262+
results = $.parseJSON(results);
263+
html = '';
264+
results.forEach(function(element){
265+
html += `<tr>
266+
<td><a href="/messages/?chat=${element.id}" ><img src="${element.photo}" class="rounded-circle my-n1" alt="[Photo]" width="32" height="32"></a></td>
267+
<td><a href="/messages/?chat=${element.id}" >${element.conversation_name}</a></td>
268+
</tr>`
269+
});
270+
$('#ConvoList').html(html);
271+
},
272+
error: function(result){
273+
274+
}
275+
});
276+
}
277+
278+
});
236279

237280
});

resources/views/members.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</div>
4141
</div>
4242
</div>
43-
<h5 class="card-title mb-0">Clients</h5>
43+
<h5 class="card-title mb-0">Member's</h5>
4444
</div>
4545
<div class="card-body">
4646
<script>

resources/views/msg.blade.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="mail-list-container col-md-3 pt-4 pb-4 border-right bg-white height10">
1818
<div class="border-bottom pb-3 px-3">
1919
<div class="form-group">
20-
<input class="form-control w-100" type="search" placeholder="Search mail" id="Mail-rearch">
20+
<input class="form-control w-100" type="search" placeholder="Search Conversation" data-toggle="modal" data-target="#search_conversation" id="Mail-rearch">
2121
</div>
2222
</div>
2323
<ul class="friend-list" id="MessageBox">
@@ -136,6 +136,27 @@
136136
</div>
137137
@endif
138138
</div>
139+
140+
<!-- Modal -->
141+
<div class="modal fade" id="search_conversation" tabindex="-1" role="dialog" aria-labelledby="ModalCenterTitle" aria-hidden="true">
142+
<div class="modal-dialog modal-dialog-centered" role="document">
143+
<div class="modal-content">
144+
<div class="modal-header">
145+
<input type="text" class="form-control" id="convo_like" />
146+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
147+
<span aria-hidden="true">&times;</span>
148+
</button>
149+
</div>
150+
<div class="modal-body" id="search_conversation_results" >
151+
<table id="ConvoList" class="table">
152+
</table>
153+
</div>
154+
<div class="modal-footer">
155+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
156+
</div>
157+
</div>
158+
</div>
159+
</div>
139160
@endsection
140161

141162
@section('script')

routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@
8282
Route::post('/messages', [KchatController::class, 'kchat'])->name('All Json Responses');
8383

8484
Route::post('/messages/update', [MessageController::class, 'UpdateConversation'])->name('Update Conversation');
85+
86+
Route::post('/getConvo', [KchatController::class, 'getConvo'])->name('get Conversations list via search');
8587

8688
});

0 commit comments

Comments
 (0)