Add prencence option in sync

master
Nicolò Balzarotti 2019-02-11 18:02:39 +01:00
parent edb59b7a8e
commit 21d3fb2814
No known key found for this signature in database
GPG Key ID: E5900B8AC02DE455
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,8 @@
function sync(u::MatrixUser;
timeout = 0, since::Union{String,Nothing} = nothing, full = false)
timeout = 0, since::Union{String,Nothing} = nothing, full = false,
presence = "offline")
req = Dict("timeout" => string(timeout),
"set_presence" => presence,
"full" => string(full))
since === nothing ? nothing : (req["since"] = string(since))
get(u, "sync"; extraquery = req)
@ -9,9 +11,9 @@ end
function sync!(s::MatrixSync)
# initial sync
res = s.last in [nothing, ""] ?
sync(s.user, timeout = s.timeout, full = true) :
sync(s.user, timeout = s.timeout, full = true, presence = s.presence) :
# updates
sync(s.user, since = s.last, timeout = s.timeout, full = false)
sync(s.user, since = s.last, timeout = s.timeout, full = false, presence = s.presence)
res = JSON.parse(String(res.body))
s.last = res["next_batch"]
s.sync = res

View File

@ -35,6 +35,7 @@ mutable struct MatrixSync
user::MatrixUser
last::Union{Nothing,String}
timeout::Int
presence::String
sync
end