summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2020-07-28 18:42:21 -0400
committerHubert Chathi <hubert@uhoreg.ca>2020-07-28 18:42:21 -0400
commitcf67d09043b7b5170a2245369e459acb725384ba (patch)
tree16df13bc824443a93dea2ab188c1b00e58b592ad /lib
parentadd test for dets (diff)
minor code improvements
Diffstat (limited to 'lib')
-rw-r--r--lib/polyjuice/client.ex4
-rw-r--r--lib/polyjuice/client/sync.ex40
2 files changed, 22 insertions, 22 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex
index 0a28db4..bdf1fde 100644
--- a/lib/polyjuice/client.ex
+++ b/lib/polyjuice/client.ex
@@ -59,9 +59,9 @@ defmodule Polyjuice.Client do
]
@doc "The r0 client URL prefix"
- def prefix_r0, do: "/_matrix/client/r0"
+ def prefix_r0, do: "_matrix/client/r0"
@doc "The unstable client URL prefix"
- def prefix_unstable, do: "/_matrix/client/unstable"
+ def prefix_unstable, do: "_matrix/client/unstable"
defprotocol API do
@moduledoc """
diff --git a/lib/polyjuice/client/sync.ex b/lib/polyjuice/client/sync.ex
index 416c336..47f9555 100644
--- a/lib/polyjuice/client/sync.ex
+++ b/lib/polyjuice/client/sync.ex
@@ -82,21 +82,20 @@ defmodule Polyjuice.Client.Sync do
end
query_params =
- URI.encode_query(
- Enum.reduce(
- opts,
- if filter do
- [{"timeout", @sync_timeout}, {"filter", filter}]
- else
- [{"timeout", @sync_timeout}]
- end,
- fn
- {:full_state, full_state}, acc -> [{"full_state", full_state} | acc]
- {:set_presence, set_presence}, acc -> [{"set_presence", set_presence} | acc]
- _, acc -> acc
- end
- )
+ Enum.reduce(
+ opts,
+ if filter do
+ [{"timeout", @sync_timeout}, {"filter", filter}]
+ else
+ [{"timeout", @sync_timeout}]
+ end,
+ fn
+ {:full_state, full_state}, acc -> [{"full_state", full_state} | acc]
+ {:set_presence, set_presence}, acc -> [{"set_presence", set_presence} | acc]
+ _, acc -> acc
+ end
)
+ |> URI.encode_query()
uri = URI.merge(homeserver_url, @sync_path)
@@ -121,10 +120,9 @@ defmodule Polyjuice.Client.Sync do
uri = state.uri
options = [recv_timeout: @sync_timeout + @buffer_timeout]
- case :hackney.connect(
- URI.to_string(%URI{scheme: uri.scheme, host: uri.host, port: uri.port}),
- options
- ) do
+ case %URI{scheme: uri.scheme, host: uri.host, port: uri.port}
+ |> URI.to_string()
+ |> :hackney.connect(options) do
{:ok, conn_ref} ->
Logger.info("Connected to sync")
state.send.({:connected})
@@ -223,6 +221,7 @@ defmodule Polyjuice.Client.Sync do
if state.backoff, do: :timer.sleep(state.backoff * 1000)
headers = [
+ {"Accept", "application/json"},
{"Authorization", "Bearer #{state.access_token}"}
]
@@ -350,8 +349,9 @@ defmodule Polyjuice.Client.Sync do
defp process_invite(roomname, room, state) do
# The invite state is a map from state type to state key to event.
invite_state =
- Enum.reduce(
- Map.get(room, "invite_state", %{}) |> Map.get("events", []),
+ Map.get(room, "invite_state", %{})
+ |> Map.get("events", [])
+ |> Enum.reduce(
%{},
fn
%{