diff --git a/Manifest.toml b/Manifest.toml index 8f33832..264227f 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -13,24 +13,12 @@ git-tree-sha1 = "b530fbeb6f41ab5a83fbe3db1fcbe879334bcd2d" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.4.2" -[[Codecs]] -deps = ["Test"] -git-tree-sha1 = "70885e5e038cba1c4c17a84ad6c40756e10a4fb5" -uuid = "19ecbf4d-ef7c-5e4b-b54a-0a0ff23c5aed" -version = "0.5.0" - [[Compat]] 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" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" version = "1.1.0" -[[Crayons]] -deps = ["Pkg", "Test"] -git-tree-sha1 = "3017c662a988bcb8a3f43306a793617c6524d476" -uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "1.0.0" - [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -97,12 +85,6 @@ git-tree-sha1 = "f57e8e907faab4f55f9f164313a633509ac83e2c" uuid = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" 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]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -144,12 +126,6 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] 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]] deps = ["Test", "Unicode"] git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" @@ -162,9 +138,3 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] 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" diff --git a/Project.toml b/Project.toml index 173fde7..08e66f0 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,5 @@ HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" -OhMyREPL = "5fb14364-9ced-5910-84b2-373655c76a03" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" URIParser = "30578b45-9adc-5946-b283-645ec420af67" -YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" diff --git a/src/MatrixChat.jl b/src/MatrixChat.jl index c772368..c299c37 100644 --- a/src/MatrixChat.jl +++ b/src/MatrixChat.jl @@ -1,9 +1,7 @@ module MatrixChat -using OhMyREPL using HTTP using JSON -using YAML using Nettle using Dates diff --git a/src/repl.jl b/src/repl.jl index 99c9f60..a7dc736 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -498,7 +498,7 @@ function do_cmd!(command::MatrixCommand, repl) elseif length(command.arguments) == 1 history_size = 10 else - history_size = command.arguments + history_size = Base.parse(Int,command.arguments[2]) end history(user, command.arguments[1], limit = history_size) elseif command.spec.kind in [ CMD_DIALOG_LIST ] @@ -742,9 +742,14 @@ function repl_init(repl) return end -function load_config_file(; configfile::String = expanduser("~/matrix/config.yaml")) +function load_config_file(; configfile::String = expanduser("~/matrix/config.jl")) if isfile(configfile) - config = YAML.load_file(configfile) + config = try + include(configfile) + catch e + @error "Malformed config file!" + throw(e) + end else # First run, create a new user/login and create the config file @error "First run not implemented!" @@ -775,7 +780,7 @@ end """Initialize the REPL mode, read config files and start the TUI client """ function repl() - global user, rooms_last_batch + global user, rooms_last_batch, syncstatus userinfo = load_secret_or_login(load_config_file()) repl_init(Base.active_repl) user = MatrixUser(userinfo...) @@ -869,3 +874,8 @@ Multiple commands can be given on the same line by interleaving a `;` between th **Commands** """ + +#= +Get alias in the event list +curl 'https://chat.nixo.xyz/_matrix/client/r0/rooms/!maXyvEjllUwxzXPTua:nixo.xyz/state?access_token=' +=# diff --git a/src/rooms.jl b/src/rooms.jl index e831f6f..62a6d66 100644 --- a/src/rooms.jl +++ b/src/rooms.jl @@ -29,10 +29,10 @@ getroomname(u::MatrixUser, room_id::String) = getroomevent(u, room_id, "m.room.n function roomhistory(u::MatrixUser, room_id::String; from::Union{Nothing,String} = nothing, - direction::String = "f", limit = 15) + direction::String = "f", limit::Int = 15) global rooms_last_batch query = Dict("dir" => direction, - "limit" => string(limit), + "limit" => limit, "from" => from === nothing ? rooms_last_batch[room_id] : from) res = get(u, join(["rooms", room_id, "messages",], "/"), extraquery = query) @@ -82,3 +82,12 @@ function history(u::MatrixUser, room_id::String; limit = 15) end , res["chunk"]) 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 diff --git a/src/tui.jl b/src/tui.jl index 3319876..3e5390e 100644 --- a/src/tui.jl +++ b/src/tui.jl @@ -5,6 +5,7 @@ function updateroomlist(user::MatrixUser) end function startsync() + global syncstatus background_sync(syncstatus) function showevent(_...) @@ -12,6 +13,10 @@ function startsync() let ks = syncstatus.sync["rooms"]["join"] for k in keys(ks) try + for msg in ks[k]["timeline"]["events"] + # Go up + print("\033[F") + end for msg in ks[k]["timeline"]["events"] println(MatrixMsg(msg["sender"], msg["origin_server_ts"], diff --git a/src/types.jl b/src/types.jl index 7ce79a4..646257e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -13,8 +13,7 @@ struct MatrixUser end import Base.== -==(u::MatrixUser, s::String) = - string("@", u.userid, ":", join(split(URI(u.server.instance).host, ".")[end-1:end], ".")) == s +==(u::MatrixUser, s::String) = string(u) == s ==(s::String, u::MatrixUser) = u == s 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)) nothing end + +import Base.string +function string(u::MatrixUser) + string("@", u.userid, ":", join(split(URI(u.server.instance).host, ".")[end-1:end], ".")) +end diff --git a/src/utils.jl b/src/utils.jl index 1e229cb..7ea3b8c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -10,7 +10,7 @@ Authenticated get request """ function get(u::MatrixUser, path::String; extraquery = Dict()) - query = Dict( + query = Dict{String,Any}( "access_token" => u.token ) merge!(query, extraquery) @@ -39,7 +39,7 @@ function post(u::MatrixUser, path::String, end function request(request::String, u::MatrixUser, path::String, - data::Dict{String,String}; + data::Dict{String,Any}; mime = "application/json") HTTP.request(request, join([u.server.instance, API_PATH, path], "/"), @@ -51,7 +51,7 @@ function request(request::String, u::MatrixUser, path::String, end function put(u::MatrixUser, path::String, - data::Dict{String,String}; + data::Dict{String,Any}; mime = "application/json") request("PUT", u, path, data, mime = mime) end