From d00571ff75567aa43618f660205faeac6e9485fb Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 18 Jun 2017 17:20:39 +0200 Subject: [PATCH] Fetch user feed on externalprofile request. This is so we always have something to show. --- lib/pleroma/web/twitter_api/twitter_api.ex | 6 ++++++ test/web/twitter_api/twitter_api_test.exs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 07ac30cb2..8e36ba3f4 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -9,6 +9,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do import Ecto.Query import Pleroma.Web.TwitterAPI.Utils + @httpoison Application.get_env(:pleroma, :httpoison) + def to_for_user_and_mentions(user, mentions, inReplyTo) do default_to = [ User.ap_followers(user), @@ -298,6 +300,10 @@ def conversation_id_to_context(id) do def get_external_profile(for_user, uri) do with {:ok, %User{} = user} <- OStatus.find_or_make_user(uri) do + with url <- user.info["topic"], + {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do + OStatus.handle_incoming(body) + end {:ok, UserRepresenter.to_map(user, %{for: for_user})} else _e -> {:error, "Couldn't find user"} diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 6848413cc..adea67422 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -353,10 +353,15 @@ test "returns an existing mapping for an existing object" do describe "fetching a user by uri" do test "fetches a user by uri" do + id = "https://mastodon.social/users/lambadalambda" user = insert(:user) + {:ok, represented} = TwitterAPI.get_external_profile(user, id) + remote = User.get_by_ap_id(id) - {:ok, represented} = TwitterAPI.get_external_profile(user, user.ap_id) - assert represented = UserRepresenter.to_map(user, %{for: user}) + assert represented == UserRepresenter.to_map(remote, %{for: user}) + + # Also fetches the feed. + assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status") end end end