+ user = User.get_cached_by_ap_id(ap_id) ->
+ user
+
+ user = User.get_by_guessed_nickname(ap_id) ->
+ user
+
+ true ->
+ User.error_user(ap_id)
+ end
+ end
+
+ def render("index.json", opts) do
+ context_ids = collect_context_ids(opts.activities)
+ users = collect_users(opts.activities)
+
+ opts =
+ opts
+ |> Map.put(:context_ids, context_ids)
+ |> Map.put(:users, users)
+
+ safe_render_many(
+ opts.activities,
+ ActivityView,
+ "activity.json",
+ opts
+ )
+ end
+
+ def render("activity.json", %{activity: %{data: %{"type" => "Delete"}} = activity} = opts) do
+ user = get_user(activity.data["actor"], opts)
+ created_at = activity.data["published"] |> Utils.date_to_asctime()
+
+ %{
+ "id" => activity.id,
+ "uri" => activity.data["object"],
+ "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+ "attentions" => [],
+ "statusnet_html" => "deleted notice {{tag",
+ "text" => "deleted notice {{tag",
+ "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" => "delete"
+ }
+ end
+
+ def render("activity.json", %{activity: %{data: %{"type" => "Follow"}} = activity} = opts) do
+ user = get_user(activity.data["actor"], opts)
+ created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
+ created_at = created_at |> Utils.date_to_asctime()
+
+ followed = get_user(activity.data["object"], opts)
+ 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
+ user = get_user(activity.data["actor"], opts)
+ created_at = activity.data["published"] |> Utils.date_to_asctime()
+ announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
+
+ text = "#{user.nickname} retweeted a status."
+
+ retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
+
+ %{
+ "id" => activity.id,
+ "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+ "statusnet_html" => text,
+ "text" => text,
+ "is_local" => activity.local,
+ "is_post_verb" => false,
+ "uri" => "tag:#{activity.data["id"]}:objectType=note",
+ "created_at" => created_at,
+ "retweeted_status" => retweeted_status,
+ "statusnet_conversation_id" => get_context_id(announced_activity, opts),
+ "external_url" => activity.data["id"],
+ "activity_type" => "repeat"
+ }
+ end
+
+ def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do
+ user = get_user(activity.data["actor"], opts)
+ liked_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
+ liked_activity_id = if liked_activity, do: liked_activity.id, else: nil
+
+ created_at =
+ activity.data["published"]
+ |> Utils.date_to_asctime()
+
+ text = "#{user.nickname} favorited a status."
+
+ favorited_status =
+ if liked_activity,
+ do: render("activity.json", Map.merge(opts, %{activity: liked_activity})),
+ else: nil
+
+ %{
+ "id" => activity.id,
+ "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+ "statusnet_html" => text,
+ "text" => text,
+ "is_local" => activity.local,
+ "is_post_verb" => false,
+ "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
+ "created_at" => created_at,
+ "favorited_status" => favorited_status,
+ "in_reply_to_status_id" => liked_activity_id,
+ "external_url" => activity.data["id"],
+ "activity_type" => "like"
+ }
+ end
+
+ def render(
+ "activity.json",
+ %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts
+ ) do
+ user = get_user(activity.data["actor"], opts)
+
+ created_at = object["published"] |> Utils.date_to_asctime()