From 6aab80a9671bb072e25f0559003279b90e270a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Tue, 18 Sep 2018 09:45:57 +0200 Subject: [PATCH 1/5] try better message printing --- src/repl.jl | 2 +- src/tui.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/repl.jl b/src/repl.jl index 99c9f60..742c06b 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -775,7 +775,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...) 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"], From b47555953539db461f3e60ae9b10b207405cd0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Tue, 18 Sep 2018 10:56:33 +0200 Subject: [PATCH 2/5] add sendtyping --- src/rooms.jl | 7 +++++++ src/utils.jl | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rooms.jl b/src/rooms.jl index e831f6f..70f7e73 100644 --- a/src/rooms.jl +++ b/src/rooms.jl @@ -82,3 +82,10 @@ 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/", escapeuri(room_id), "/typing/", u.userid)], "/") + data = Dict{String,Any}("typing" => typing, "timeout" => timeout) + put(u, path, data) +end diff --git a/src/utils.jl b/src/utils.jl index 1e229cb..ab2d18a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 From d11bd8ac31cab12bd776d8c12367ec7c565b1e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Wed, 19 Sep 2018 07:26:18 +0200 Subject: [PATCH 3/5] remove OhMyREPL from dependencies (speed up pkg load, wasn't used) --- Manifest.toml | 18 ------------------ Project.toml | 1 - src/MatrixChat.jl | 1 - 3 files changed, 20 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 8f33832..2f41a95 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -25,12 +25,6 @@ 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 +91,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 +132,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" diff --git a/Project.toml b/Project.toml index 173fde7..979faaa 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,6 @@ 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..bc34605 100644 --- a/src/MatrixChat.jl +++ b/src/MatrixChat.jl @@ -1,6 +1,5 @@ module MatrixChat -using OhMyREPL using HTTP using JSON using YAML From 98ce81a32dfab7859f9b83ed4593d273624baa34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Wed, 19 Sep 2018 07:26:41 +0200 Subject: [PATCH 4/5] some repl fixes --- src/repl.jl | 7 ++++++- src/rooms.jl | 8 +++++--- src/types.jl | 8 ++++++-- src/utils.jl | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/repl.jl b/src/repl.jl index 742c06b..d5db453 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 ] @@ -869,3 +869,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 70f7e73..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) @@ -85,7 +85,9 @@ end function sendtyping(u::MatrixUser, room_id::String; typing = true, timeout = 30000) path = join([u.server.instance, API_PATH, - string("rooms/", escapeuri(room_id), "/typing/", u.userid)], "/") + 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/types.jl b/src/types.jl index 00cd6f8..8bfa0bd 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 @@ -75,3 +74,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 ab2d18a..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) From 0e8367757c3fab2d0564fe1e366cc74f526b2011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Thu, 8 Nov 2018 14:31:43 +0100 Subject: [PATCH 5/5] remove YAML --- Manifest.toml | 12 ------------ Project.toml | 1 - src/MatrixChat.jl | 1 - src/repl.jl | 9 +++++++-- src/users.jl | 1 + 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 2f41a95..264227f 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -13,12 +13,6 @@ 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" @@ -144,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 979faaa..08e66f0 100644 --- a/Project.toml +++ b/Project.toml @@ -11,4 +11,3 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" 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 bc34605..c299c37 100644 --- a/src/MatrixChat.jl +++ b/src/MatrixChat.jl @@ -2,7 +2,6 @@ module MatrixChat using HTTP using JSON -using YAML using Nettle using Dates diff --git a/src/repl.jl b/src/repl.jl index d5db453..a7dc736 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -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!" diff --git a/src/users.jl b/src/users.jl index 951e68c..298d12f 100644 --- a/src/users.jl +++ b/src/users.jl @@ -26,6 +26,7 @@ function new_user(s::MatrixServer, parsed = String(raw_response.body) write("$(username).json", parsed) + parsed = JSON.json(parsed) MatrixUser(s, parsed["user_id"], parsed["access_token"], parsed["device_id"])