Update user data on fetch if it changed.
This commit is contained in:
parent
ffc9d7708b
commit
6935fc3e01
|
@ -192,6 +192,11 @@ def find_or_make_user(uri) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def insert_or_update_user(data) do
|
||||||
|
cs = User.remote_user_creation(data)
|
||||||
|
Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
|
||||||
|
end
|
||||||
|
|
||||||
def make_user(uri) do
|
def make_user(uri) do
|
||||||
with {:ok, info} <- gather_user_info(uri) do
|
with {:ok, info} <- gather_user_info(uri) do
|
||||||
data = %{
|
data = %{
|
||||||
|
@ -204,9 +209,7 @@ def make_user(uri) do
|
||||||
}
|
}
|
||||||
with %User{} = user <- User.get_by_ap_id(data.ap_id) do
|
with %User{} = user <- User.get_by_ap_id(data.ap_id) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else _e ->
|
else _e -> insert_or_update_user(data)
|
||||||
cs = User.remote_user_creation(data)
|
|
||||||
Repo.insert(cs)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -322,4 +322,11 @@ test "it builds a missing status from an html url" do
|
||||||
assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "insert or update a user from given data" do
|
||||||
|
user = insert(:user, %{nickname: "nick@name.de"})
|
||||||
|
data = %{ ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname }
|
||||||
|
|
||||||
|
assert {:ok, %User{}} = OStatus.insert_or_update_user(data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue