diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-07-28 18:42:21 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-07-28 18:42:21 -0400 |
commit | cf67d09043b7b5170a2245369e459acb725384ba (patch) | |
tree | 16df13bc824443a93dea2ab188c1b00e58b592ad /lib/polyjuice/client/sync.ex | |
parent | add test for dets (diff) |
minor code improvements
Diffstat (limited to '')
-rw-r--r-- | lib/polyjuice/client/sync.ex | 40 |
1 files changed, 20 insertions, 20 deletions
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 %{ |