Skip to content

Commit

Permalink
fix: быстрая отправка непрочитанных при изменении, медленная (раз в ч…
Browse files Browse the repository at this point in the history
…ас), когда изменений нет
  • Loading branch information
popstas committed Aug 27, 2020
1 parent bcbebbc commit 8152ce0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/_planfixfix.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,34 @@ let $; // заглушает ошибки в определении $ в мод
initUserInfoSender() {
if (!PFF.sendUserInfoInterval || !PFF.sendUserInfoTo) return;
// setTimeout(PFF.sendUserInfo, 5000);
setInterval(PFF.sendUserInfo, 60000);
setInterval(PFF.sendUserInfo, 5000);
},

sendUserInfo() {
const randomDelay = Math.floor(Math.random() * 1000);
setTimeout(() => {
const user = win.Current.logined;
const count = win.PlanfixPage.newCount;
// const time = new Date().toTimeString().split(' ')[0];
const lastSent = localStorage.pff_tasksCountLastSent || 0;
const lastCount = localStorage.pff_tasksCountLastCount || 0;

if(Date.now() - lastSent < PFF.sendUserInfoInterval * 1000) return;
const sentAgo = Date.now() - lastSent;
if (sentAgo < PFF.sendUserInfoInterval * 1000) {
// console.log('sentAgo: ', sentAgo);
return;
}
localStorage.pff_tasksCountLastSent = Date.now();

if (lastCount == count && sentAgo < 3600 * 1000) { // минимум раз в час отправляем, даже если не поменялось
// console.log('unreaded no change: ', count);
return;
}

// const time = new Date().toTimeString().split(' ')[0];
// console.log(`${time}: ${count}`);

localStorage.pff_tasksCountLastCount = count;

const url = `${PFF.sendUserInfoTo}?user=${user}&unreaded=${count}`;
// console.log('url: ', url);

Expand Down

0 comments on commit 8152ce0

Please sign in to comment.