From: Roger Braun Date: Sat, 24 Jun 2017 11:09:46 +0000 (+0200) Subject: Update user data on fetch if it changed. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=6935fc3e010391d647bcec70bd3d6d6cb8de73a0;p=akkoma Update user data on fetch if it changed. --- diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 7fd3a5edd..bb0a3b5b9 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -192,6 +192,11 @@ defmodule Pleroma.Web.OStatus do 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 with {:ok, info} <- gather_user_info(uri) do data = %{ @@ -204,9 +209,7 @@ defmodule Pleroma.Web.OStatus do } with %User{} = user <- User.get_by_ap_id(data.ap_id) do {:ok, user} - else _e -> - cs = User.remote_user_creation(data) - Repo.insert(cs) + else _e -> insert_or_update_user(data) end end end diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index a49d95087..11b618fdb 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -322,4 +322,11 @@ defmodule Pleroma.Web.OStatusTest do assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" 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