add check if there's no new mentions or DMs in related reset-save functions

This commit is contained in:
Simon Grim 2017-07-14 03:44:40 +05:00
parent 9a97fd0328
commit 366540889c

View File

@ -128,6 +128,9 @@ function queryPendingPushMentions(req, res) {
} }
function resetMentionsCount() { function resetMentionsCount() {
if (!twister.mentions.lengthNew)
return;
twister.mentions.lengthNew = 0; twister.mentions.lengthNew = 0;
for (var j in twister.mentions.twists.cached) for (var j in twister.mentions.twists.cached)
@ -420,30 +423,47 @@ function getNewGroupDMsCount() {
} }
function resetNewDMsCount() { function resetNewDMsCount() {
var isNewDetected;
for (var peerAlias in twister.DMs) for (var peerAlias in twister.DMs)
if (peerAlias[0] !== '*') { if (twister.DMs[peerAlias].lengthNew && peerAlias[0] !== '*') {
twister.DMs[peerAlias].lengthNew = 0; twister.DMs[peerAlias].lengthNew = 0;
for (var j in twister.DMs[peerAlias].twists.cached) for (var j in twister.DMs[peerAlias].twists.cached)
delete twister.DMs[peerAlias].twists.cached[j].isNew; delete twister.DMs[peerAlias].twists.cached[j].isNew;
isNewDetected = true;
} }
if (!isNewDetected)
return;
saveDMsToStorage(); saveDMsToStorage();
$.MAL.updateNewDMsUI(getNewDMsCount()); $.MAL.updateNewDMsUI(getNewDMsCount());
} }
function resetNewDMsCountGroup() { function resetNewDMsCountGroup() {
var isNewDetected;
for (var peerAlias in twister.DMs) for (var peerAlias in twister.DMs)
if (peerAlias[0] === '*') { if (twister.DMs[peerAlias].lengthNew && peerAlias[0] === '*') {
twister.DMs[peerAlias].lengthNew = 0; twister.DMs[peerAlias].lengthNew = 0;
for (var j in twister.DMs[peerAlias].twists.cached) for (var j in twister.DMs[peerAlias].twists.cached)
delete twister.DMs[peerAlias].twists.cached[j].isNew; delete twister.DMs[peerAlias].twists.cached[j].isNew;
isNewDetected = true;
} }
if (!isNewDetected)
return;
saveDMsToStorage(); saveDMsToStorage();
$.MAL.updateNewGroupDMsUI(getNewGroupDMsCount()); $.MAL.updateNewGroupDMsUI(getNewGroupDMsCount());
} }
function resetNewDMsCountForPeer(peerAlias) { function resetNewDMsCountForPeer(peerAlias) {
if (!twister.DMs[peerAlias].lengthNew)
return;
twister.DMs[peerAlias].lengthNew = 0; twister.DMs[peerAlias].lengthNew = 0;
for (var j in twister.DMs[peerAlias].twists.cached) for (var j in twister.DMs[peerAlias].twists.cached)
delete twister.DMs[peerAlias].twists.cached[j].isNew; delete twister.DMs[peerAlias].twists.cached[j].isNew;