43 lines
1.2 KiB
Julia
43 lines
1.2 KiB
Julia
"""Logs into a matrix server.
|
|
`login(::MatrixServer, username::String, password::String)`
|
|
|
|
the optional parameter `deviceid` is `JuliaMatrix` by default
|
|
"""
|
|
function login(s::MatrixServer, username::String, password::String;
|
|
deviceid::Union{Nothing,String} = nothing)
|
|
body = Dict(
|
|
"type" => "m.login.password",
|
|
"identifier" => Dict(
|
|
"type" => "m.id.user",
|
|
"user" => username
|
|
),
|
|
"password" => password,
|
|
"device_id" => deviceid === nothing ? "JuliaMatrix" : deviceid
|
|
)
|
|
try res = post(s, "login", body)
|
|
catch x
|
|
if isa(x,HTTP.ExceptionRequest.StatusError) && x.status == 403
|
|
@error "Auth failed"
|
|
@show x
|
|
else
|
|
@warn "Matrix: Unknown error"
|
|
throw(x)
|
|
end
|
|
end
|
|
res
|
|
end
|
|
|
|
function setavatar(u::MatrixUser, murl::String)
|
|
put(u, string("profile/", u.userid, "/avatar_url"),
|
|
Dict("avatar_url" => murl))
|
|
end
|
|
|
|
function setavatar(u::MatrixUser, data)
|
|
pic = upload(u, "image/png", data)
|
|
setavatar(u, pic["content_uri"])
|
|
end
|
|
|
|
# function setavatar(s::MatrixServer, u::MatrixUser, file::String)
|
|
# setavatar(s::MatrixServer, u::MatrixUser, read(file))
|
|
# end
|