add support for all status type (ostatus) and replase case with if

This commit is contained in:
Sachin Joshi 2019-04-02 12:15:41 +05:45
parent 6386c1c9c1
commit f20e8d28de
1 changed files with 27 additions and 26 deletions

View File

@ -74,38 +74,39 @@ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profil
end end
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
case is_status?(acct) do if is_status?(acct) do
true -> {:ok, object} = ActivityPub.fetch_object_from_id(acct)
{:ok, object} = ActivityPub.fetch_object_from_id(acct) %Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"])
%Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"]) redirect(conn, to: "/notice/#{activity_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 -> if !!user do
{err, followee} = OStatus.find_or_make_user(acct) conn
avatar = User.avatar_url(followee) |> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id})
name = followee.nickname else
id = followee.id conn
|> render("follow_login.html", %{
if !!user do error: false,
conn acct: acct,
|> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id}) avatar: avatar,
else name: name,
conn id: id
|> render("follow_login.html", %{ })
error: false, end
acct: acct,
avatar: avatar,
name: name,
id: id
})
end
end end
end end
defp is_status?(acct) do defp is_status?(acct) do
case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do case ActivityPub.fetch_and_contain_remote_object_from_id(acct) do
{:ok, %{"type" => "Note"}} -> true {:ok, %{"type" => type}} when type in ["Article", "Note", "Video", "Page", "Question"] ->
_ -> false true
_ ->
false
end end
end end