Skip to content

Commit

Permalink
Regression: thread loading parent msg if is not loaded (#14839)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored and sampaiodiego committed Jun 21, 2019
1 parent f7cb62f commit c6c90cc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,33 +429,34 @@ Template.message.helpers({

const findParentMessage = (() => {
const waiting = [];

const uid = Tracker.nonreactive(() => Meteor.userId());
const getMessages = _.debounce(async function() {
const uid = Tracker.nonreactive(() => Meteor.userId());
const _tmp = [...waiting];
waiting.length = 0;
(await call('getMessages', _tmp)).map((msg) => upsertMessage({ msg: { ...msg, _hidden: true }, uid }));
(await call('getMessages', _tmp)).map((msg) => Messages.findOne({ _id: msg._id }) || upsertMessage({ msg: { ...msg, _hidden: true }, uid }));
}, 500);


return (tmid) => {
if (waiting.indexOf(tmid) > -1) {
return;
}

const message = Messages.findOne({ _id: tmid });
if (message) {
const uid = Tracker.nonreactive(() => Meteor.userId());
return Messages.update({ tmid, repliesCount: { $exists: 0 } }, {
if (!message) {
waiting.push(tmid);
return getMessages();
}
return Messages.update(
{ tmid, repliesCount: { $exists: 0 } },
{
$set: {
following: message.replies && message.replies.indexOf(uid) > -1,
threadMsg: normalizeThreadMessage(message),
repliesCount: message.tcount,
},
}, { multi: true });
}

waiting.push(tmid);
getMessages();
},
{ multi: true }
);
};
})();

Expand Down

0 comments on commit c6c90cc

Please sign in to comment.