- object = Object.normalize(activity, fetch: false)
-
- user = CommonAPI.get_user(activity.data["actor"])
- user_follower_address = user.follower_address
-
- like_count = object.data["like_count"] || 0
- announcement_count = object.data["announcement_count"] || 0
-
- hashtags = Object.hashtags(object)
- sensitive = object.data["sensitive"] || Enum.member?(hashtags, "nsfw")
-
- tags = Object.tags(object)
-
- tag_mentions =
- tags
- |> Enum.filter(fn tag -> is_map(tag) and tag["type"] == "Mention" end)
- |> Enum.map(fn tag -> tag["href"] end)
-
- mentions =
- (object.data["to"] ++ tag_mentions)
- |> Enum.uniq()
- |> Enum.map(fn
- Pleroma.Constants.as_public() -> nil
- ^user_follower_address -> nil
- ap_id -> User.get_cached_by_ap_id(ap_id)
- end)
- |> Enum.filter(& &1)
- |> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
-
- favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
-
- bookmarked = Activity.get_bookmark(activity, opts[:for]) != nil
-
- client_posted_this_activity = opts[:for] && user.id == opts[:for].id
-
- expires_at =
- with true <- client_posted_this_activity,
- %Oban.Job{scheduled_at: scheduled_at} <-
- Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id) do
- scheduled_at
- else
- _ -> nil
- end
-
- thread_muted? =
- cond do
- is_nil(opts[:for]) -> false
- is_boolean(activity.thread_muted?) -> activity.thread_muted?
- true -> CommonAPI.thread_muted?(opts[:for], activity)
- end
-
- attachment_data = object.data["attachment"] || []
- attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
-
- created_at = Utils.to_masto_date(object.data["published"])
-
- edited_at =
- with %{"updated" => updated} <- object.data,
- date <- Utils.to_masto_date(updated),
- true <- date != "" do
- date
- else
- _ ->
- nil
- end
-
- reply_to = get_reply_to(activity, opts)
-
- reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
-
- history_len =
- 1 +
- (Object.Updater.history_for(object.data)
- |> Map.get("orderedItems")
- |> length())
-
- # See render("history.json", ...) for more details
- # Here the implicit index of the current content is 0
- chrono_order = history_len - 1
-
- content =
- object
- |> render_content()
-
- content_html =
- content
- |> Activity.HTML.get_cached_scrubbed_html_for_activity(
- User.html_filter_policy(opts[:for]),
- activity,
- "mastoapi:content:#{chrono_order}"
- )
-
- content_plaintext =
- content
- |> Activity.HTML.get_cached_stripped_html_for_activity(
- activity,
- "mastoapi:content:#{chrono_order}"
- )
-
- summary = object.data["summary"] || ""
-
- card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity))
+ with %Object{} = object <- Object.normalize(activity, fetch: false) do
+ user = CommonAPI.get_user(activity.data["actor"])
+ user_follower_address = user.follower_address
+
+ like_count = object.data["like_count"] || 0
+ announcement_count = object.data["announcement_count"] || 0
+
+ hashtags = Object.hashtags(object)
+ sensitive = object.data["sensitive"] || Enum.member?(hashtags, "nsfw")
+
+ tags = Object.tags(object)
+
+ tag_mentions =
+ tags
+ |> Enum.filter(fn tag -> is_map(tag) and tag["type"] == "Mention" end)
+ |> Enum.map(fn tag -> tag["href"] end)
+
+ to_data = if is_nil(object.data["to"]), do: [], else: object.data["to"]
+
+ mentions =
+ (to_data ++ tag_mentions)
+ |> Enum.uniq()
+ |> Enum.map(fn
+ Pleroma.Constants.as_public() -> nil
+ ^user_follower_address -> nil
+ ap_id -> User.get_cached_by_ap_id(ap_id)
+ end)
+ |> Enum.filter(& &1)
+ |> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
+
+ favorited = opts[:for] && opts[:for].ap_id in (object.data["likes"] || [])
+
+ bookmarked = Activity.get_bookmark(activity, opts[:for]) != nil
+
+ client_posted_this_activity = opts[:for] && user.id == opts[:for].id
+
+ expires_at =
+ with true <- client_posted_this_activity,
+ %Oban.Job{scheduled_at: scheduled_at} <-
+ Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id) do
+ scheduled_at
+ else
+ _ -> nil
+ end
+
+ thread_muted? =
+ cond do
+ is_nil(opts[:for]) -> false
+ is_boolean(activity.thread_muted?) -> activity.thread_muted?
+ true -> CommonAPI.thread_muted?(opts[:for], activity)
+ end
+
+ attachment_data = object.data["attachment"] || []
+ attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
+
+ created_at = Utils.to_masto_date(object.data["published"])
+
+ edited_at =
+ with %{"updated" => updated} <- object.data,
+ date <- Utils.to_masto_date(updated),
+ true <- date != "" do
+ date
+ else
+ _ ->
+ nil
+ end
+
+ reply_to = get_reply_to(activity, opts)
+
+ reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
+
+ history_len =
+ 1 +
+ (Object.Updater.history_for(object.data)
+ |> Map.get("orderedItems")
+ |> length())
+
+ # See render("history.json", ...) for more details
+ # Here the implicit index of the current content is 0
+ chrono_order = history_len - 1
+
+ content =
+ object
+ |> render_content()
+
+ content_html =
+ content
+ |> Activity.HTML.get_cached_scrubbed_html_for_activity(
+ User.html_filter_policy(opts[:for]),
+ activity,
+ "mastoapi:content:#{chrono_order}"
+ )