Skip to content
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
16 changes: 14 additions & 2 deletions packages/rocketchat-ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,19 @@ Template.message.onViewRendered = function(context) {
return this._domrange.onAttached(function(domRange) {
const currentNode = domRange.lastNode();
const currentDataset = currentNode.dataset;
const previousNode = currentNode.previousElementSibling;
const getPreviousSentMessage = (currentNode) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My biggest concern here is performance. If we are creating a new function for every message, then I can imagine the memory level just went up a little bit more...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, can we have some monitoring on unstable and develop when this hits? @geekgonecrazy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@graywolf336 do you think simply moving the function to outer scope would help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about that, as I don't know if it would be created everytime the template is initialized. That would be something to test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how garbage collector works for these lambda functions used/created on closed contexts.. if that is a real problem or not..

what I know is moving it to file's root scope will define it once and will not run every time the template is initialized.

if ($(currentNode).hasClass('temp')) {
return currentNode.previousElementSibling;
}
if (currentNode.previousElementSibling != null) {
let previousValid = currentNode.previousElementSibling;
while (previousValid != null && $(previousValid).hasClass('temp')) {
previousValid = previousValid.previousElementSibling;
}
return previousValid;
}
};
const previousNode = getPreviousSentMessage(currentNode);
const nextNode = currentNode.nextElementSibling;
const $currentNode = $(currentNode);
const $nextNode = $(nextNode);
Expand Down Expand Up @@ -372,7 +384,7 @@ Template.message.onViewRendered = function(context) {
if (nextDataset.groupable !== 'false') {
if (nextDataset.username !== currentDataset.username || parseInt(nextDataset.timestamp) - parseInt(currentDataset.timestamp) > RocketChat.settings.get('Message_GroupingPeriod') * 1000) {
$nextNode.removeClass('sequential');
} else if (!$nextNode.hasClass('new-day')) {
} else if (!$nextNode.hasClass('new-day') && !$currentNode.hasClass('temp')) {
$nextNode.addClass('sequential');
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/lib/RoomManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const RoomManager = new function() {
};

const loadMissedMessages = function(rid) {
const lastMessage = ChatMessage.findOne({rid}, {sort: {ts: -1}, limit: 1});
const lastMessage = ChatMessage.findOne({rid, temp: { $exists: false } }, {sort: {ts: -1}, limit: 1});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing!

if (lastMessage == null) {
return;
}
Expand Down