Skip to content

Commit 676a0a6

Browse files
author
Igor Khomenko
committed
fixed issues in Cordova text chat code sample
1 parent cf1abbd commit 676a0a6

File tree

26 files changed

+375
-298
lines changed

26 files changed

+375
-298
lines changed

samples/chat/index.html

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<span class="sr-only">Toggle navigation</span>
1818
<span class="glyphicon glyphicon-cog"></span>
1919
</button>
20-
20+
2121
<a href="https://quickblox.com/developers/Chat">
2222
<img src="images/logo-quickblox.png" id="logo">
2323
</a>
@@ -51,48 +51,52 @@
5151
<div class="panel panel-primary">
5252
<div class="panel-body">
5353
<div class="row">
54+
5455
<div class="col-md-4">
5556
<div class="list-header">
5657
<h4 class="list-header-title">History</h4>
5758
</div>
5859
<div class="list-group pre-scrollable nice-scroll" id="dialogs-list">
59-
<!-- list of chat dialogs will be here -->
60+
61+
<!-- list of chat dialogs will be here -->
62+
6063
</div>
6164
</div>
62-
<div id="mcs_container" class="col-md-8 nice-scroll">
63-
<div class="customScrollBox">
64-
<div class="container del-style">
65-
<div class="content list-group pre-scrollable nice-scroll" id="messages-list">
66-
<!-- list of chat messages will be here -->
67-
</div>
68-
</div>
65+
<div id="mcs_container" class="col-md-8">
66+
<div class="container del-style">
67+
<div class="content list-group pre-scrollable nice-scroll" id="messages-list">
68+
69+
<!-- list of chat messages will be here -->
70+
6971
</div>
70-
<div><img src="images/ajax-loader.gif" class="load-msg"></div>
71-
<form class="form-inline" role="form" method="POST" action="" onsubmit="return submit_handler(this)">
72-
<div class="input-group">
73-
<span class="input-group-btn input-group-btn_change_load">
74-
<input id="load-img" type="file">
75-
<button type="button" id="attach_btn" class="btn btn-default" onclick="$('#load-img').click();">
76-
<i class="icon-photo"></i>
77-
</button>
78-
</span>
79-
<span class="input-group-btn input-group-btn_change_load">
80-
<button type="button" id="stickers_btn" class="btn btn-default" onclick="">
81-
<i class="icon-sticker"></i>
82-
</button>
83-
</span>
84-
85-
<span class="input-group-btn" style="width: 100%;">
86-
<input type="text" class="form-control" id="message_text" placeholder="Enter message">
87-
</span>
88-
89-
<span class="input-group-btn">
90-
<button type="submit" id="send_btn" class="btn btn-default" onclick="clickSendMessage()">Send</button>
91-
</span>
92-
</div>
93-
<img src="images/ajax-loader.gif" id="progress">
94-
</form>
9572
</div>
73+
74+
<div><img src="images/ajax-loader.gif" class="load-msg"></div>
75+
<form class="form-inline" role="form" method="POST" action="" onsubmit="return submit_handler(this)">
76+
<div class="input-group">
77+
<span class="input-group-btn input-group-btn_change_load">
78+
<input id="load-img" type="file">
79+
<button type="button" id="attach_btn" class="btn btn-default" onclick="$('#load-img').click();">
80+
<i class="icon-photo"></i>
81+
</button>
82+
</span>
83+
<span class="input-group-btn input-group-btn_change_load">
84+
<button type="button" id="stickers_btn" class="btn btn-default" onclick="">
85+
<i class="icon-sticker"></i>
86+
</button>
87+
</span>
88+
89+
<span class="input-group-btn" style="width: 100%;">
90+
<input type="text" class="form-control" id="message_text" placeholder="Enter message">
91+
</span>
92+
93+
<span class="input-group-btn">
94+
<button type="submit" id="send_btn" class="btn btn-default" onclick="clickSendMessage()">Send</button>
95+
</span>
96+
</div>
97+
<img src="images/ajax-loader.gif" id="progress">
98+
</form>
99+
</div>
96100
</div>
97101
</div>
98102
</div>

samples/chat/js/messages.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function onMessage(userId, msg) {
3131
if (isMessageForCurrentDialog(userId, msg.dialog_id)){
3232
dialogsMessages.push(msg);
3333

34-
if (msg.markable === 1) {
34+
if (msg.markable === 1 && userId != currentUser.id) {
3535
sendReadStatus(userId, msg.id, msg.dialog_id);
3636
}
3737

@@ -61,10 +61,19 @@ function sendReadStatus(userId, messageId, dialogId) {
6161
}
6262

6363
function onDeliveredStatusListener(messageId) {
64-
$('#delivered_'+messageId).fadeIn(200);
64+
showDeliveredСheckmark(messageId)
6565
}
6666

6767
function onReadStatusListener(messageId) {
68+
showReadСheckmark(messageId)
69+
}
70+
71+
function showDeliveredСheckmark(messageId){
72+
$('#read_'+messageId).fadeOut(100);
73+
$('#delivered_'+messageId).fadeIn(200);
74+
}
75+
76+
function showReadСheckmark(messageId){
6877
$('#delivered_'+messageId).fadeOut(100);
6978
$('#read_'+messageId).fadeIn(200);
7079
}
@@ -123,11 +132,9 @@ function retrieveChatMessages(dialog, beforeDateSent){
123132

124133
// Show delivered statuses
125134
if (item.read_ids.length > 1 && messageSenderId === currentUser.id) {
126-
$('#delivered_'+messageId).fadeOut(100);
127-
$('#read_'+messageId).fadeIn(200);
135+
showReadСheckmark(messageId);
128136
} else if (item.delivered_ids.length > 1 && messageSenderId === currentUser.id) {
129-
$('#delivered_'+messageId).fadeIn(100);
130-
$('#read_'+messageId).fadeOut(200);
137+
showDeliveredСheckmark(messageId);
131138
}
132139

133140
if (i > 5) {$('#messages-list').scrollTop($('#messages-list').prop('scrollHeight'));}
@@ -191,14 +198,14 @@ function sendMessage(text, attachmentFileId) {
191198
},
192199
markable: 1
193200
};
194-
201+
195202
if(attachmentFileId !== null){
196203
msg['extension']['attachments'] = [{id: attachmentFileId, type: 'photo'}];
197204
}
198205

199206
if (currentDialog.type === 3) {
200207
opponentId = QB.chat.helpers.getRecipientId(currentDialog.occupants_ids, currentUser.id);
201-
208+
202209
QB.chat.send(opponentId, msg);
203210

204211
$('.list-group-item.active .list-group-item-text')
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)