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)
|
function MatrixChat:sync(timeout)
|
||||||
http.fetch(MatrixChat:get_sync_table(timeout),
|
http.fetch(MatrixChat:get_sync_table(timeout),
|
||||||
function(res)
|
function(res)
|
||||||
if res == nil then -- received nothing from server
|
if res == nil then -- received nothing from server
|
||||||
minetest.log("error", "matrix_bridge - sync response is nil")
|
minetest.log("error", "matrix_bridge - sync response is nil")
|
||||||
elseif res.code == 0 then
|
elseif res.code == 0 then
|
||||||
minetest.log("info", "matrix_bridge - not found / timeout")
|
minetest.log("info", "matrix_bridge - not found / timeout")
|
||||||
elseif res.code == 404 then
|
elseif res.code == 404 then
|
||||||
else
|
else
|
||||||
local response = minetest.parse_json(res.data)
|
local response = minetest.parse_json(res.data)
|
||||||
if response ~= nil then
|
if response ~= nil then
|
||||||
MatrixChat:minechat(response)
|
MatrixChat:minechat(response)
|
||||||
self.since = response.next_batch
|
self.since = response.next_batch
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- https://matrix.org/docs/api/client-server/#post-/login
|
-- https://matrix.org/docs/api/client-server/#post-/login
|
||||||
|
@ -107,17 +107,20 @@ function MatrixChat:login()
|
||||||
if res.code == 200 then
|
if res.code == 200 then
|
||||||
minetest.log("action", res.data)
|
minetest.log("action", res.data)
|
||||||
local data = minetest.parse_json(res.data)
|
local data = minetest.parse_json(res.data)
|
||||||
self.token = data.access_token
|
if data.access_token ~= nil and data.user_id ~= nil then
|
||||||
self.userid = data.user_id
|
self.token = data.access_token
|
||||||
MatrixChat:sync()
|
self.userid = data.user_id
|
||||||
minetest.log("action", "Matrix authenticated")
|
MatrixChat:sync()
|
||||||
|
minetest.log("action", "Matrix authenticated")
|
||||||
|
else
|
||||||
|
minetest.log("error", "Matrix login failed")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
minetest.log("error", to_string(res))
|
minetest.log("error", to_string(res))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
MatrixChat:login()
|
|
||||||
|
|
||||||
-- https://matrix.org/docs/api/client-server/#put-/rooms/-roomId-/send/-eventType-/-txnId-
|
-- https://matrix.org/docs/api/client-server/#put-/rooms/-roomId-/send/-eventType-/-txnId-
|
||||||
-- 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)
|
MatrixChat:send("<"..name.."> "..message)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function() MatrixChat:login() end)
|
||||||
|
|
Loading…
Reference in New Issue