Skip to content

Commit

Permalink
fix message issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhsherl committed Apr 7, 2020
1 parent e0fcd75 commit 39d3812
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/models/client/models/ChatMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const CachedChatMessage = new CachedCollection({ name: 'chatMessage' });

export const ChatMessage = CachedChatMessage.collection;

let timeout;

ChatMessage.setReactions = function(messageId, reactions, tempActions) {
this.update({ _id: messageId }, { $set: { temp: true, tempActions, reactions } });
return CachedChatMessage.save();
Expand Down Expand Up @@ -92,7 +94,8 @@ const messagePreFetch = () => {
if (!messagesFetched && CachedChatSubscription.ready.get()) {
const status = Meteor.status();
if (status.status !== 'connected') {
cleanMessagesAtStartup();
clearTimeout(timeout);
timeout = setTimeout(cleanMessagesAtStartup, 3000);
return;
}
messagesFetched = true;
Expand Down Expand Up @@ -122,6 +125,7 @@ const messagePreFetch = () => {
});
});
});
clearTimeout(timeout);
cleanMessagesAtStartup(false);
}
});
Expand Down
4 changes: 2 additions & 2 deletions app/utils/client/lib/offlineMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ function clearOldMessages({ records: messages, ...value }) {
value.updatedAt = new Date();
localforage.setItem('chatMessage', value).then(() => {
CachedChatMessage.loadFromCache();
triggerOfflineMsgs(retain);
});
}

export const cleanMessagesAtStartup = (offline = true) => {
localforage.getItem('chatMessage').then((value) => {
if (value && value.records) {
triggerOfflineMsgs(value.records);
offline && clearOldMessages(value);
offline ? clearOldMessages(value) : triggerOfflineMsgs(value.records);
}
});
};

0 comments on commit 39d3812

Please sign in to comment.