Bugfix. markScrolled
wasn't debounced for MUC.
This commit is contained in:
parent
308cbf5fb7
commit
21a46a15ae
|
@ -265,7 +265,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
this.markScrolled = _.debounce(this.markScrolled, 100);
|
this.markScrolled = _.debounce(this._markScrolled, 100);
|
||||||
this.createEmojiPicker();
|
this.createEmojiPicker();
|
||||||
this.model.messages.on('add', this.onMessageAdded, this);
|
this.model.messages.on('add', this.onMessageAdded, this);
|
||||||
this.model.on('show', this.show, this);
|
this.model.on('show', this.show, this);
|
||||||
|
@ -434,9 +434,13 @@
|
||||||
Element.prototype.getAttribute,
|
Element.prototype.getAttribute,
|
||||||
'data-isodate'
|
'data-isodate'
|
||||||
)
|
)
|
||||||
msg_dates.push(cutoff.format());
|
if (_.isObject(cutoff)) {
|
||||||
|
cutoff = cutoff.format();
|
||||||
|
}
|
||||||
|
msg_dates.push(cutoff);
|
||||||
msg_dates.sort();
|
msg_dates.sort();
|
||||||
return msg_dates[msg_dates.indexOf(cutoff)-1];
|
const idx = msg_dates.indexOf(cutoff);
|
||||||
|
return msg_dates[idx === 0 ? idx : idx-1];
|
||||||
},
|
},
|
||||||
|
|
||||||
showMessage (attrs) {
|
showMessage (attrs) {
|
||||||
|
@ -455,7 +459,8 @@
|
||||||
first_msg_el = this.content.firstElementChild,
|
first_msg_el = this.content.firstElementChild,
|
||||||
first_msg_date = first_msg_el ? first_msg_el.getAttribute('data-isodate') : null,
|
first_msg_date = first_msg_el ? first_msg_el.getAttribute('data-isodate') : null,
|
||||||
append_element = _.bind(this.content.insertAdjacentElement, this.content, 'beforeend'),
|
append_element = _.bind(this.content.insertAdjacentElement, this.content, 'beforeend'),
|
||||||
append_html = _.bind(this.content.insertAdjacentHTML, this.content, 'beforeend');
|
append_html = _.bind(this.content.insertAdjacentHTML, this.content, 'beforeend'),
|
||||||
|
prepend_element = _.bind(this.content.insertAdjacentElement, this.content, 'afterbegin');
|
||||||
|
|
||||||
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
|
||||||
|
@ -483,7 +488,6 @@
|
||||||
// We need to prepend the message immediately before the
|
// We need to prepend the message immediately before the
|
||||||
// first message (so that it'll still be after the day
|
// first message (so that it'll still be after the day
|
||||||
// indicator).
|
// indicator).
|
||||||
const prepend_element = _.bind(this.content.insertAdjacentElement, this.content, 'afterbegin');
|
|
||||||
this.insertMessage(attrs, prepend_element);
|
this.insertMessage(attrs, prepend_element);
|
||||||
if (current_msg_date.isBefore(first_msg_date, 'day')) {
|
if (current_msg_date.isBefore(first_msg_date, 'day')) {
|
||||||
// This message is also on a different day, so
|
// This message is also on a different day, so
|
||||||
|
@ -495,8 +499,12 @@
|
||||||
const previous_msg_date = this.getLastMessageDate(current_msg_date);
|
const previous_msg_date = this.getLastMessageDate(current_msg_date);
|
||||||
const previous_msg_el = this.content.querySelector(
|
const previous_msg_el = this.content.querySelector(
|
||||||
`.message[data-isodate="${previous_msg_date}"]`);
|
`.message[data-isodate="${previous_msg_date}"]`);
|
||||||
this.insertMessage(
|
if (_.isNull(previous_msg_el)) {
|
||||||
attrs, _.bind(previous_msg_el.insertAdjacentElement, previous_msg_el, 'afterend'));
|
this.insertMessage(attrs, prepend_element);
|
||||||
|
} else {
|
||||||
|
this.insertMessage(
|
||||||
|
attrs, _.bind(previous_msg_el.insertAdjacentElement, previous_msg_el, 'afterend'));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getExtraMessageTemplateAttributes () {
|
getExtraMessageTemplateAttributes () {
|
||||||
|
@ -617,15 +625,15 @@
|
||||||
|
|
||||||
handleTextMessage (message) {
|
handleTextMessage (message) {
|
||||||
this.showMessage(_.clone(message.attributes));
|
this.showMessage(_.clone(message.attributes));
|
||||||
if (u.isNewMessage(message) && message.get('sender') === 'me') {
|
if (u.isNewMessage(message)) {
|
||||||
// We remove the "scrolled" flag so that the chat area
|
if (message.get('sender') === 'me') {
|
||||||
// gets scrolled down. We always want to scroll down
|
// We remove the "scrolled" flag so that the chat area
|
||||||
// when the user writes a message as opposed to when a
|
// gets scrolled down. We always want to scroll down
|
||||||
// message is received.
|
// when the user writes a message as opposed to when a
|
||||||
this.model.set('scrolled', false);
|
// message is received.
|
||||||
} else {
|
this.model.set('scrolled', false);
|
||||||
if (u.isNewMessage(message) && this.model.get('scrolled', true)) {
|
} else if (this.model.get('scrolled', true)) {
|
||||||
this.$el.find('.new-msgs-indicator').removeClass('hidden');
|
this.showNewMessagesIndicator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.shouldShowOnTextMessage()) {
|
if (this.shouldShowOnTextMessage()) {
|
||||||
|
@ -991,6 +999,10 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showNewMessagesIndicator () {
|
||||||
|
u.showElement(this.el.querySelector('.new-msgs-indicator'));
|
||||||
|
},
|
||||||
|
|
||||||
hideNewMessagesIndicator () {
|
hideNewMessagesIndicator () {
|
||||||
const new_msgs_indicator = this.el.querySelector('.new-msgs-indicator');
|
const new_msgs_indicator = this.el.querySelector('.new-msgs-indicator');
|
||||||
if (!_.isNull(new_msgs_indicator)) {
|
if (!_.isNull(new_msgs_indicator)) {
|
||||||
|
@ -998,7 +1010,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
markScrolled: function (ev) {
|
_markScrolled: function (ev) {
|
||||||
/* Called when the chat content is scrolled up or down.
|
/* Called when the chat content is scrolled up or down.
|
||||||
* We want to record when the user has scrolled away from
|
* We want to record when the user has scrolled away from
|
||||||
* the bottom, so that we don't automatically scroll away
|
* the bottom, so that we don't automatically scroll away
|
||||||
|
@ -1042,14 +1054,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onScrolledDown() {
|
|
||||||
this.hideNewMessagesIndicator();
|
|
||||||
if (_converse.windowState !== 'hidden') {
|
|
||||||
this.model.clearUnreadMsgCounter();
|
|
||||||
}
|
|
||||||
_converse.emit('chatBoxScrolledDown', {'chatbox': this.model});
|
|
||||||
},
|
|
||||||
|
|
||||||
scrollDown () {
|
scrollDown () {
|
||||||
if (_.isUndefined(this.debouncedScrollDown)) {
|
if (_.isUndefined(this.debouncedScrollDown)) {
|
||||||
/* We wrap the method in a debouncer and set it on the
|
/* We wrap the method in a debouncer and set it on the
|
||||||
|
@ -1062,6 +1066,14 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onScrolledDown() {
|
||||||
|
this.hideNewMessagesIndicator();
|
||||||
|
if (_converse.windowState !== 'hidden') {
|
||||||
|
this.model.clearUnreadMsgCounter();
|
||||||
|
}
|
||||||
|
_converse.emit('chatBoxScrolledDown', {'chatbox': this.model});
|
||||||
|
},
|
||||||
|
|
||||||
onWindowStateChanged (state) {
|
onWindowStateChanged (state) {
|
||||||
if (this.model.get('num_unread', 0) && !this.model.newMessageWillBeHidden()) {
|
if (this.model.get('num_unread', 0) && !this.model.newMessageWillBeHidden()) {
|
||||||
this.model.clearUnreadMsgCounter();
|
this.model.clearUnreadMsgCounter();
|
||||||
|
|
|
@ -439,6 +439,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
|
this.markScrolled = _.debounce(this._markScrolled, 100);
|
||||||
|
|
||||||
this.model.messages.on('add', this.onMessageAdded, this);
|
this.model.messages.on('add', this.onMessageAdded, this);
|
||||||
this.model.on('show', this.show, this);
|
this.model.on('show', this.show, this);
|
||||||
this.model.on('destroy', this.hide, this);
|
this.model.on('destroy', this.hide, this);
|
||||||
|
|
18
src/utils.js
18
src/utils.js
|
@ -87,23 +87,29 @@
|
||||||
|
|
||||||
var u = {};
|
var u = {};
|
||||||
|
|
||||||
|
u.removeClass = function (klass, el) {
|
||||||
|
if (!_.isNil(el)) {
|
||||||
|
el.classList.remove(klass);
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
u.removeElement = function (el) {
|
u.removeElement = function (el) {
|
||||||
if (!_.isNil(el) && !_.isNil(el.parentNode)) {
|
if (!_.isNil(el) && !_.isNil(el.parentNode)) {
|
||||||
el.parentNode.removeChild(el);
|
el.parentNode.removeChild(el);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u.showElement = function (el) {
|
u.showElement = _.flow(
|
||||||
if (!_.isNil(el)) {
|
_.partial(u.removeClass, 'collapsed'),
|
||||||
el.classList.remove('collapsed');
|
_.partial(u.removeClass, 'hidden')
|
||||||
el.classList.remove('hidden');
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u.hideElement = function (el) {
|
u.hideElement = function (el) {
|
||||||
if (!_.isNil(el)) {
|
if (!_.isNil(el)) {
|
||||||
el.classList.add('hidden');
|
el.classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
u.nextUntil = function (el, selector, include_self=false) {
|
u.nextUntil = function (el, selector, include_self=false) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user