Commit 11da69b0 authored by JC Brand's avatar JC Brand

Use native methods instead of DayJS

Results in a 4x speedup
parent 9ee0b681
...@@ -1312,24 +1312,26 @@ converse.plugins.add('converse-muc-views', { ...@@ -1312,24 +1312,26 @@ converse.plugins.add('converse-muc-views', {
}, },
/** /**
* Working backwards, get the first join/leave notification * Working backwards, get today's most recent join/leave notification
* from the same user, on the same day and BEFORE any chat * from the same user (if any exists) after the most recent chat message.
* messages were received.
* @private * @private
* @method _converse.ChatRoomView#getPreviousJoinOrLeaveNotification * @method _converse.ChatRoomView#getPreviousJoinOrLeaveNotification
* @param {HTMLElement} el * @param {HTMLElement} el
* @param {string} nick * @param {string} nick
*/ */
getPreviousJoinOrLeaveNotification (el, nick) { getPreviousJoinOrLeaveNotification (el, nick) {
while (!_.isNil(el)) { const today = (new Date()).toISOString().split('T')[0];
const data = _.get(el, 'dataset', {}); while (el !== null) {
if (!_.includes(_.get(el, 'classList', []), 'chat-info')) { if (!el.classList.contains('chat-info')) {
return; return;
} }
if (!dayjs(el.getAttribute('data-isodate')).isSame(new Date(), "day")) { // Check whether el is still from today.
el = el.previousElementSibling; // We don't use `Dayjs.same` here, since it's about 4 times slower.
continue; const date = el.getAttribute('data-isodate');
if (date && date.split('T')[0] !== today) {
return;
} }
const data = _.get(el, 'dataset', {});
if (data.join === nick || if (data.join === nick ||
data.leave === nick || data.leave === nick ||
data.leavejoin === nick || data.leavejoin === nick ||
......
...@@ -258,7 +258,7 @@ u.getLastChildElement = function (el, selector='*') { ...@@ -258,7 +258,7 @@ u.getLastChildElement = function (el, selector='*') {
} }
u.hasClass = function (className, el) { u.hasClass = function (className, el) {
return Array.from(el.classList).includes(className); return el.classList.contains(className);
}; };
u.addClass = function (className, el) { u.addClass = function (className, el) {
......
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