summaryrefslogtreecommitdiff
path: root/lib/polyjuice/client/sync.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/polyjuice/client/sync.ex')
-rw-r--r--lib/polyjuice/client/sync.ex23
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/polyjuice/client/sync.ex b/lib/polyjuice/client/sync.ex
index 3ac6f8a..573af71 100644
--- a/lib/polyjuice/client/sync.ex
+++ b/lib/polyjuice/client/sync.ex
@@ -26,6 +26,7 @@ defmodule Polyjuice.Client.Sync do
:handler,
:conn_ref,
:id,
+ :pid,
:homeserver_url,
:uri,
:storage,
@@ -45,6 +46,7 @@ defmodule Polyjuice.Client.Sync do
def sync(
homeserver_url,
id,
+ pid,
opts
) do
storage = Keyword.fetch!(opts, :storage)
@@ -92,6 +94,7 @@ defmodule Polyjuice.Client.Sync do
connect(%__MODULE__{
handler: handler,
id: id,
+ pid: pid,
homeserver_url: homeserver_url,
uri: uri,
query_params: query_params,
@@ -138,13 +141,7 @@ defmodule Polyjuice.Client.Sync do
e = &URI.encode_www_form/1
- {access_token, user_id} =
- Agent.get(
- Polyjuice.Client.process_name(state.id, :state),
- fn %{access_token: access_token, user_id: user_id} ->
- {access_token, user_id}
- end
- )
+ %{access_token: access_token, user_id: user_id} = GenServer.call(state.pid, :get_state)
path =
URI.merge(
@@ -202,7 +199,7 @@ defmodule Polyjuice.Client.Sync do
:hackney.close(state.conn_ref)
Polyjuice.Client.set_logged_out(
- state.id,
+ state.pid,
state.storage,
state.handler,
Map.get(json_body, "soft_logout", false)
@@ -245,11 +242,7 @@ defmodule Polyjuice.Client.Sync do
defp do_sync(state) do
if state.backoff, do: :timer.sleep(state.backoff * 1000)
- access_token =
- Agent.get(
- Polyjuice.Client.process_name(state.id, :state),
- fn %{access_token: access_token} -> access_token end
- )
+ %{access_token: access_token} = GenServer.call(state.pid, :get_state)
headers = [
{"Accept", "application/json"},
@@ -298,7 +291,7 @@ defmodule Polyjuice.Client.Sync do
:hackney.close(state.conn_ref)
Polyjuice.Client.set_logged_out(
- state.id,
+ state.pid,
state.storage,
state.handler,
Map.get(json_body, "soft_logout", false)
@@ -429,7 +422,7 @@ defmodule Polyjuice.Client.Sync do
end
)
- user_id = Agent.get(Polyjuice.Client.process_name(state.id, :state), &Map.get(&1, :user_id))
+ %{user_id: user_id} = GenServer.call(state.pid, :get_state)
inviter =
invite_state