From f20e8d28de97e154ec43120cb4fc07e2792e955a Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Tue, 2 Apr 2019 12:15:41 +0545 Subject: [PATCH] add support for all status type (ostatus) and replase case with if --- .../controllers/util_controller.ex | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 2a1c73111..b661c4363 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -74,38 +74,39 @@ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profil end def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do - case is_status?(acct) do - true -> - {:ok, object} = ActivityPub.fetch_object_from_id(acct) - %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) - redirect(conn, to: "/notice/#{activity_id}") + if is_status?(acct) do + {:ok, object} = ActivityPub.fetch_object_from_id(acct) + %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) + redirect(conn, to: "/notice/#{activity_id}") + else + {err, followee} = OStatus.find_or_make_user(acct) + avatar = User.avatar_url(followee) + name = followee.nickname + id = followee.id - false -> - {err, followee} = OStatus.find_or_make_user(acct) - avatar = User.avatar_url(followee) - name = followee.nickname - id = followee.id - - if !!user do - conn - |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) - else - conn - |> render("follow_login.html", %{ - error: false, - acct: acct, - avatar: avatar, - name: name, - id: id - }) - end + if !!user do + conn + |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) + else + conn + |> render("follow_login.html", %{ + error: false, + acct: acct, + avatar: avatar, + name: name, + id: id + }) + end end end defp is_status?(acct) do case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do - {:ok, %{"type" => "Note"}} -> true - _ -> false + {:ok, %{"type" => type}} when type in ["Article", "Note", "Video", "Page", "Question"] -> + true + + _ -> + false end end