diff options
author | William Pitcock <nenolod@dereferenced.org> | 2018-10-05 23:40:49 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2018-10-05 23:40:49 +0000 |
commit | e69faf550cd14cfee8f56f050a2a544b7450367c (patch) | |
tree | 0684403c575ffe7125d2c8ce72ff564907064fa2 /lib/pleroma/user.ex | |
parent | 3e751496e3d5f8c90d5e73d356bebb607d0edb44 (diff) | |
download | pleroma-e69faf550cd14cfee8f56f050a2a544b7450367c.tar.gz |
user: add wait_and_refresh() for async three-way handshake case
Diffstat (limited to 'lib/pleroma/user.ex')
-rw-r--r-- | lib/pleroma/user.ex | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 228f12498..02f13eb2c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -738,4 +738,28 @@ defmodule Pleroma.User do get_or_fetch_by_nickname(uri_or_nickname) end end + + # wait a period of time and return newest version of the User structs + # this is because we have synchronous follow APIs and need to simulate them + # with an async handshake + def wait_and_refresh(_, %User{local: true} = a, %User{local: true} = b) do + with %User{} = a <- Repo.get(User, a.id), + %User{} = b <- Repo.get(User, b.id) do + {:ok, a, b} + else + _e -> + :error + end + end + + def wait_and_refresh(timeout, %User{} = a, %User{} = b) do + with :ok <- :timer.sleep(timeout), + %User{} = a <- Repo.get(User, a.id), + %User{} = b <- Repo.get(User, b.id) do + {:ok, a, b} + else + _e -> + :error + end + end end |