Nicolò Balzarotti 2019-02-11 18:02:47 +01:00
commit d65d989567
No known key found for this signature in database
GPG Key ID: E5900B8AC02DE455
8 changed files with 39 additions and 45 deletions

View File

@ -13,24 +13,12 @@ git-tree-sha1 = "b530fbeb6f41ab5a83fbe3db1fcbe879334bcd2d"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.4.2" version = "0.4.2"
[[Codecs]]
deps = ["Test"]
git-tree-sha1 = "70885e5e038cba1c4c17a84ad6c40756e10a4fb5"
uuid = "19ecbf4d-ef7c-5e4b-b54a-0a0ff23c5aed"
version = "0.5.0"
[[Compat]] [[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "ae262fa91da6a74e8937add6b613f58cd56cdad4" git-tree-sha1 = "ae262fa91da6a74e8937add6b613f58cd56cdad4"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "1.1.0" version = "1.1.0"
[[Crayons]]
deps = ["Pkg", "Test"]
git-tree-sha1 = "3017c662a988bcb8a3f43306a793617c6524d476"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "1.0.0"
[[Dates]] [[Dates]]
deps = ["Printf"] deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@ -97,12 +85,6 @@ git-tree-sha1 = "f57e8e907faab4f55f9f164313a633509ac83e2c"
uuid = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" uuid = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
version = "0.4.0" version = "0.4.0"
[[OhMyREPL]]
deps = ["Crayons", "InteractiveUtils", "Markdown", "Pkg", "Printf", "REPL", "Test", "Tokenize"]
git-tree-sha1 = "e00d5394d110afe279101ffe10cebd11eaedcb8a"
uuid = "5fb14364-9ced-5910-84b2-373655c76a03"
version = "0.3.0"
[[Pkg]] [[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
@ -144,12 +126,6 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[Tokenize]]
deps = ["Printf", "Test"]
git-tree-sha1 = "4a9fefb5c5c831c6fc06fcc5d2ae7399918bb587"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.2"
[[URIParser]] [[URIParser]]
deps = ["Test", "Unicode"] deps = ["Test", "Unicode"]
git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69"
@ -162,9 +138,3 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[Unicode]] [[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[YAML]]
deps = ["Codecs", "Compat", "Pkg"]
git-tree-sha1 = "3bde77cee95cce0c0b9b18813d85e18e8ed4f415"
uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
version = "0.3.2"

View File

@ -9,7 +9,5 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
URIParser = "30578b45-9adc-5946-b283-645ec420af67" URIParser = "30578b45-9adc-5946-b283-645ec420af67"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

View File

@ -1,9 +1,7 @@
module MatrixChat module MatrixChat
using OhMyREPL
using HTTP using HTTP
using JSON using JSON
using YAML
using Nettle using Nettle
using Dates using Dates

View File

@ -498,7 +498,7 @@ function do_cmd!(command::MatrixCommand, repl)
elseif length(command.arguments) == 1 elseif length(command.arguments) == 1
history_size = 10 history_size = 10
else else
history_size = command.arguments history_size = Base.parse(Int,command.arguments[2])
end end
history(user, command.arguments[1], limit = history_size) history(user, command.arguments[1], limit = history_size)
elseif command.spec.kind in [ CMD_DIALOG_LIST ] elseif command.spec.kind in [ CMD_DIALOG_LIST ]
@ -742,9 +742,14 @@ function repl_init(repl)
return return
end end
function load_config_file(; configfile::String = expanduser("~/matrix/config.yaml")) function load_config_file(; configfile::String = expanduser("~/matrix/config.jl"))
if isfile(configfile) if isfile(configfile)
config = YAML.load_file(configfile) config = try
include(configfile)
catch e
@error "Malformed config file!"
throw(e)
end
else else
# First run, create a new user/login and create the config file # First run, create a new user/login and create the config file
@error "First run not implemented!" @error "First run not implemented!"
@ -775,7 +780,7 @@ end
"""Initialize the REPL mode, read config files and start the TUI client """Initialize the REPL mode, read config files and start the TUI client
""" """
function repl() function repl()
global user, rooms_last_batch global user, rooms_last_batch, syncstatus
userinfo = load_secret_or_login(load_config_file()) userinfo = load_secret_or_login(load_config_file())
repl_init(Base.active_repl) repl_init(Base.active_repl)
user = MatrixUser(userinfo...) user = MatrixUser(userinfo...)
@ -869,3 +874,8 @@ Multiple commands can be given on the same line by interleaving a `;` between th
**Commands** **Commands**
""" """
#=
Get alias in the event list
curl 'https://chat.nixo.xyz/_matrix/client/r0/rooms/!maXyvEjllUwxzXPTua:nixo.xyz/state?access_token='
=#

View File

@ -29,10 +29,10 @@ getroomname(u::MatrixUser, room_id::String) = getroomevent(u, room_id, "m.room.n
function roomhistory(u::MatrixUser, room_id::String; function roomhistory(u::MatrixUser, room_id::String;
from::Union{Nothing,String} = nothing, from::Union{Nothing,String} = nothing,
direction::String = "f", limit = 15) direction::String = "f", limit::Int = 15)
global rooms_last_batch global rooms_last_batch
query = Dict("dir" => direction, query = Dict("dir" => direction,
"limit" => string(limit), "limit" => limit,
"from" => from === nothing ? "from" => from === nothing ?
rooms_last_batch[room_id] : from) rooms_last_batch[room_id] : from)
res = get(u, join(["rooms", room_id, "messages",], "/"), extraquery = query) res = get(u, join(["rooms", room_id, "messages",], "/"), extraquery = query)
@ -82,3 +82,12 @@ function history(u::MatrixUser, room_id::String; limit = 15)
end end
, res["chunk"]) , res["chunk"])
end end
function sendtyping(u::MatrixUser, room_id::String; typing = true, timeout = 30000)
path = join([u.server.instance, API_PATH,
string("rooms/", HTTP.escapeuri(room_id), "/typing/", u.userid)], "/")
data = Dict{String,Any}("typing" => typing, "timeout" => timeout)
@show data
@show path
put(u, path, data)
end

View File

@ -5,6 +5,7 @@ function updateroomlist(user::MatrixUser)
end end
function startsync() function startsync()
global syncstatus
background_sync(syncstatus) background_sync(syncstatus)
function showevent(_...) function showevent(_...)
@ -12,6 +13,10 @@ function startsync()
let ks = syncstatus.sync["rooms"]["join"] let ks = syncstatus.sync["rooms"]["join"]
for k in keys(ks) for k in keys(ks)
try try
for msg in ks[k]["timeline"]["events"]
# Go up
print("\033[F")
end
for msg in ks[k]["timeline"]["events"] for msg in ks[k]["timeline"]["events"]
println(MatrixMsg(msg["sender"], println(MatrixMsg(msg["sender"],
msg["origin_server_ts"], msg["origin_server_ts"],

View File

@ -13,8 +13,7 @@ struct MatrixUser
end end
import Base.== import Base.==
==(u::MatrixUser, s::String) = ==(u::MatrixUser, s::String) = string(u) == s
string("@", u.userid, ":", join(split(URI(u.server.instance).host, ".")[end-1:end], ".")) == s
==(s::String, u::MatrixUser) = u == s ==(s::String, u::MatrixUser) = u == s
import Base.show import Base.show
@ -76,3 +75,8 @@ function Base.show(io::IO, m::MatrixMsg; muser::Union{Nothing,MatrixUser} = noth
print(io, string("[", dtfmt, "] ", m.sender, direction, m.body)) print(io, string("[", dtfmt, "] ", m.sender, direction, m.body))
nothing nothing
end end
import Base.string
function string(u::MatrixUser)
string("@", u.userid, ":", join(split(URI(u.server.instance).host, ".")[end-1:end], "."))
end

View File

@ -10,7 +10,7 @@ Authenticated get request
""" """
function get(u::MatrixUser, path::String; function get(u::MatrixUser, path::String;
extraquery = Dict()) extraquery = Dict())
query = Dict( query = Dict{String,Any}(
"access_token" => u.token "access_token" => u.token
) )
merge!(query, extraquery) merge!(query, extraquery)
@ -39,7 +39,7 @@ function post(u::MatrixUser, path::String,
end end
function request(request::String, u::MatrixUser, path::String, function request(request::String, u::MatrixUser, path::String,
data::Dict{String,String}; data::Dict{String,Any};
mime = "application/json") mime = "application/json")
HTTP.request(request, HTTP.request(request,
join([u.server.instance, API_PATH, path], "/"), join([u.server.instance, API_PATH, path], "/"),
@ -51,7 +51,7 @@ function request(request::String, u::MatrixUser, path::String,
end end
function put(u::MatrixUser, path::String, function put(u::MatrixUser, path::String,
data::Dict{String,String}; data::Dict{String,Any};
mime = "application/json") mime = "application/json")
request("PUT", u, path, data, mime = mime) request("PUT", u, path, data, mime = mime)
end end