Skip to content

Commit 4b8e3dd

Browse files
Vladlukhanindimaspirit
authored andcommitted
Fixes for chat sample
The Chat Sample (fixed): QBWEBSDK-616; QBWEBSDK-620; QBWEBSDK-539. The JS SDK (fixed): Updated QB.chat.message.unreadCount() method; Updated QB.chat.dialog.create() method; Updated QB.users.listUsers() method.
1 parent ea21366 commit 4b8e3dd

File tree

12 files changed

+44
-31
lines changed

12 files changed

+44
-31
lines changed

quickblox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/chat/css/dashboard.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@
308308
margin: 0 0 16px 0;
309309
}
310310

311-
.message__wrap.m-notification_message {
312-
display: block;
311+
.message__wrap .m-notification_message {
312+
width: 100%;
313313
color: #778594;
314314
font-size: 13px;
315315
font-weight: 500;

samples/chat/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ <h1 class="dialog__title j-dialog__title"><%- title %></h1>
238238
</script>
239239

240240
<script type="text/template" id="tpl_notificationMessage">
241-
<div class="message__wrap m-notification_message" id="<%= _id %>">
242-
<%= message || body %>
241+
<div class="message__wrap" id="<%= id %>">
242+
<p class="m-notification_message"><%= text %></p>
243243
</div>
244244
</script>
245245

samples/chat/js/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ App.prototype.renderDashboard = function (activeTabName) {
5757
listeners.setListeners();
5858

5959
logoutBtn.addEventListener('click', function () {
60-
QB.users.delete(app.user.id, function(err, user){
61-
if (!user) {
62-
console.error('Can\'t delete user by id: '+app.user.id+' ', err);
60+
QB.logout(function(error, result){
61+
if (error) {
62+
console.error('Logout was unsuccessful', error);
6363
}
64+
6465
loginModule.isLogin = false;
6566
app.isDashboardLoaded = false;
6667

samples/chat/js/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Dialog.prototype.updateDialog = function (updates) {
461461
if(updates.title !== dialog.name){
462462
toUpdateParams.name = updates.title;
463463
updatedMsg.extension.dialog_name = updates.title;
464-
updatedMsg.body = app.user.name + ' changed the conversation name to "' + updates.title + '".'
464+
updatedMsg.body = app.user.name + ' changed the conversation name to "' + updates.title + '".';
465465
}
466466
}
467467

samples/chat/js/helpers.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ Helpers.prototype.fillMessagePrams = function (message) {
136136
if (message.message === CONSTANTS.ATTACHMENT.BODY) {
137137
message.message = '';
138138
}
139+
139140
if(!selfDelevered){
140141
messageModule.sendDeliveredStatus(message._id, message.sender_id, message.chat_dialog_id);
141-
};
142+
}
142143

143144
message.selfReaded = selfReaded;
144145

@@ -163,25 +164,26 @@ Helpers.prototype.getMessageStatus = function(message){
163164
};
164165

165166
Helpers.prototype.fillMessageBody = function (str) {
166-
var url, url_text,
167-
URL_REGEXP = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»]))/gi;
167+
var self = this,
168+
url,
169+
URL_REGEXP = /https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s\^\'\"\<\>\(\)]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s\^\'\"\<\>\(\)]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s\^\'\"\<\>\(\)]{2,}|www\.[a-zA-Z0-9]\.[^\s\^\'\"\<\>\(\)]{2,}/g;
168170

169-
str = escapeHTML(str);
171+
str = self.escapeHTML(str);
170172

171173
// parser of paragraphs
172174
str = str.replace(/\n/g, '<br>');
173175
// parser of links
174176
str = str.replace(URL_REGEXP, function(match) {
175-
url = (/^[a-z]+:/i).test(match) ? match : 'http://' + match;
176-
url_text = match;
177-
return '<a href="' + escapeHTML(url) + '" target="_blank">' + escapeHTML(url_text) + '</a>';
177+
url = (/^[a-z]+:/i).test(match) ? match : 'https://' + match;
178+
179+
return '<a href="' + self.escapeHTML(url) + '" target="_blank">' + self.escapeHTML(match) + '</a>';
178180
});
179181

180182
return str;
183+
};
181184

182-
function escapeHTML(s) {
183-
return s.replace(/</g, "&lt;").replace(/>/g, "&gt;");
184-
}
185+
Helpers.prototype.escapeHTML = function (str) {
186+
return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
185187
};
186188

187189
Helpers.prototype.getSrcFromAttachmentId = function (id) {

samples/chat/js/login.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ Login.prototype.login = function (user) {
101101
reject(error);
102102
}
103103
});
104+
104105
};
105106

106107
Login.prototype.renderLoginPage = function(){
107108
helpers.clearView(app.page);
108109

109110
app.page.innerHTML = helpers.fillTemplate('tpl_login', {
110-
version: QB.version
111+
version: QB.version,
112+
buildNumber: QB.buildNumber
111113
});
112114
this.isLoginPageRendered = true;
113115
this.setListeners();

samples/chat/js/message.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ Message.prototype.getMessages = function (dialogId) {
184184
self.container.classList.add('loading');
185185

186186
QB.chat.message.list(params, function (err, messages) {
187-
if (!err) {
187+
if (messages) {
188188
var dialog = dialogModule._cache[dialogId];
189189
dialog.messages = dialog.messages.concat(messages.items);
190-
190+
191191
if (messages.items.length < self.limit) {
192192
dialog.full = true;
193193
}
@@ -266,8 +266,9 @@ Message.prototype.sendReadStatus = function(messageId, userId, dialogId){
266266
Message.prototype.renderMessage = function (message, setAsFirst) {
267267
var self = this,
268268
sender = userModule._cache[message.sender_id],
269+
dialogId = message.chat_dialog_id,
269270
messagesHtml,
270-
dialogId = message.chat_dialog_id;
271+
messageText;
271272

272273
if(!message.selfReaded){
273274
self.sendReadStatus(message._id, message.sender_id, dialogId);
@@ -276,11 +277,14 @@ Message.prototype.renderMessage = function (message, setAsFirst) {
276277
}
277278

278279
if(message.notification_type || (message.extension && message.extension.notification_type)) {
279-
messagesHtml = helpers.fillTemplate('tpl_notificationMessage', message);
280+
messageText = message.message ? helpers.escapeHTML(message.message) : helpers.escapeHTML(message.body);
281+
282+
messagesHtml = helpers.fillTemplate('tpl_notificationMessage', {
283+
id: message._id,
284+
text: messageText
285+
});
280286
} else {
281-
var messageText = message.message ?
282-
helpers.fillMessageBody(message.message || '') :
283-
helpers.fillMessageBody(message.body || '');
287+
messageText = message.message ? helpers.fillMessageBody(message.message || '') : helpers.fillMessageBody(message.body || '');
284288

285289
messagesHtml = helpers.fillTemplate('tpl_message', {
286290
message: {

src/modules/chat/qbDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DialogProxy.prototype = {
5252
* @callback createDialogCallback
5353
* */
5454

55-
if (params.occupants_ids instanceof Array) {
55+
if (params && params.occupants_ids && Utils.isArray(params.occupants_ids)) {
5656
params.occupants_ids = params.occupants_ids.join(', ');
5757
}
5858

src/modules/chat/qbMessage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ MessageProxy.prototype = {
126126
* @callback unreadCountMessageCallback
127127
* */
128128

129+
if (params && params.chat_dialog_ids && Utils.isArray(params.chat_dialog_ids)) {
130+
params.chat_dialog_ids = params.chat_dialog_ids.join(', ');
131+
}
132+
129133
this.service.ajax({
130134
url: Utils.getUrl(MESSAGES_API_URL + '/unread'),
131135
data: params

src/modules/qbUsers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ UsersProxy.prototype = {
4848
params = {};
4949
}
5050

51-
if (params.filter) {
52-
if (params.filter instanceof Array) {
51+
if (params && params.filter) {
52+
if (Utils.isArray(params.filter)) {
5353
params.filter.forEach(function(el) {
5454
item = generateFilter(el);
5555
filters.push(item);

src/qbConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
var config = {
1515
version: '2.8.0',
16-
buildNumber: '1055',
16+
buildNumber: '1058',
1717
creds: {
1818
appId: '',
1919
authKey: '',

0 commit comments

Comments
 (0)