TwApi ActivityView: Add follows.
This commit is contained in:
parent
4afbef39f4
commit
1f32ba052c
|
@ -8,6 +8,29 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
|
|
||||||
|
def render("activity.json", %{activity: %{data: %{"type" => "Follow"}} = activity} = opts) do
|
||||||
|
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||||
|
created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
|
||||||
|
created_at = created_at |> Utils.date_to_asctime()
|
||||||
|
|
||||||
|
followed = User.get_cached_by_ap_id(activity.data["object"])
|
||||||
|
text = "#{user.nickname} started following #{followed.nickname}"
|
||||||
|
|
||||||
|
%{
|
||||||
|
"id" => activity.id,
|
||||||
|
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
|
||||||
|
"attentions" => [],
|
||||||
|
"statusnet_html" => text,
|
||||||
|
"text" => text,
|
||||||
|
"is_local" => activity.local,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"created_at" => created_at,
|
||||||
|
"in_reply_to_status_id" => nil,
|
||||||
|
"external_url" => activity.data["id"],
|
||||||
|
"activity_type" => "follow"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activity} = opts) do
|
def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activity} = opts) do
|
||||||
user = User.get_by_ap_id(activity.data["actor"])
|
user = User.get_by_ap_id(activity.data["actor"])
|
||||||
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
created_at = activity.data["published"] |> Utils.date_to_asctime()
|
||||||
|
@ -15,7 +38,6 @@ def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activ
|
||||||
|
|
||||||
text = "#{user.nickname} retweeted a status."
|
text = "#{user.nickname} retweeted a status."
|
||||||
|
|
||||||
# retweeted_status = to_map(announced_activity, Map.merge(%{user: announced_user}, opts))
|
|
||||||
retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
|
retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -8,6 +8,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
||||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
test "a create activity with a note" do
|
test "a create activity with a note" do
|
||||||
|
@ -119,4 +121,31 @@ test "an announce activity" do
|
||||||
|
|
||||||
assert result == expected
|
assert result == expected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "A follow activity" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user, %{nickname: "shp"})
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||||
|
{:ok, follower} = User.follow(user, other_user)
|
||||||
|
{:ok, follow} = ActivityPub.follow(follower, other_user)
|
||||||
|
|
||||||
|
result = ActivityView.render("activity.json", activity: follow)
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
"activity_type" => "follow",
|
||||||
|
"attentions" => [],
|
||||||
|
"created_at" => follow.data["published"] |> Utils.date_to_asctime(),
|
||||||
|
"external_url" => follow.data["id"],
|
||||||
|
"id" => follow.id,
|
||||||
|
"in_reply_to_status_id" => nil,
|
||||||
|
"is_local" => true,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"statusnet_html" => "#{user.nickname} started following shp",
|
||||||
|
"text" => "#{user.nickname} started following shp",
|
||||||
|
"user" => UserView.render("show.json", user: user)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert result == expected
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue