Skip to content

Commit 30594e6

Browse files
Vladlukhanindimaspirit
authored andcommitted
Fixes for chat sample
1 parent caedd2b commit 30594e6

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

samples/chat/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ <h2 class="dashboard__title"><%- user.user_tags %></h2>
146146
<button class="open_sidebar j-open_sidebar"></button>
147147
<h1 class="dialog__title j-dialog__title"><%- title %></h1>
148148
<div class="action_links">
149-
<a href="#!/dialog/<%- _id %>/edit" class="add_to_dialog j-add_to_dialog <% type !== 2 ? print('hidden') : ''%>"><i class="material-icons">person_add</i></a>
150-
<a href="#" class="quit_fom_dialog_link j-quit_fom_dialog_link <% type === 1 ? print('hidden') : ''%>"><i class="material-icons">delete</i></a>
149+
<a href="#!/dialog/<%- _id %>/edit" class="add_to_dialog j-add_to_dialog <% type !== 2 ? print('hidden') : ''%>">
150+
<i class="material-icons">person_add</i>
151+
</a>
152+
<a href="#" class="quit_fom_dialog_link j-quit_fom_dialog_link <% type === 1 ? print('hidden') : ''%>" data-dialog="<%- _id %>">
153+
<i class="material-icons">delete</i>
154+
</a>
151155
</div>
152156
</div>
153157
<div class="notifications j-notifications hidden"></div>

samples/chat/js/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ App.prototype.renderDashboard = function (activeTabName) {
5858

5959
logoutBtn.addEventListener('click', function () {
6060
QB.users.delete(app.user.id, function(err, user){
61-
if (!user) {
61+
if (err) {
6262
console.error('Can\'t delete user by id: '+app.user.id+' ', err);
63-
63+
6464
return false;
6565
}
6666

@@ -69,7 +69,9 @@ App.prototype.renderDashboard = function (activeTabName) {
6969

7070
localStorage.removeItem('user');
7171
helpers.clearCache();
72+
7273
QB.chat.disconnect();
74+
7375
router.navigate('#!/login');
7476
});
7577
});

samples/chat/js/dialog.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ Dialog.prototype.renderMessages = function (dialogId) {
227227
}.bind(self));
228228

229229
messageModule.init();
230+
231+
self.quitLink.addEventListener('click', function(e) {
232+
e.preventDefault();
233+
if(dialog.type === CONSTANTS.DIALOG_TYPES.PUBLICCHAT) return;
234+
self.quitFromTheDialog(this.dataset.dialog);
235+
});
230236
} else {
231237
if (self.prevDialogId) {
232238
messageModule.sendStopTypingStatus(self.prevDialogId);
@@ -246,9 +252,11 @@ Dialog.prototype.renderMessages = function (dialogId) {
246252
}
247253
}
248254

255+
self.editLink.href = '#!/dialog/' + self.dialogId + '/edit';
256+
self.quitLink.dataset.dialog = dialogId;
257+
249258
if(dialog.type === CONSTANTS.DIALOG_TYPES.GROUPCHAT){
250259
self.editLink.classList.remove('hidden');
251-
self.editLink.href = '#!/dialog/' + self.dialogId + '/edit';
252260
} else {
253261
self.editLink.classList.add('hidden');
254262
}
@@ -262,12 +270,6 @@ Dialog.prototype.renderMessages = function (dialogId) {
262270
helpers.clearView(self.messagesContainer);
263271
helpers.clearView(self.attachmentsPreviewContainer);
264272
document.forms.send_message.attach_file.value = null;
265-
266-
self.quitLink.onclick = function(e){
267-
e.preventDefault();
268-
if(dialog.type === CONSTANTS.DIALOG_TYPES.PUBLICCHAT) return;
269-
self.quitFromTheDialog(dialogId);
270-
};
271273
}
272274

273275
messageModule.setLoadMoreMessagesListener();
@@ -484,7 +486,7 @@ Dialog.prototype.updateDialog = function (updates) {
484486

485487
self._cache[dialogId].users = self._cache[dialogId].users.concat(newUsers);
486488

487-
updatedMsg.body = app.user.name + ' adds ' + usernames.join(',') + ' to the conversation.';
489+
updatedMsg.body = app.user.name + ' adds ' + usernames.join(', ') + ' to the conversation.';
488490
updatedMsg.extension.occupants_ids_added = newUsers.join(',');
489491
} else {
490492
router.navigate('/dialog/' + dialogId);
@@ -536,7 +538,7 @@ Dialog.prototype.updateDialog = function (updates) {
536538

537539
_.each(users, function(user){
538540
QB.chat.sendSystemMessage(+user, msg);
539-
})
541+
});
540542
}
541543
};
542544

0 commit comments

Comments
 (0)