mirror of
https://github.com/mt-mods/mail.git
synced 2025-03-20 16:41:25 +00:00
cleanup / array rx support
This commit is contained in:
parent
eea0736296
commit
93690fdf6e
1 changed files with 9 additions and 11 deletions
|
@ -1,8 +1,6 @@
|
||||||
-- bi-directional http-channel
|
-- bi-directional http-channel
|
||||||
-- with long-poll GET and POST on the same URL
|
-- with long-poll GET and POST on the same URL
|
||||||
|
|
||||||
local debug = false
|
|
||||||
|
|
||||||
local function Channel(http, url, cfg)
|
local function Channel(http, url, cfg)
|
||||||
cfg = cfg or {}
|
cfg = cfg or {}
|
||||||
local extra_headers = cfg.extra_headers or {}
|
local extra_headers = cfg.extra_headers or {}
|
||||||
|
@ -33,13 +31,17 @@ local function Channel(http, url, cfg)
|
||||||
if res.succeeded and res.code == 200 then
|
if res.succeeded and res.code == 200 then
|
||||||
local data = minetest.parse_json(res.data)
|
local data = minetest.parse_json(res.data)
|
||||||
|
|
||||||
if debug then
|
|
||||||
minetest.log("action", "[webmail-rx] " .. dump(data))
|
|
||||||
end
|
|
||||||
|
|
||||||
if data then
|
if data then
|
||||||
for _,listener in pairs(recv_listeners) do
|
for _,listener in pairs(recv_listeners) do
|
||||||
listener(data)
|
if #data > 0 then
|
||||||
|
-- array received
|
||||||
|
for _, entry in ipairs(data) do
|
||||||
|
listener(entry)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- single item received
|
||||||
|
listener(data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- reschedule immediately
|
-- reschedule immediately
|
||||||
|
@ -56,10 +58,6 @@ local function Channel(http, url, cfg)
|
||||||
assert(run)
|
assert(run)
|
||||||
-- POST
|
-- POST
|
||||||
|
|
||||||
if debug then
|
|
||||||
minetest.log("action", "[webmail-tx] " .. dump(data))
|
|
||||||
end
|
|
||||||
|
|
||||||
http.fetch({
|
http.fetch({
|
||||||
url = url,
|
url = url,
|
||||||
extra_headers = post_headers,
|
extra_headers = post_headers,
|
||||||
|
|
Loading…
Add table
Reference in a new issue