Add remote interaction ui for posts
This commit is contained in:
parent
6ccab516a3
commit
2701628786
3 changed files with 124 additions and 0 deletions
|
@ -0,0 +1,13 @@
|
|||
<%= if @error do %>
|
||||
<h2>Error: <%= @error %></h2>
|
||||
<% else %>
|
||||
<h2>Interacting with <%= @nickname %></h2>
|
||||
<div>
|
||||
<%= @status_id %>
|
||||
</div>
|
||||
<%= form_for @conn, Routes.util_path(@conn, :remote_subscribe), [as: "status"], fn f -> %>
|
||||
<%= hidden_input f, :status, value: @status_id %>
|
||||
<%= text_input f, :profile, placeholder: "Your account ID, e.g. lain@quitter.se" %>
|
||||
<%= submit "Interact" %>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||
|
||||
require Logger
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Emoji
|
||||
alias Pleroma.Healthcheck
|
||||
|
@ -59,6 +60,27 @@ def remote_subscribe(conn, %{"nickname" => nick, "profile" => _}) do
|
|||
end
|
||||
end
|
||||
|
||||
def remote_subscribe(conn, %{"status_id" => id, "profile" => _}) do
|
||||
with %Activity{} = activity <- Activity.get_by_id(id),
|
||||
%User{} = user <- User.get_cached_by_ap_id(activity.actor),
|
||||
avatar = User.avatar_url(user) do
|
||||
conn
|
||||
|> render("status_interact.html", %{
|
||||
status_id: id,
|
||||
nickname: user.nickname,
|
||||
avatar: avatar,
|
||||
error: false
|
||||
})
|
||||
else
|
||||
_e ->
|
||||
render(conn, "status_interact.html", %{
|
||||
status_id: id,
|
||||
avatar: nil,
|
||||
error: "Could not find status"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profile}}) do
|
||||
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile),
|
||||
%User{ap_id: ap_id} <- User.get_cached_by_nickname(nick) do
|
||||
|
@ -74,6 +96,31 @@ def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profil
|
|||
end
|
||||
end
|
||||
|
||||
def remote_subscribe(conn, %{"status" => %{"status_id" => id, "profile" => profile}}) do
|
||||
get_ap_id = fn activity ->
|
||||
object = Pleroma.Object.normalize(activity, fetch: false)
|
||||
|
||||
case object do
|
||||
%{data: %{"id" => ap_id}} -> {:ok, ap_id}
|
||||
_ -> {:no_ap_id, nil}
|
||||
end
|
||||
end
|
||||
|
||||
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile),
|
||||
%Activity{} = activity <- Activity.get_by_id(id),
|
||||
{:ok, ap_id} <- get_ap_id.(activity) do
|
||||
conn
|
||||
|> Phoenix.Controller.redirect(external: String.replace(template, "{uri}", ap_id))
|
||||
else
|
||||
_e ->
|
||||
render(conn, "status_interact.html", %{
|
||||
status_id: id,
|
||||
avatar: nil,
|
||||
error: "Something went wrong."
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def remote_interaction(%{body_params: %{ap_id: ap_id, profile: profile}} = conn, _params) do
|
||||
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do
|
||||
conn
|
||||
|
|
|
@ -233,6 +233,70 @@ test "it renders form with error when user not found", %{conn: conn} do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /main/ostatus - remote_subscribe/2 - with statuses" do
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
test "renders subscribe form", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
status = insert(:note_activity, %{user: user})
|
||||
status_id = status.id
|
||||
|
||||
assert is_binary(status_id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{"status_id" => status_id, "profile" => ""})
|
||||
|> response(:ok)
|
||||
|
||||
refute response =~ "Could not find status"
|
||||
assert response =~ "Interacting with"
|
||||
end
|
||||
|
||||
test "renders subscribe form with error when status not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{"status_id" => "somerandomid", "profile" => ""})
|
||||
|> response(:ok)
|
||||
|
||||
assert response =~ "Could not find status"
|
||||
refute response =~ "Interacting with"
|
||||
end
|
||||
|
||||
test "it redirect to webfinger url", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
status = insert(:note_activity, %{user: user})
|
||||
status_id = status.id
|
||||
status_ap_id = status.data["object"]
|
||||
|
||||
assert is_binary(status_id)
|
||||
assert is_binary(status_ap_id)
|
||||
|
||||
user2 = insert(:user, ap_id: "shp@social.heldscal.la")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> post("/main/ostatus", %{
|
||||
"status" => %{"status_id" => status_id, "profile" => user2.ap_id}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) ==
|
||||
"https://social.heldscal.la/main/ostatussub?profile=#{status_ap_id}"
|
||||
end
|
||||
|
||||
test "it renders form with error when status not found", %{conn: conn} do
|
||||
user2 = insert(:user, ap_id: "shp@social.heldscal.la")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/main/ostatus", %{
|
||||
"status" => %{"status_id" => "somerandomid", "profile" => user2.ap_id}
|
||||
})
|
||||
|> response(:ok)
|
||||
|
||||
assert response =~ "Something went wrong."
|
||||
end
|
||||
end
|
||||
|
||||
test "it returns new captcha", %{conn: conn} do
|
||||
with_mock Pleroma.Captcha,
|
||||
new: fn -> "test_captcha" end do
|
||||
|
|
Loading…
Reference in a new issue