Commit 26d3455f authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents dcf87368 2cb4a36a
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
- `hide_open_bookmarks` is now by default `true`. - `hide_open_bookmarks` is now by default `true`.
### UX/UI changes ### UX/UI changes
- #984 Improve loading of archived messages via "infinite scroll"
- Use CSS3 fade transitions to render various elements. - Use CSS3 fade transitions to render various elements.
- Remove `Login` and `Registration` tabs and consolidate into one panel. - Remove `Login` and `Registration` tabs and consolidate into one panel.
- Show validation error messages on the login form. - Show validation error messages on the login form.
......
...@@ -404,7 +404,7 @@ ...@@ -404,7 +404,7 @@
* This element must have a "data-isodate" attribute * This element must have a "data-isodate" attribute
* which specifies its creation date. * which specifies its creation date.
*/ */
const prev_msg_el = this.getPreviousMessageElement(next_msg_el), const prev_msg_el = u.getPreviousElement(next_msg_el, ".message:not(.chat-event)"),
prev_msg_date = _.isNull(prev_msg_el) ? null : prev_msg_el.getAttribute('data-isodate'), prev_msg_date = _.isNull(prev_msg_el) ? null : prev_msg_el.getAttribute('data-isodate'),
next_msg_date = next_msg_el.getAttribute('data-isodate'); next_msg_date = next_msg_el.getAttribute('data-isodate');
...@@ -419,34 +419,6 @@ ...@@ -419,34 +419,6 @@
} }
}, },
isNotPermanentMessage (el) {
return !_.isNull(el) && (u.hasClass('chat-event', el) || !u.hasClass('message', el));
},
getPreviousMessageElement (el) {
let prev_msg_el = el.previousSibling;
while (this.isNotPermanentMessage(prev_msg_el)) {
prev_msg_el = prev_msg_el.previousSibling
}
return prev_msg_el;
},
getLastMessageElement () {
let last_msg_el = this.content.lastElementChild;
while (this.isNotPermanentMessage(last_msg_el)) {
last_msg_el = last_msg_el.previousSibling
}
return last_msg_el;
},
getFirstMessageElement () {
let first_msg_el = this.content.firstElementChild;
while (this.isNotPermanentMessage(first_msg_el)) {
first_msg_el = first_msg_el.nextSibling
}
return first_msg_el;
},
getLastMessageDate (cutoff) { getLastMessageDate (cutoff) {
/* Return the ISO8601 format date of the latest message. /* Return the ISO8601 format date of the latest message.
* *
...@@ -454,12 +426,12 @@ ...@@ -454,12 +426,12 @@
* (Object) cutoff: Moment Date cutoff date. The last * (Object) cutoff: Moment Date cutoff date. The last
* message received cutoff this date will be returned. * message received cutoff this date will be returned.
*/ */
const first_msg = this.getFirstMessageElement(), const first_msg = u.getFirstChildElement(this.content, '.message:not(.chat-event)'),
oldest_date = first_msg ? first_msg.getAttribute('data-isodate') : null; oldest_date = first_msg ? first_msg.getAttribute('data-isodate') : null;
if (!_.isNull(oldest_date) && moment(oldest_date).isAfter(cutoff)) { if (!_.isNull(oldest_date) && moment(oldest_date).isAfter(cutoff)) {
return null; return null;
} }
const last_msg = this.getLastMessageElement(), const last_msg = u.getLastChildElement(this.content, '.message:not(.chat-event)'),
most_recent_date = last_msg ? last_msg.getAttribute('data-isodate') : null; most_recent_date = last_msg ? last_msg.getAttribute('data-isodate') : null;
if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) { if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) {
return most_recent_date; return most_recent_date;
...@@ -511,7 +483,30 @@ ...@@ -511,7 +483,30 @@
} }
this.insertDayIndicator(message_el); this.insertDayIndicator(message_el);
this.clearStatusNotification(); this.clearStatusNotification();
this.scrollDown(); this.setScrollPosition(message_el);
},
setScrollPosition (message_el) {
/* Given a newly inserted message, determine whether we
* should keep the scrollbar in place (so as to not scroll
* up when using infinite scroll).
*/
if (this.model.get('scrolled')) {
const next_msg_el = u.getNextElement(message_el, ".chat-message");
if (next_msg_el) {
// The currently received message is not new, there
// are newer messages after it. So let's see if we
// should maintain our current scroll position.
if (this.content.scrollTop === 0 || this.model.get('top_visible_message')) {
const top_visible_message = this.model.get('top_visible_message') || next_msg_el;
this.model.set('top_visible_message', top_visible_message);
this.content.scrollTop = top_visible_message.offsetTop - 30;
}
}
} else {
this.scrollDown();
}
}, },
getExtraMessageTemplateAttributes () { getExtraMessageTemplateAttributes () {
...@@ -1027,13 +1022,6 @@ ...@@ -1027,13 +1022,6 @@
* received. * received.
*/ */
if (ev && ev.preventDefault) { ev.preventDefault(); } if (ev && ev.preventDefault) { ev.preventDefault(); }
if (this.model.get('auto_scrolled')) {
this.model.set({
'scrolled': false,
'auto_scrolled': false
});
return;
}
let scrolled = true; let scrolled = true;
const is_at_bottom = const is_at_bottom =
(this.content.scrollTop + this.content.clientHeight) >= (this.content.scrollTop + this.content.clientHeight) >=
...@@ -1043,11 +1031,17 @@ ...@@ -1043,11 +1031,17 @@
scrolled = false; scrolled = false;
this.onScrolledDown(); this.onScrolledDown();
} }
u.safeSave(this.model, {'scrolled': scrolled}); u.safeSave(this.model, {
'scrolled': scrolled,
'top_visible_message': null
});
}, },
viewUnreadMessages () { viewUnreadMessages () {
this.model.save('scrolled', false); this.model.save({
'scrolled': false,
'top_visible_message': null
});
this.scrollDown(); this.scrollDown();
}, },
...@@ -1058,8 +1052,6 @@ ...@@ -1058,8 +1052,6 @@
} }
if (u.isVisible(this.content) && !this.model.get('scrolled')) { if (u.isVisible(this.content) && !this.model.get('scrolled')) {
this.content.scrollTop = this.content.scrollHeight; this.content.scrollTop = this.content.scrollHeight;
this.onScrolledDown();
this.model.save({'auto_scrolled': true});
} }
}, },
......
This diff is collapsed.
...@@ -64,16 +64,6 @@ ...@@ -64,16 +64,6 @@
}); });
}; };
function calculateElementHeight (el) {
/* Return the height of the passed in DOM element,
* based on the heights of its children.
*/
return _.reduce(
el.children,
(result, child) => result + child.offsetHeight, 0
);
}
function slideOutWrapup (el) { function slideOutWrapup (el) {
/* Wrapup function for slideOut. */ /* Wrapup function for slideOut. */
el.removeAttribute('data-slider-marker'); el.removeAttribute('data-slider-marker');
...@@ -85,6 +75,48 @@ ...@@ -85,6 +75,48 @@
var u = {}; var u = {};
u.getNextElement = function (el, selector='*') {
let next_el = el.nextElementSibling;
while (!_.isNull(next_el) && !sizzle.matchesSelector(next_el, selector)) {
next_el = next_el.nextElementSibling;
}
return next_el;
}
u.getPreviousElement = function (el, selector='*') {
let prev_el = el.previousSibling;
while (!_.isNull(prev_el) && !sizzle.matchesSelector(prev_el, selector)) {
prev_el = prev_el.previousSibling
}
return prev_el;
}
u.getFirstChildElement = function (el, selector='*') {
let first_el = el.firstElementChild;
while (!_.isNull(first_el) && !sizzle.matchesSelector(first_el, selector)) {
first_el = first_el.nextSibling
}
return first_el;
}
u.getLastChildElement = function (el, selector='*') {
let last_el = el.lastElementChild;
while (!_.isNull(last_el) && !sizzle.matchesSelector(last_el, selector)) {
last_el = last_el.previousSibling
}
return last_el;
}
u.calculateElementHeight = function (el) {
/* Return the height of the passed in DOM element,
* based on the heights of its children.
*/
return _.reduce(
el.children,
(result, child) => result + child.offsetHeight, 0
);
}
u.addClass = function (className, el) { u.addClass = function (className, el) {
if (el instanceof Element) { if (el instanceof Element) {
el.classList.add(className); el.classList.add(className);
...@@ -199,7 +231,7 @@ ...@@ -199,7 +231,7 @@
el.removeAttribute('data-slider-marker'); el.removeAttribute('data-slider-marker');
window.cancelAnimationFrame(marker); window.cancelAnimationFrame(marker);
} }
const end_height = calculateElementHeight(el); const end_height = u.calculateElementHeight(el);
if (window.converse_disable_effects) { // Effects are disabled (for tests) if (window.converse_disable_effects) { // Effects are disabled (for tests)
el.style.height = end_height + 'px'; el.style.height = end_height + 'px';
slideOutWrapup(el); slideOutWrapup(el);
...@@ -227,7 +259,7 @@ ...@@ -227,7 +259,7 @@
// browser bug where browsers don't know the correct // browser bug where browsers don't know the correct
// offsetHeight beforehand. // offsetHeight beforehand.
el.removeAttribute('data-slider-marker'); el.removeAttribute('data-slider-marker');
el.style.height = calculateElementHeight(el) + 'px'; el.style.height = u.calculateElementHeight(el) + 'px';
el.style.overflow = ""; el.style.overflow = "";
el.style.height = ""; el.style.height = "";
resolve(); resolve();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment