From 93690fdf6ee799cfa863867ec51a283c5b1407d4 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 27 Jan 2020 13:00:03 +0100 Subject: [PATCH] cleanup / array rx support --- util/channel.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/util/channel.lua b/util/channel.lua index 0bd8d19..e879adf 100644 --- a/util/channel.lua +++ b/util/channel.lua @@ -1,8 +1,6 @@ -- bi-directional http-channel -- with long-poll GET and POST on the same URL -local debug = false - local function Channel(http, url, cfg) cfg = cfg 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 local data = minetest.parse_json(res.data) - if debug then - minetest.log("action", "[webmail-rx] " .. dump(data)) - end - if data then 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 -- reschedule immediately @@ -56,10 +58,6 @@ local function Channel(http, url, cfg) assert(run) -- POST - if debug then - minetest.log("action", "[webmail-tx] " .. dump(data)) - end - http.fetch({ url = url, extra_headers = post_headers,