225 |
225 |
226 function does_opt_in(remoteDomain) |
226 function does_opt_in(remoteDomain) |
227 |
227 |
228 -- try to read answer from cache. |
228 -- try to read answer from cache. |
229 local cached_value = opt_in_cache[remoteDomain] |
229 local cached_value = opt_in_cache[remoteDomain] |
230 if cached_value ~= nil and os.difftime(cached_value.expires, os.time()) > 0 then |
230 local ttl = cached_value and os.difftime(cached_value.expires, os.time()); |
|
231 if cached_value and ttl > (publication_interval + 60) then |
231 module:log("debug", "Opt-in status (from cache) for '%s': %s", remoteDomain, cached_value.opt_in) |
232 module:log("debug", "Opt-in status (from cache) for '%s': %s", remoteDomain, cached_value.opt_in) |
232 return cached_value.opt_in; |
233 return cached_value.opt_in; |
233 end |
234 end |
234 |
235 |
|
236 -- We don't have a cached value, or it is nearing expiration - refresh it now |
235 -- TODO worry about not having multiple requests in flight to the same domain.cached_value |
237 -- TODO worry about not having multiple requests in flight to the same domain.cached_value |
236 |
238 |
237 -- Cache could not provide an answer. Perform service discovery. |
|
238 module:log("debug", "No cached opt-in status for '%s': performing disco/info to determine opt-in.", remoteDomain) |
239 module:log("debug", "No cached opt-in status for '%s': performing disco/info to determine opt-in.", remoteDomain) |
239 local discoRequest = st.iq({ type = "get", to = remoteDomain, from = actor, id = new_id() }) |
240 local discoRequest = st.iq({ type = "get", to = remoteDomain, from = actor, id = new_id() }) |
240 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }) |
241 :tag("query", { xmlns = "http://jabber.org/protocol/disco#info" }) |
241 |
242 |
242 module:send_iq(discoRequest):next( |
243 module:send_iq(discoRequest):next( |