|
@@ -13,15 +13,16 @@
|
|
"converse-chatboxes",
|
|
"converse-chatboxes",
|
|
"emojione",
|
|
"emojione",
|
|
"xss",
|
|
"xss",
|
|
|
|
+ "tpl!action",
|
|
"tpl!chatbox",
|
|
"tpl!chatbox",
|
|
"tpl!chatbox_head",
|
|
"tpl!chatbox_head",
|
|
- "tpl!new_day",
|
|
|
|
- "tpl!action",
|
|
|
|
"tpl!emojis",
|
|
"tpl!emojis",
|
|
- "tpl!message",
|
|
|
|
"tpl!help_message",
|
|
"tpl!help_message",
|
|
- "tpl!toolbar",
|
|
|
|
- "tpl!spinner"
|
|
|
|
|
|
+ "tpl!info",
|
|
|
|
+ "tpl!message",
|
|
|
|
+ "tpl!new_day",
|
|
|
|
+ "tpl!spinner",
|
|
|
|
+ "tpl!toolbar"
|
|
], factory);
|
|
], factory);
|
|
}(this, function (
|
|
}(this, function (
|
|
$,
|
|
$,
|
|
@@ -29,15 +30,16 @@
|
|
dummy,
|
|
dummy,
|
|
emojione,
|
|
emojione,
|
|
xss,
|
|
xss,
|
|
|
|
+ tpl_action,
|
|
tpl_chatbox,
|
|
tpl_chatbox,
|
|
tpl_chatbox_head,
|
|
tpl_chatbox_head,
|
|
- tpl_new_day,
|
|
|
|
- tpl_action,
|
|
|
|
tpl_emojis,
|
|
tpl_emojis,
|
|
- tpl_message,
|
|
|
|
tpl_help_message,
|
|
tpl_help_message,
|
|
- tpl_toolbar,
|
|
|
|
- tpl_spinner
|
|
|
|
|
|
+ tpl_info,
|
|
|
|
+ tpl_message,
|
|
|
|
+ tpl_new_day,
|
|
|
|
+ tpl_spinner,
|
|
|
|
+ tpl_toolbar
|
|
) {
|
|
) {
|
|
"use strict";
|
|
"use strict";
|
|
const { $msg, Backbone, Strophe, _, b64_sha1, moment } = converse.env;
|
|
const { $msg, Backbone, Strophe, _, b64_sha1, moment } = converse.env;
|
|
@@ -321,9 +323,7 @@
|
|
afterMessagesFetched () {
|
|
afterMessagesFetched () {
|
|
this.insertIntoDOM();
|
|
this.insertIntoDOM();
|
|
this.scrollDown();
|
|
this.scrollDown();
|
|
- // We only start listening for the scroll event after
|
|
|
|
- // cached messages have been fetched
|
|
|
|
- this.$content.on('scroll', this.markScrolled.bind(this));
|
|
|
|
|
|
+ this.content.addEventListener('scroll', this.markScrolled.bind(this));
|
|
_converse.emit('afterMessagesFetched', this);
|
|
_converse.emit('afterMessagesFetched', this);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -349,18 +349,21 @@
|
|
},
|
|
},
|
|
|
|
|
|
clearStatusNotification () {
|
|
clearStatusNotification () {
|
|
- this.$content.find('div.chat-event').remove();
|
|
|
|
|
|
+ u.removeElement(this.content.querySelector('div.chat-event'));
|
|
},
|
|
},
|
|
|
|
|
|
showStatusNotification (message, keep_old, permanent) {
|
|
showStatusNotification (message, keep_old, permanent) {
|
|
if (!keep_old) {
|
|
if (!keep_old) {
|
|
this.clearStatusNotification();
|
|
this.clearStatusNotification();
|
|
}
|
|
}
|
|
- const $el = $('<div class="chat-info"></div>').text(message);
|
|
|
|
- if (!permanent) {
|
|
|
|
- $el.addClass('chat-event');
|
|
|
|
- }
|
|
|
|
- this.content.insertAdjacentElement('beforeend', $el[0]);
|
|
|
|
|
|
+ this.content.insertAdjacentHTML(
|
|
|
|
+ 'beforeend',
|
|
|
|
+ tpl_info({
|
|
|
|
+ 'extra_classes': !permanent ? 'chat-event' : '',
|
|
|
|
+ 'message': message,
|
|
|
|
+ 'isodate': moment().format(),
|
|
|
|
+ 'data': ''
|
|
|
|
+ }));
|
|
this.scrollDown();
|
|
this.scrollDown();
|
|
},
|
|
},
|
|
|
|
|
|
@@ -391,8 +394,8 @@
|
|
* (String) date - An ISO8601 date string.
|
|
* (String) date - An ISO8601 date string.
|
|
*/
|
|
*/
|
|
const day_date = moment(date).startOf('day');
|
|
const day_date = moment(date).startOf('day');
|
|
- const insert = prepend ? this.$content.prepend: this.$content.append;
|
|
|
|
- insert.call(this.$content, tpl_new_day({
|
|
|
|
|
|
+ const insert = prepend ? $(this.content).prepend: $(this.content).append;
|
|
|
|
+ insert.call($(this.content), tpl_new_day({
|
|
isodate: day_date.format(),
|
|
isodate: day_date.format(),
|
|
datestring: day_date.format("dddd MMM Do YYYY")
|
|
datestring: day_date.format("dddd MMM Do YYYY")
|
|
}));
|
|
}));
|
|
@@ -406,9 +409,9 @@
|
|
* Parameters:
|
|
* Parameters:
|
|
* (Object) attrs: An object containing the message attributes.
|
|
* (Object) attrs: An object containing the message attributes.
|
|
*/
|
|
*/
|
|
- const insert = prepend ? this.$content.prepend : this.$content.append;
|
|
|
|
|
|
+ const insert = prepend ? $(this.content).prepend : $(this.content).append;
|
|
_.flow(($el) => {
|
|
_.flow(($el) => {
|
|
- insert.call(this.$content, $el);
|
|
|
|
|
|
+ insert.call($(this.content), $el);
|
|
return $el;
|
|
return $el;
|
|
},
|
|
},
|
|
this.scrollDown.bind(this)
|
|
this.scrollDown.bind(this)
|
|
@@ -428,8 +431,8 @@
|
|
* attributes.
|
|
* attributes.
|
|
*/
|
|
*/
|
|
let current_msg_date = moment(attrs.time) || moment;
|
|
let current_msg_date = moment(attrs.time) || moment;
|
|
- const $first_msg = this.$content.find('.chat-message:first'),
|
|
|
|
- first_msg_date = $first_msg.data('isodate');
|
|
|
|
|
|
+ const first_msg_el = this.content.firstElementChild,
|
|
|
|
+ first_msg_date = first_msg_el ? first_msg_el.getAttribute('data-isodate') : null;
|
|
|
|
|
|
if (!first_msg_date) {
|
|
if (!first_msg_date) {
|
|
// This is the first received message, so we insert a
|
|
// This is the first received message, so we insert a
|
|
@@ -439,7 +442,8 @@
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- const last_msg_date = this.$content.find('.chat-message:last').data('isodate');
|
|
|
|
|
|
+ const last_msg_el = this.content.lastElementChild,
|
|
|
|
+ last_msg_date = last_msg_el.getAttribute('data-isodate');
|
|
if (current_msg_date.isAfter(last_msg_date) ||
|
|
if (current_msg_date.isAfter(last_msg_date) ||
|
|
current_msg_date.isSame(last_msg_date)) {
|
|
current_msg_date.isSame(last_msg_date)) {
|
|
// The new message is after the last message
|
|
// The new message is after the last message
|
|
@@ -466,17 +470,18 @@
|
|
}
|
|
}
|
|
// Find the correct place to position the message
|
|
// Find the correct place to position the message
|
|
current_msg_date = current_msg_date.format();
|
|
current_msg_date = current_msg_date.format();
|
|
- const msg_dates = _.map(
|
|
|
|
- this.$content.find('.chat-message'),
|
|
|
|
- (el) => $(el).data('isodate')
|
|
|
|
- );
|
|
|
|
|
|
+ const msg_dates = _.invokeMap(
|
|
|
|
+ this.content.querySelector('.message'),
|
|
|
|
+ Element.prototype.getAttribute,
|
|
|
|
+ 'data-isodate'
|
|
|
|
+ )
|
|
msg_dates.push(current_msg_date);
|
|
msg_dates.push(current_msg_date);
|
|
msg_dates.sort();
|
|
msg_dates.sort();
|
|
|
|
|
|
const idx = msg_dates.indexOf(current_msg_date)-1;
|
|
const idx = msg_dates.indexOf(current_msg_date)-1;
|
|
- const $latest_message = this.$content.find(`.chat-message[data-isodate="${msg_dates[idx]}"]:last`);
|
|
|
|
|
|
+ const latest_msg_el = this.content.querySelector(`.message[data-isodate="${msg_dates[idx]}"]`);
|
|
_.flow(($el) => {
|
|
_.flow(($el) => {
|
|
- $el.insertAfter($latest_message);
|
|
|
|
|
|
+ $el.insertAfter(latest_msg_el);
|
|
return $el;
|
|
return $el;
|
|
},
|
|
},
|
|
this.scrollDown.bind(this)
|
|
this.scrollDown.bind(this)
|
|
@@ -524,7 +529,7 @@
|
|
template = tpl_message;
|
|
template = tpl_message;
|
|
username = attrs.sender === 'me' && __('me') || fullname;
|
|
username = attrs.sender === 'me' && __('me') || fullname;
|
|
}
|
|
}
|
|
- this.$content.find('div.chat-event').remove();
|
|
|
|
|
|
+ $(this.content).find('div.chat-event').remove();
|
|
|
|
|
|
if (text.length > 8000) {
|
|
if (text.length > 8000) {
|
|
text = text.substring(0, 10) + '...';
|
|
text = text.substring(0, 10) + '...';
|
|
@@ -564,9 +569,9 @@
|
|
);
|
|
);
|
|
});
|
|
});
|
|
if (spinner === true) {
|
|
if (spinner === true) {
|
|
- this.$content.append(tpl_spinner);
|
|
|
|
|
|
+ $(this.content).append(tpl_spinner);
|
|
} else if (spinner === false) {
|
|
} else if (spinner === false) {
|
|
- this.$content.find('span.spinner').remove();
|
|
|
|
|
|
+ $(this.content).find('span.spinner').remove();
|
|
}
|
|
}
|
|
return this.scrollDown();
|
|
return this.scrollDown();
|
|
},
|
|
},
|
|
@@ -589,7 +594,7 @@
|
|
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
|
|
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
|
|
}
|
|
}
|
|
} else if (_.includes([_converse.INACTIVE, _converse.ACTIVE], message.get('chat_state'))) {
|
|
} else if (_.includes([_converse.INACTIVE, _converse.ACTIVE], message.get('chat_state'))) {
|
|
- this.$content.find('div.chat-event').remove();
|
|
|
|
|
|
+ $(this.content).find('div.chat-event').remove();
|
|
} else if (message.get('chat_state') === _converse.GONE) {
|
|
} else if (message.get('chat_state') === _converse.GONE) {
|
|
this.showStatusNotification(message.get('fullname')+' '+__('has gone away'));
|
|
this.showStatusNotification(message.get('fullname')+' '+__('has gone away'));
|
|
}
|
|
}
|
|
@@ -620,9 +625,16 @@
|
|
},
|
|
},
|
|
|
|
|
|
handleErrorMessage (message) {
|
|
handleErrorMessage (message) {
|
|
- const $message = $(`[data-msgid=${message.get('msgid')}]`);
|
|
|
|
- if ($message.length) {
|
|
|
|
- $message.after($('<div class="chat-info chat-error"></div>').text(message.get('message')));
|
|
|
|
|
|
+ const message_el = this.content.querySelector(`[data-msgid="${message.get('msgid')}"]`);
|
|
|
|
+ if (!_.isNull(message_el)) {
|
|
|
|
+ message_el.insertAdjacentHTML(
|
|
|
|
+ 'afterend',
|
|
|
|
+ tpl_info({
|
|
|
|
+ 'extra_classes': 'chat-error',
|
|
|
|
+ 'message': message.get('message'),
|
|
|
|
+ 'isodate': moment().format(),
|
|
|
|
+ 'data': ''
|
|
|
|
+ }));
|
|
this.scrollDown();
|
|
this.scrollDown();
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -799,7 +811,7 @@
|
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
|
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
|
const result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
|
|
const result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
|
|
if (result === true) {
|
|
if (result === true) {
|
|
- this.$content.empty();
|
|
|
|
|
|
+ this.content.innerHTML = '';
|
|
this.model.messages.reset();
|
|
this.model.messages.reset();
|
|
this.model.messages.browserStorage._clear();
|
|
this.model.messages.browserStorage._clear();
|
|
}
|
|
}
|
|
@@ -992,8 +1004,8 @@
|
|
}
|
|
}
|
|
let scrolled = true;
|
|
let scrolled = true;
|
|
const is_at_bottom =
|
|
const is_at_bottom =
|
|
- (this.$content.scrollTop() + this.$content.innerHeight()) >=
|
|
|
|
- this.$content[0].scrollHeight-10;
|
|
|
|
|
|
+ ($(this.content).scrollTop() + $(this.content).innerHeight()) >=
|
|
|
|
+ $(this.content)[0].scrollHeight-10;
|
|
|
|
|
|
if (is_at_bottom) {
|
|
if (is_at_bottom) {
|
|
scrolled = false;
|
|
scrolled = false;
|