Check whether login succeeds
This commit is contained in:
parent
e307c24e06
commit
4bd0e718a2
41
init.lua
41
init.lua
|
@ -79,21 +79,21 @@ end
|
|||
|
||||
function MatrixChat:sync(timeout)
|
||||
http.fetch(MatrixChat:get_sync_table(timeout),
|
||||
function(res)
|
||||
if res == nil then -- received nothing from server
|
||||
minetest.log("error", "matrix_bridge - sync response is nil")
|
||||
elseif res.code == 0 then
|
||||
minetest.log("info", "matrix_bridge - not found / timeout")
|
||||
elseif res.code == 404 then
|
||||
else
|
||||
local response = minetest.parse_json(res.data)
|
||||
if response ~= nil then
|
||||
MatrixChat:minechat(response)
|
||||
self.since = response.next_batch
|
||||
function(res)
|
||||
if res == nil then -- received nothing from server
|
||||
minetest.log("error", "matrix_bridge - sync response is nil")
|
||||
elseif res.code == 0 then
|
||||
minetest.log("info", "matrix_bridge - not found / timeout")
|
||||
elseif res.code == 404 then
|
||||
else
|
||||
local response = minetest.parse_json(res.data)
|
||||
if response ~= nil then
|
||||
MatrixChat:minechat(response)
|
||||
self.since = response.next_batch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
-- https://matrix.org/docs/api/client-server/#post-/login
|
||||
|
@ -107,17 +107,20 @@ function MatrixChat:login()
|
|||
if res.code == 200 then
|
||||
minetest.log("action", res.data)
|
||||
local data = minetest.parse_json(res.data)
|
||||
self.token = data.access_token
|
||||
self.userid = data.user_id
|
||||
MatrixChat:sync()
|
||||
minetest.log("action", "Matrix authenticated")
|
||||
if data.access_token ~= nil and data.user_id ~= nil then
|
||||
self.token = data.access_token
|
||||
self.userid = data.user_id
|
||||
MatrixChat:sync()
|
||||
minetest.log("action", "Matrix authenticated")
|
||||
else
|
||||
minetest.log("error", "Matrix login failed")
|
||||
end
|
||||
else
|
||||
minetest.log("error", to_string(res))
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
MatrixChat:login()
|
||||
|
||||
-- https://matrix.org/docs/api/client-server/#put-/rooms/-roomId-/send/-eventType-/-txnId-
|
||||
-- PUT /rooms/{roomId}/send/{eventType}/{txnId}
|
||||
|
@ -240,4 +243,4 @@ minetest.register_on_chat_message(function(name, message)
|
|||
MatrixChat:send("<"..name.."> "..message)
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_mods_loaded(function() MatrixChat:login() end)
|
||||
|
|
Loading…
Reference in New Issue