"Fossies" - the Fresh Open Source Software Archive

Member "Signal-Server-11.96.0/service/src/main/resources/lua/apn/get.lua" (20 Feb 2024, 1492 Bytes) of package /linux/www/Signal-Server-11.96.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 local pendingNotificationQueue = KEYS[1]
    2 
    3 local maxTime = ARGV[1]
    4 local limit = ARGV[2]
    5 
    6 local hgetall = function (key)
    7     local bulk = redis.call('HGETALL', key)
    8     local result = {}
    9     local nextkey
   10     for i, v in ipairs(bulk) do
   11         if i % 2 == 1 then
   12             nextkey = v
   13         else
   14             result[nextkey] = v
   15         end
   16     end
   17     return result
   18 end
   19 
   20 local getNextInterval = function(interval)
   21     if interval < 20000 then
   22         return 20000
   23     end
   24 
   25     if interval < 40000 then
   26         return 40000
   27     end
   28 
   29     if interval < 80000 then
   30         return 80000
   31     end
   32 
   33     if interval < 160000 then
   34         return 160000
   35     end
   36 
   37     if interval < 600000 then
   38         return 600000
   39     end
   40 
   41     if interval < 1800000 then
   42         return 1800000
   43     end
   44 
   45     return 3600000
   46 end
   47 
   48 
   49 local results  = redis.call("ZRANGEBYSCORE", pendingNotificationQueue, 0, maxTime, "LIMIT", 0, limit)
   50 local collated = {}
   51 
   52 if results and next(results) then
   53     for i, name in ipairs(results) do
   54         local pending      = hgetall(name)
   55         local lastInterval = pending["interval"]
   56 
   57         if lastInterval == nil then
   58             lastInterval = 0
   59         end
   60 
   61         local nextInterval = getNextInterval(tonumber(lastInterval))
   62 
   63         redis.call("HSET", name, "interval", nextInterval)
   64         redis.call("ZADD", pendingNotificationQueue, tonumber(maxTime) + nextInterval, name)
   65 
   66         collated[i] = pending["account"] .. ":" .. pending["device"]
   67     end
   68 end
   69 
   70 return collated