|
|
|
@ -3,8 +3,14 @@ import visitor from '../../imports/client/visitor'; |
|
|
|
|
|
|
|
|
|
const firedTriggers = JSON.parse(localStorage.getItem('rocketChatFiredTriggers')) || []; |
|
|
|
|
|
|
|
|
|
// promise cache for multiple calls (let's say multiple triggers running before the previous finished)
|
|
|
|
|
const agentCacheExpiry = 3600000; |
|
|
|
|
let agentPromise; |
|
|
|
|
function getAgent(triggerAction) { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
if (agentPromise) { |
|
|
|
|
return agentPromise; |
|
|
|
|
} |
|
|
|
|
agentPromise = new Promise((resolve, reject) => { |
|
|
|
|
const { params } = triggerAction; |
|
|
|
|
if (params.sender === 'queue') { |
|
|
|
|
const cache = localStorage.getItem('triggerAgent'); |
|
|
|
@ -12,7 +18,7 @@ function getAgent(triggerAction) { |
|
|
|
|
const cacheAgent = JSON.parse(cache); |
|
|
|
|
|
|
|
|
|
// cache valid for 1h
|
|
|
|
|
if (cacheAgent.ts && Date.now() - cacheAgent.ts < 3600000) { |
|
|
|
|
if (cacheAgent.ts && Date.now() - cacheAgent.ts < agentCacheExpiry) { |
|
|
|
|
return resolve(cacheAgent.agent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -39,6 +45,13 @@ function getAgent(triggerAction) { |
|
|
|
|
reject('Unknown sender'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// expire the promise cache as well
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
agentPromise = null; |
|
|
|
|
}, agentCacheExpiry); |
|
|
|
|
|
|
|
|
|
return agentPromise; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.Triggers = (function() { |
|
|
|
|