From a3f63b0b6fdcc8518f81695e6c2e6b643a50070a Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Fri, 6 Jan 2017 23:28:41 +0100
Subject: fix last_carts handling


diff --git a/src/playlog.lua b/src/playlog.lua
index 591468f..2bfc1af 100644
--- a/src/playlog.lua
+++ b/src/playlog.lua
@@ -64,7 +64,7 @@ function playlog:getLastCart(output, timestamp)
 
    local cart = cur:fetch()
    if cart == nil then cart = 0 end
-   return cart
+   return tonumber(cart)
 end
 
 function playlog:getLastCarts()
@@ -79,11 +79,11 @@ function playlog:getLastCarts()
       data = cur:fetch(data, "a")
       if data == nil then break end
 
-      t[data.output] = self:getLastCart(data.output, data.timestamp)
+      carts[data.output] = self:getLastCart(data.output, data.timestamp)
    end
    cur:close()
 
-   return t
+   return carts
 end
 
 function playlog:insertNow(timestamp, cart, len, showtitle, title, artist, album, carttype, output)
diff --git a/src/qlistener.lua b/src/qlistener.lua
index 5e31890..ef3f6bb 100644
--- a/src/qlistener.lua
+++ b/src/qlistener.lua
@@ -35,7 +35,7 @@ function init(conffile)
    cnf = conf.load(conffile)
 end
 
-function handle_now(timestamp, nowcart, nowlen)
+function handle_now(timestamp, output, nowcart, nowlen)
    local results, err = rddb:getCartInfo(nowcart)
    if results == nil then
       io.stderr:write("ERROR: can't fetch cart info: " .. err .. "\n")
@@ -46,7 +46,7 @@ function handle_now(timestamp, nowcart, nowlen)
          io.stderr:write("ERROR: can't fetch show/pool name: " .. carttype .. "\n")
          return true
       else
-         local ret, err = playlog:insertNow(timestamp, nowcart, nowlen, showtitle, results.TITLE, results.ARTIST, results.ALBUM, carttype)
+         local ret, err = playlog:insertNow(timestamp, nowcart, nowlen, showtitle, results.TITLE, results.ARTIST, results.ALBUM, carttype, output)
          if ret == nil then
             io.stderr:write("ERROR: can't insert cart info: " .. err .. "\n")
          else
@@ -68,7 +68,7 @@ function handle_message(msg, q)
       if last_carts[output] == nil then last_carts[output] = 0 end
       if last_carts[output] ~= nowcart and nowlen > 0 then
          last_carts[output] = nowcart
-         local ret = handle_now(timestamp, nowcart, nowlen)
+         local ret = handle_now(timestamp, output, nowcart, nowlen)
          if ret == nil then
             io.stderr:write("INFO: trying to push last message back onto the queue - before exiting\n")
             local result, err = mq.send(q, timestamp .. " " .. output .. " " .. nowcart .. " " .. nowlen .. " " .. nextcart .. " " .. nextlen, 0)
-- 
cgit v0.10.2