diff options
author | Sachin Joshi <satchin.joshi@gmail.com> | 2019-04-01 22:12:02 +0545 |
---|---|---|
committer | Sachin Joshi <satchin.joshi@gmail.com> | 2019-04-01 22:26:58 +0545 |
commit | 1d01e8e656c364b97b9ee36a6173a830d3f5f4fc (patch) | |
tree | 8b7fb86f0a2bf63a8409e8214bca19fd8e76f95a /lib | |
parent | 9e3899bf36cea47560c5de1d4787125f6296a3b8 (diff) | |
download | pleroma-1d01e8e656c364b97b9ee36a6173a830d3f5f4fc.tar.gz |
[OStatus] adds status to pleroma instance if the url given is a status
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/twitter_api/controllers/util_controller.ex | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index faa733fec..7f301a518 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do require Logger alias Comeonin.Pbkdf2 + alias Pleroma.Activity alias Pleroma.Emoji alias Pleroma.Notification alias Pleroma.PasswordResetToken @@ -73,26 +74,39 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do - {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 - }) + 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}") + + 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 end end + defp is_status?(acct) do + %URI{path: path} = URI.parse(acct) + Regex.match?(~r/\/users\/[^\/]+\/statuses\/([0-9]+)$/, path) + end + def do_remote_follow(conn, %{ "authorization" => %{"name" => username, "password" => password, "id" => id} }) do |