Skip to content

Sprint 14 #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"jaguarjs-jsdoc": "^1.0.1",
"jasmine": "^2.5.2",
"jasmine-core": "^2.6.0",
"jquery-custom": "^1.1.1",
"jsdoc": "^3.5.5",
"jshint": "^2.9.3",
"jshint-stylish": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion quickblox.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions samples/chat/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@
margin: 0 0 16px 0;
}

.message__wrap.m-notification_message {
display: block;
.message__wrap .m-notification_message {
width: 100%;
color: #778594;
font-size: 13px;
font-weight: 500;
Expand Down
12 changes: 8 additions & 4 deletions samples/chat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ <h2 class="dashboard__title"><%- user.user_tags %></h2>
<button class="open_sidebar j-open_sidebar"></button>
<h1 class="dialog__title j-dialog__title"><%- title %></h1>
<div class="action_links">
<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>
<a href="#" class="quit_fom_dialog_link j-quit_fom_dialog_link <% type === 1 ? print('hidden') : ''%>"><i class="material-icons">delete</i></a>
<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>
<a href="#" class="quit_fom_dialog_link j-quit_fom_dialog_link <% type === 1 ? print('hidden') : ''%>" data-dialog="<%- _id %>">
<i class="material-icons">delete</i>
</a>
</div>
</div>
<div class="notifications j-notifications hidden"></div>
Expand Down Expand Up @@ -238,8 +242,8 @@ <h1 class="dialog__title j-dialog__title"><%- title %></h1>
</script>

<script type="text/template" id="tpl_notificationMessage">
<div class="message__wrap m-notification_message" id="<%= _id %>">
<%= message || body %>
<div class="message__wrap" id="<%= id %>">
<p class="m-notification_message"><%= text %></p>
</div>
</script>

Expand Down
7 changes: 6 additions & 1 deletion samples/chat/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ App.prototype.renderDashboard = function (activeTabName) {

logoutBtn.addEventListener('click', function () {
QB.users.delete(app.user.id, function(err, user){
if (!user) {
if (err) {
console.error('Can\'t delete user by id: '+app.user.id+' ', err);

return false;
}

loginModule.isLogin = false;
app.isDashboardLoaded = false;

localStorage.removeItem('user');
helpers.clearCache();

QB.chat.disconnect();

router.navigate('#!/login');
});
});
Expand Down
31 changes: 19 additions & 12 deletions samples/chat/js/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ Dialog.prototype.renderMessages = function (dialogId) {
self.sidebar.classList.add('active');
}.bind(self));

self.quitLink.addEventListener('click', function(e){
e.preventDefault();
messageModule.init();

self.quitLink.addEventListener('click', function(e) {
e.preventDefault();
if(dialog.type === CONSTANTS.DIALOG_TYPES.PUBLICCHAT) return;
self.quitFromTheDialog(dialogId)
self.quitFromTheDialog(this.dataset.dialog);
});

messageModule.init();
} else {
if (self.prevDialogId) {
messageModule.sendStopTypingStatus(self.prevDialogId);
Expand All @@ -252,9 +252,11 @@ Dialog.prototype.renderMessages = function (dialogId) {
}
}

self.editLink.href = '#!/dialog/' + self.dialogId + '/edit';
self.quitLink.dataset.dialog = dialogId;

if(dialog.type === CONSTANTS.DIALOG_TYPES.GROUPCHAT){
self.editLink.classList.remove('hidden');
self.editLink.href = '#!/dialog/' + self.dialogId + '/edit';
} else {
self.editLink.classList.add('hidden');
}
Expand Down Expand Up @@ -329,14 +331,19 @@ Dialog.prototype.createDialog = function (params) {
if (err) {
console.error(err);
} else {
var id = createdDialog._id;
var occupants = createdDialog.occupants_ids,
var occupants_names = [],
id = createdDialog._id,
occupants = createdDialog.occupants_ids,
message_body = (app.user.name || app.user.login) + ' created new dialog with: ';

_.each(occupants, function (occupantId) {
message_body += (userModule._cache[occupantId].name || userModule._cache[occupantId].login) + " ";
var occupant_name = userModule._cache[occupantId].name || userModule._cache[occupantId].login;

occupants_names.push(occupant_name);
});

message_body += occupants_names.join(', ');

var systemMessage = {
extension: {
notification_type: 1,
Expand Down Expand Up @@ -461,7 +468,7 @@ Dialog.prototype.updateDialog = function (updates) {
if(updates.title !== dialog.name){
toUpdateParams.name = updates.title;
updatedMsg.extension.dialog_name = updates.title;
updatedMsg.body = app.user.name + ' changed the conversation name to "' + updates.title + '".'
updatedMsg.body = app.user.name + ' changed the conversation name to "' + updates.title + '".';
}
}

Expand All @@ -479,7 +486,7 @@ Dialog.prototype.updateDialog = function (updates) {

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

updatedMsg.body = app.user.name + ' adds ' + usernames.join(',') + ' to the conversation.';
updatedMsg.body = app.user.name + ' adds ' + usernames.join(', ') + ' to the conversation.';
updatedMsg.extension.occupants_ids_added = newUsers.join(',');
} else {
router.navigate('/dialog/' + dialogId);
Expand Down Expand Up @@ -531,7 +538,7 @@ Dialog.prototype.updateDialog = function (updates) {

_.each(users, function(user){
QB.chat.sendSystemMessage(+user, msg);
})
});
}
};

Expand Down
22 changes: 12 additions & 10 deletions samples/chat/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ Helpers.prototype.fillMessagePrams = function (message) {
if (message.message === CONSTANTS.ATTACHMENT.BODY) {
message.message = '';
}

if(!selfDelevered){
messageModule.sendDeliveredStatus(message._id, message.sender_id, message.chat_dialog_id);
};
}

message.selfReaded = selfReaded;

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

Helpers.prototype.fillMessageBody = function (str) {
var url, url_text,
URL_REGEXP = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
var self = this,
url,
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;

str = escapeHTML(str);
str = self.escapeHTML(str);

// parser of paragraphs
str = str.replace(/\n/g, '<br>');
// parser of links
str = str.replace(URL_REGEXP, function(match) {
url = (/^[a-z]+:/i).test(match) ? match : 'http://' + match;
url_text = match;
return '<a href="' + escapeHTML(url) + '" target="_blank">' + escapeHTML(url_text) + '</a>';
url = (/^[a-z]+:/i).test(match) ? match : 'https://' + match;

return '<a href="' + self.escapeHTML(url) + '" target="_blank">' + self.escapeHTML(match) + '</a>';
});

return str;
};

function escapeHTML(s) {
return s.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
Helpers.prototype.escapeHTML = function (str) {
return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
};

Helpers.prototype.getSrcFromAttachmentId = function (id) {
Expand Down
9 changes: 7 additions & 2 deletions samples/chat/js/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ Listeners.prototype.onNotificationMessage = function(userId, message){
msg = helpers.fillNewMessageParams(userId, message),
dialog = dialogModule._cache[message.dialog_id],
extension = message.extension,
dialogId = message.dialog_id;
dialogId = message.dialog_id,
occupantsIdsAdded = extension.occupants_ids_added && extension.occupants_ids_added.split(',');

if(extension.notification_type === CONSTANTS.NOTIFICATION_TYPES.UPDATE_DIALOG){
if (extension.occupants_ids_removed) {
dialogModule._cache[dialogId].users = dialogModule._cache[dialogId].users.filter(function(user){
return user !== userId;
});
} else if(extension.occupants_ids_added) {
dialog.users.push(userId);
_.each(occupantsIdsAdded, function(userId) {
if (dialog.users.indexOf(+userId) === -1) {
dialog.users.push(+userId);
}
});
} else if(extension.dialog_name){
dialog.name = extension.dialog_name;
dialogModule.updateDialogUi(dialogId, extension.dialog_name);
Expand Down
3 changes: 2 additions & 1 deletion samples/chat/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ Login.prototype.login = function (user) {
reject(error);
}
});

};

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

app.page.innerHTML = helpers.fillTemplate('tpl_login', {
version: QB.version
version: QB.version + ':' + QB.buildNumber
});
this.isLoginPageRendered = true;
this.setListeners();
Expand Down
18 changes: 11 additions & 7 deletions samples/chat/js/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ Message.prototype.getMessages = function (dialogId) {
self.container.classList.add('loading');

QB.chat.message.list(params, function (err, messages) {
if (!err) {
if (messages) {
var dialog = dialogModule._cache[dialogId];
dialog.messages = dialog.messages.concat(messages.items);

if (messages.items.length < self.limit) {
dialog.full = true;
}
Expand Down Expand Up @@ -266,8 +266,9 @@ Message.prototype.sendReadStatus = function(messageId, userId, dialogId){
Message.prototype.renderMessage = function (message, setAsFirst) {
var self = this,
sender = userModule._cache[message.sender_id],
dialogId = message.chat_dialog_id,
messagesHtml,
dialogId = message.chat_dialog_id;
messageText;

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

if(message.notification_type || (message.extension && message.extension.notification_type)) {
messagesHtml = helpers.fillTemplate('tpl_notificationMessage', message);
messageText = message.message ? helpers.escapeHTML(message.message) : helpers.escapeHTML(message.body);

messagesHtml = helpers.fillTemplate('tpl_notificationMessage', {
id: message._id,
text: messageText
});
} else {
var messageText = message.message ?
helpers.fillMessageBody(message.message || '') :
helpers.fillMessageBody(message.body || '');
messageText = message.message ? helpers.fillMessageBody(message.message || '') : helpers.fillMessageBody(message.body || '');

messagesHtml = helpers.fillTemplate('tpl_message', {
message: {
Expand Down
7 changes: 4 additions & 3 deletions samples/chat/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ router.on({
var userItem = JSON.parse(JSON.stringify(user));

userItem.selected = dialogOccupants.indexOf(userItem.id) !== -1;

return userItem;
});

Expand All @@ -197,15 +198,15 @@ router.on({
if(elem.classList.contains('disabled')) return;
if(elem.classList.contains('selected')){
elem.classList.remove('selected');
newUsersCount--
newUsersCount--;
} else {
elem.classList.add('selected');
newUsersCount++
newUsersCount++;
}

counterElem.innerText = newUsersCount;

addUsersBtn.disabled = !newUsersCount
addUsersBtn.disabled = !newUsersCount;
});

userList.appendChild(userElem);
Expand Down
2 changes: 1 addition & 1 deletion samples/chat/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ User.prototype.getUsers = function () {

resolve(userList);
});
})
});
};

User.prototype.buildUserItem = function (user) {
Expand Down
13 changes: 9 additions & 4 deletions samples/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ <h2 class="panel__title">Create a new place</h2>
<input id="latlng" type="hidden" value={{latLng}}>

<div class="form_item">
<input id="title" class="inp" type="text" required placeholder="Place name" maxlength="40">
<input id="title" class="inp" type="text" required pattern="[A-Za-z\s]{4,40}" title="Only latin from 4 to 40 symbols" placeholder="Place name">
</div>

<div class="form_item">
<input id="description" class="inp" type="text" required placeholder="Description" maxlength="80">
<input id="description" class="inp" type="text" required pattern="[A-Za-z\s]{4,80}" title="Only latin from 4 to 80 symbols" placeholder="Description" >
</div>

<div class="form_item">
<label for="rate">Rate</label>
<input id="rate" class="inp" type="number" min="0" max="5" step="0.1" value="0" required>
<input id="rate" class="inp" type="number" min="0" max="5" step="0.1" value="5" required>
</div>

<div class="form_item" class="form_item form_item-media">
Expand Down Expand Up @@ -227,7 +227,12 @@ <h4 class="form__title">Check in</h4>
<input id="checkin_id" type="hidden" value={{id}}>

<div class="form_item">
<input id="checkin_comment" class="inp" type="text" required placeholder="Enter your comment" maxlength="40" required>
<input id="checkin_comment" class="inp"
type="text"
placeholder="Enter your comment"
pattern="[A-Za-z\s]{4,40}"
title="Only latin from 4 to 40 symbols"
required>
</div>

<div class="form_item">
Expand Down
Loading