"""
def fix_object(object, options \\ []) do
object
+ |> strip_internal_fields
|> fix_actor
|> fix_url
|> fix_attachments
|> fix_emoji
|> fix_tag
|> fix_content_map
- |> fix_likes
|> fix_addressing
|> fix_summary
|> fix_type(options)
|> Map.put("actor", Containment.get_actor(%{"actor" => actor}))
end
- # Check for standardisation
- # This is what Peertube does
- # curl -H 'Accept: application/activity+json' $likes | jq .totalItems
- # Prismo returns only an integer (count) as "likes"
- def fix_likes(%{"likes" => likes} = object) when not is_map(likes) do
- object
- |> Map.put("likes", [])
- |> Map.put("like_count", 0)
- end
-
- def fix_likes(object) do
- object
- end
-
def fix_in_reply_to(object, options \\ [])
def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object, options)
with %User{ap_id: ^actor_id} = actor <- User.get_cached_by_ap_id(object["id"]) do
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(object)
- banner = new_user_data[:info]["banner"]
- locked = new_user_data[:info]["locked"] || false
+ banner = new_user_data[:info][:banner]
+ locked = new_user_data[:info][:locked] || false
update_data =
new_user_data
|> Map.take([:name, :bio, :avatar])
- |> Map.put(:info, %{"banner" => banner, "locked" => locked})
+ |> Map.put(:info, %{banner: banner, locked: locked})
actor
|> User.upgrade_changeset(update_data)
|> add_mention_tags
|> add_emoji_tags
|> add_attributed_to
- |> add_likes
|> prepare_attachments
|> set_conversation
|> set_reply_to_uri
|> Map.put("attributedTo", attributed_to)
end
- def add_likes(%{"id" => id, "like_count" => likes} = object) do
- likes = %{
- "id" => "#{id}/likes",
- "first" => "#{id}/likes?page=1",
- "type" => "OrderedCollection",
- "totalItems" => likes
- }
-
- object
- |> Map.put("likes", likes)
- end
-
- def add_likes(object) do
- object
- end
-
def prepare_attachments(object) do
attachments =
(object["attachment"] || [])
defp strip_internal_fields(object) do
object
|> Map.drop([
+ "likes",
"like_count",
"announcements",
"announcement_count",
PleromaJobQueue.enqueue(:transmogrifier, __MODULE__, [:user_upgrade, user])
end
- if Pleroma.Config.get([:instance, :external_user_synchronization]) do
- update_following_followers_counters(user)
- end
-
{:ok, user}
else
%User{} = user -> {:ok, user}
data
|> maybe_fix_user_url
end
-
- def update_following_followers_counters(user) do
- info = %{}
-
- following = fetch_counter(user.following_address)
- info = if following, do: Map.put(info, :following_count, following), else: info
-
- followers = fetch_counter(user.follower_address)
- info = if followers, do: Map.put(info, :follower_count, followers), else: info
-
- User.set_info_cache(user, info)
- end
-
- defp fetch_counter(url) do
- with {:ok, %{body: body, status: code}} when code in 200..299 <-
- Pleroma.HTTP.get(
- url,
- [{:Accept, "application/activity+json"}]
- ),
- {:ok, data} <- Jason.decode(body) do
- data["totalItems"]
- end
- end
end