saved - look into timing later

This commit is contained in:
- 2022-01-22 20:24:06 -08:00
parent e600d4a1e3
commit 45292083f2
1 changed files with 15 additions and 6 deletions

View File

@ -15,8 +15,8 @@ local token = nil
local txid = 0
-- used for msync()
local since = nil
local last_batch = nil
-- accepts list of events
local function mchat(data)
if data == nil then
return
@ -36,8 +36,10 @@ local function mchat(data)
else
local events = data["rooms"]["join"][MATRIX_ROOM]["timeline"]["events"]
if events == nil then
minetest.log("action", "matrix_bridge - found timeline but no events")
return
end
minetest.log("action", "matrix_bridge - sync'd and found new messages")
for i, event in ipairs(events) do
if event.type == "m.room.message"
and event.sender ~= MATRIX_USERNAME_LONG then
@ -53,7 +55,8 @@ local function msync()
-- local param1 = '&filter={\"room\":{\"timeline\":{\"limit\":1}}}'
local param1 = "?access_token=" .. token
local param2 = "&full_state=false"
local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2
local param3 = "&timeout=30000"
local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2 .. param3
if since == nil then -- first time sync
-- do nothing for now
else -- second time sync -> append since parameter
@ -66,11 +69,12 @@ local function msync()
elseif res.code == 0 then
minetest.log("info", "matrix_bridge - not found / timeout")
elseif res.code == 404 then
minetest.log("info", "matrix_bridge - 404")
minetest.log("error", "matrix_bridge - 404")
else
local response = minetest.parse_json(res.data)
if response ~= nil then
since = response.next_batch
since = response.next_batch
last_batch = response.prev_batch
mchat(response)
end
end
@ -125,8 +129,13 @@ end
-- end
-- end)
minetest.register_globalstep(function()
msync()
local GLOBAL_STEPS = 0
minetest.register_globalstep(function(dtine)
-- print(GLOBAL_STEPS)
if GLOBAL_STEPS == 4 then
msync()
end
GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5
end)
minetest.register_on_joinplayer(function(player)