Display like activities.
This commit is contained in:
parent
834c84b5dc
commit
d0da40dc81
|
@ -4,6 +4,25 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
|
||||||
|
|
||||||
|
def to_map(%Activity{data: %{"type" => "Like"}} = activity, %{user: user, liked_activity: liked_activity} = opts) do
|
||||||
|
created_at = get_in(activity.data, ["published"])
|
||||||
|
|> date_to_asctime
|
||||||
|
|
||||||
|
text = "#{user.nickname} favorited a status."
|
||||||
|
|
||||||
|
%{
|
||||||
|
"id" => activity.id,
|
||||||
|
"user" => UserRepresenter.to_map(user, opts),
|
||||||
|
"statusnet_html" => text, # TODO: add summary
|
||||||
|
"text" => text,
|
||||||
|
"is_local" => true,
|
||||||
|
"is_post_verb" => false,
|
||||||
|
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
|
||||||
|
"created_at" => created_at,
|
||||||
|
"in_reply_to_status_id" => liked_activity.id,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
|
def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
|
||||||
created_at = get_in(activity.data, ["published"])
|
created_at = get_in(activity.data, ["published"])
|
||||||
|> date_to_asctime
|
|> date_to_asctime
|
||||||
|
|
|
@ -192,6 +192,15 @@ defp activities_to_statuses(activities, opts) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For likes, fetch the liked activity, too.
|
||||||
|
defp activity_to_status(%Activity{data: %{"type" => "Like"}} = activity, opts) do
|
||||||
|
actor = get_in(activity.data, ["actor"])
|
||||||
|
user = Repo.get_by!(User, ap_id: actor)
|
||||||
|
[liked_activity] = Activity.all_by_object_ap_id(activity.data["object"])
|
||||||
|
|
||||||
|
ActivityRepresenter.to_map(activity, Map.merge(opts, %{user: user, liked_activity: liked_activity}))
|
||||||
|
end
|
||||||
|
|
||||||
defp activity_to_status(activity, opts) do
|
defp activity_to_status(activity, opts) do
|
||||||
actor = get_in(activity.data, ["actor"])
|
actor = get_in(activity.data, ["actor"])
|
||||||
user = Repo.get_by!(User, ap_id: actor)
|
user = Repo.get_by!(User, ap_id: actor)
|
||||||
|
|
|
@ -2,7 +2,21 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.{User, Activity, Object}
|
alias Pleroma.{User, Activity, Object}
|
||||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter}
|
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter}
|
||||||
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Builders.UserBuilder
|
alias Pleroma.Builders.UserBuilder
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
test "a like activity" do
|
||||||
|
user = insert(:user)
|
||||||
|
note_activity = insert(:note_activity)
|
||||||
|
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||||
|
|
||||||
|
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||||
|
status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
|
||||||
|
|
||||||
|
assert status["id"] == like_activity.id
|
||||||
|
assert status["in_reply_to_status_id"] == note_activity.id
|
||||||
|
end
|
||||||
|
|
||||||
test "an activity" do
|
test "an activity" do
|
||||||
{:ok, user} = UserBuilder.insert
|
{:ok, user} = UserBuilder.insert
|
||||||
|
|
Loading…
Reference in a new issue