1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Utils do
9 alias Pleroma.Notification
14 alias Pleroma.Web.ActivityPub.ActivityPub
15 alias Pleroma.Web.ActivityPub.Visibility
16 alias Pleroma.Web.AdminAPI.AccountView
17 alias Pleroma.Web.Endpoint
18 alias Pleroma.Web.Router.Helpers
23 require Pleroma.Constants
25 @supported_object_types [
35 @strip_status_report_states ~w(closed resolved)
36 @supported_report_states ~w(open closed resolved)
37 @valid_visibilities ~w(public unlisted private direct)
39 # Some implementations send the actor URI as the actor field, others send the entire actor object,
40 # so figure out what the actor's URI is based on what we have.
41 def get_ap_id(%{"id" => id} = _), do: id
42 def get_ap_id(id), do: id
44 def normalize_params(params) do
45 Map.put(params, "actor", get_ap_id(params["actor"]))
48 @spec determine_explicit_mentions(map()) :: map()
49 def determine_explicit_mentions(%{"tag" => tag} = _) when is_list(tag) do
51 %{"type" => "Mention", "href" => href} -> [href]
56 def determine_explicit_mentions(%{"tag" => tag} = object) when is_map(tag) do
58 |> Map.put("tag", [tag])
59 |> determine_explicit_mentions()
62 def determine_explicit_mentions(_), do: []
64 @spec label_in_collection?(any(), any()) :: boolean()
65 defp label_in_collection?(ap_id, coll) when is_binary(coll), do: ap_id == coll
66 defp label_in_collection?(ap_id, coll) when is_list(coll), do: ap_id in coll
67 defp label_in_collection?(_, _), do: false
69 @spec label_in_message?(String.t(), map()) :: boolean()
70 def label_in_message?(label, params),
72 [params["to"], params["cc"], params["bto"], params["bcc"]]
73 |> Enum.any?(&label_in_collection?(label, &1))
75 @spec unaddressed_message?(map()) :: boolean()
76 def unaddressed_message?(params),
78 [params["to"], params["cc"], params["bto"], params["bcc"]]
79 |> Enum.all?(&is_nil(&1))
81 @spec recipient_in_message(User.t(), User.t(), map()) :: boolean()
82 def recipient_in_message(%User{ap_id: ap_id} = recipient, %User{} = actor, params),
84 label_in_message?(ap_id, params) || unaddressed_message?(params) ||
85 User.following?(recipient, actor)
87 defp extract_list(target) when is_binary(target), do: [target]
88 defp extract_list(lst) when is_list(lst), do: lst
89 defp extract_list(_), do: []
91 def maybe_splice_recipient(ap_id, params) do
93 !label_in_collection?(ap_id, params["to"]) &&
94 !label_in_collection?(ap_id, params["cc"])
97 cc_list = extract_list(params["cc"])
98 Map.put(params, "cc", [ap_id | cc_list])
104 def make_json_ld_header do
107 "https://www.w3.org/ns/activitystreams",
108 "#{Web.base_url()}/schemas/litepub-0.1.jsonld",
117 DateTime.utc_now() |> DateTime.to_iso8601()
120 def generate_activity_id do
121 generate_id("activities")
124 def generate_context_id do
125 generate_id("contexts")
128 def generate_object_id do
129 Helpers.o_status_url(Endpoint, :object, UUID.generate())
132 def generate_id(type) do
133 "#{Web.base_url()}/#{type}/#{UUID.generate()}"
136 def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do
137 fake_create_activity = %{
138 "to" => object["to"],
139 "cc" => object["cc"],
144 get_notified_from_object(fake_create_activity)
147 def get_notified_from_object(object) do
148 Notification.get_notified_from_activity(%Activity{data: object}, false)
151 def create_context(context) do
152 context = context || generate_id("contexts")
154 # Ecto has problems accessing the constraint inside the jsonb,
155 # so we explicitly check for the existed object before insert
156 object = Object.get_cached_by_ap_id(context)
158 with true <- is_nil(object),
159 changeset <- Object.context_mapping(context),
160 {:ok, inserted_object} <- Repo.insert(changeset) do
169 Enqueues an activity for federation if it's local
171 @spec maybe_federate(any()) :: :ok
172 def maybe_federate(%Activity{local: true} = activity) do
173 if Pleroma.Config.get!([:instance, :federating]) do
174 Pleroma.Web.Federator.publish(activity)
180 def maybe_federate(_), do: :ok
183 Adds an id and a published data if they aren't there,
184 also adds it to an included object
186 @spec lazy_put_activity_defaults(map(), boolean) :: map()
187 def lazy_put_activity_defaults(map, fake? \\ false)
189 def lazy_put_activity_defaults(map, true) do
191 |> Map.put_new("id", "pleroma:fakeid")
192 |> Map.put_new_lazy("published", &make_date/0)
193 |> Map.put_new("context", "pleroma:fakecontext")
194 |> Map.put_new("context_id", -1)
195 |> lazy_put_object_defaults(true)
198 def lazy_put_activity_defaults(map, _fake?) do
199 %{data: %{"id" => context}, id: context_id} = create_context(map["context"])
202 |> Map.put_new_lazy("id", &generate_activity_id/0)
203 |> Map.put_new_lazy("published", &make_date/0)
204 |> Map.put_new("context", context)
205 |> Map.put_new("context_id", context_id)
206 |> lazy_put_object_defaults(false)
209 # Adds an id and published date if they aren't there.
211 @spec lazy_put_object_defaults(map(), boolean()) :: map()
212 defp lazy_put_object_defaults(%{"object" => map} = activity, true)
216 |> Map.put_new("id", "pleroma:fake_object_id")
217 |> Map.put_new_lazy("published", &make_date/0)
218 |> Map.put_new("context", activity["context"])
219 |> Map.put_new("context_id", activity["context_id"])
220 |> Map.put_new("fake", true)
222 %{activity | "object" => object}
225 defp lazy_put_object_defaults(%{"object" => map} = activity, _)
229 |> Map.put_new_lazy("id", &generate_object_id/0)
230 |> Map.put_new_lazy("published", &make_date/0)
231 |> Map.put_new("context", activity["context"])
232 |> Map.put_new("context_id", activity["context_id"])
234 %{activity | "object" => object}
237 defp lazy_put_object_defaults(activity, _), do: activity
240 Inserts a full object if it is contained in an activity.
242 def insert_full_object(%{"object" => %{"type" => type} = object_data} = map)
243 when is_map(object_data) and type in @supported_object_types do
244 with {:ok, object} <- Object.create(object_data) do
245 map = Map.put(map, "object", object.data["id"])
251 def insert_full_object(map), do: {:ok, map, nil}
253 #### Like-related helpers
256 Returns an existing like if a user already liked an object
258 @spec get_existing_like(String.t(), map()) :: Activity.t() | nil
259 def get_existing_like(actor, %{data: %{"id" => id}}) do
261 |> Activity.Queries.by_actor()
262 |> Activity.Queries.by_object_id(id)
263 |> Activity.Queries.by_type("Like")
269 Returns like activities targeting an object
271 def get_object_likes(%{data: %{"id" => id}}) do
273 |> Activity.Queries.by_object_id()
274 |> Activity.Queries.by_type("Like")
278 @spec make_like_data(User.t(), map(), String.t()) :: map()
280 %User{ap_id: ap_id} = actor,
281 %{data: %{"actor" => object_actor_id, "id" => id}} = object,
284 object_actor = User.get_cached_by_ap_id(object_actor_id)
287 if Visibility.is_public?(object) do
288 [actor.follower_address, object.data["actor"]]
290 [object.data["actor"]]
294 (object.data["to"] ++ (object.data["cc"] || []))
295 |> List.delete(actor.ap_id)
296 |> List.delete(object_actor.follower_address)
304 "context" => object.data["context"]
306 |> maybe_put("id", activity_id)
309 def make_emoji_reaction_data(user, object, emoji, activity_id) do
310 make_like_data(user, object, activity_id)
311 |> Map.put("type", "EmojiReaction")
312 |> Map.put("content", emoji)
315 @spec update_element_in_object(String.t(), list(any), Object.t()) ::
316 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
317 def update_element_in_object(property, element, object) do
319 if is_map(element) do
332 %{"#{property}_count" => length, "#{property}s" => element}
336 |> Changeset.change(data: data)
337 |> Object.update_and_set_cache()
340 @spec add_emoji_reaction_to_object(Activity.t(), Object.t()) ::
341 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
343 def add_emoji_reaction_to_object(
344 %Activity{data: %{"content" => emoji, "actor" => actor}},
347 reactions = object.data["reactions"] || %{}
348 emoji_actors = reactions[emoji] || []
349 new_emoji_actors = [actor | emoji_actors] |> Enum.uniq()
350 new_reactions = Map.put(reactions, emoji, new_emoji_actors)
351 update_element_in_object("reaction", new_reactions, object)
354 def remove_emoji_reaction_from_object(
355 %Activity{data: %{"content" => emoji, "actor" => actor}},
358 reactions = object.data["reactions"] || %{}
359 emoji_actors = reactions[emoji] || []
360 new_emoji_actors = List.delete(emoji_actors, actor)
363 if new_emoji_actors == [] do
364 Map.delete(reactions, emoji)
366 Map.put(reactions, emoji, new_emoji_actors)
369 update_element_in_object("reaction", new_reactions, object)
372 @spec add_like_to_object(Activity.t(), Object.t()) ::
373 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
374 def add_like_to_object(%Activity{data: %{"actor" => actor}}, object) do
375 [actor | fetch_likes(object)]
377 |> update_likes_in_object(object)
380 @spec remove_like_from_object(Activity.t(), Object.t()) ::
381 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
382 def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do
385 |> List.delete(actor)
386 |> update_likes_in_object(object)
389 defp update_likes_in_object(likes, object) do
390 update_element_in_object("like", likes, object)
393 defp fetch_likes(object) do
394 if is_list(object.data["likes"]) do
401 #### Follow-related helpers
404 Updates a follow activity's state (for locked accounts).
406 @spec update_follow_state_for_all(Activity.t(), String.t()) :: {:ok, Activity} | {:error, any()}
407 def update_follow_state_for_all(
408 %Activity{data: %{"actor" => actor, "object" => object}} = activity,
412 |> Activity.Queries.by_type()
413 |> Activity.Queries.by_actor(actor)
414 |> Activity.Queries.by_object_id(object)
415 |> where(fragment("data->>'state' = 'pending'"))
416 |> update(set: [data: fragment("jsonb_set(data, '{state}', ?)", ^state)])
417 |> Repo.update_all([])
419 User.set_follow_state_cache(actor, object, state)
421 activity = Activity.get_by_id(activity.id)
426 def update_follow_state(
427 %Activity{data: %{"actor" => actor, "object" => object}} = activity,
430 new_data = Map.put(activity.data, "state", state)
431 changeset = Changeset.change(activity, data: new_data)
433 with {:ok, activity} <- Repo.update(changeset) do
434 User.set_follow_state_cache(actor, object, state)
440 Makes a follow activity data for the given follower and followed
442 def make_follow_data(
443 %User{ap_id: follower_id},
444 %User{ap_id: followed_id} = _followed,
449 "actor" => follower_id,
450 "to" => [followed_id],
451 "cc" => [Pleroma.Constants.as_public()],
452 "object" => followed_id,
455 |> maybe_put("id", activity_id)
458 def fetch_latest_follow(%User{ap_id: follower_id}, %User{ap_id: followed_id}) do
460 |> Activity.Queries.by_type()
461 |> where(actor: ^follower_id)
462 # this is to use the index
463 |> Activity.Queries.by_object_id(followed_id)
464 |> order_by([activity], fragment("? desc nulls last", activity.id))
469 def get_latest_reaction(internal_activity_id, %{ap_id: ap_id}, emoji) do
470 %{data: %{"object" => object_ap_id}} = Activity.get_by_id(internal_activity_id)
473 |> Activity.Queries.by_type()
474 |> where(actor: ^ap_id)
475 |> where([activity], fragment("?->>'content' = ?", activity.data, ^emoji))
476 |> Activity.Queries.by_object_id(object_ap_id)
477 |> order_by([activity], fragment("? desc nulls last", activity.id))
482 #### Announce-related helpers
485 Retruns an existing announce activity if the notice has already been announced
487 @spec get_existing_announce(String.t(), map()) :: Activity.t() | nil
488 def get_existing_announce(actor, %{data: %{"id" => ap_id}}) do
490 |> Activity.Queries.by_type()
491 |> where(actor: ^actor)
492 # this is to use the index
493 |> Activity.Queries.by_object_id(ap_id)
498 Make announce activity data for the given actor and object
500 # for relayed messages, we only want to send to subscribers
501 def make_announce_data(
502 %User{ap_id: ap_id} = user,
503 %Object{data: %{"id" => id}} = object,
508 "type" => "Announce",
511 "to" => [user.follower_address],
513 "context" => object.data["context"]
515 |> maybe_put("id", activity_id)
518 def make_announce_data(
519 %User{ap_id: ap_id} = user,
520 %Object{data: %{"id" => id}} = object,
525 "type" => "Announce",
528 "to" => [user.follower_address, object.data["actor"]],
529 "cc" => [Pleroma.Constants.as_public()],
530 "context" => object.data["context"]
532 |> maybe_put("id", activity_id)
536 Make unannounce activity data for the given actor and object
538 def make_unannounce_data(
539 %User{ap_id: ap_id} = user,
540 %Activity{data: %{"context" => context, "object" => object}} = activity,
543 object = Object.normalize(object)
548 "object" => activity.data,
549 "to" => [user.follower_address, object.data["actor"]],
550 "cc" => [Pleroma.Constants.as_public()],
553 |> maybe_put("id", activity_id)
556 def make_unlike_data(
557 %User{ap_id: ap_id} = user,
558 %Activity{data: %{"context" => context, "object" => object}} = activity,
561 object = Object.normalize(object)
566 "object" => activity.data,
567 "to" => [user.follower_address, object.data["actor"]],
568 "cc" => [Pleroma.Constants.as_public()],
571 |> maybe_put("id", activity_id)
575 %User{ap_id: actor, follower_address: follower_address},
577 data: %{"id" => undone_activity_id, "context" => context},
578 actor: undone_activity_actor
585 "object" => undone_activity_id,
586 "to" => [follower_address, undone_activity_actor],
587 "cc" => [Pleroma.Constants.as_public()],
590 |> maybe_put("id", activity_id)
593 @spec add_announce_to_object(Activity.t(), Object.t()) ::
594 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
595 def add_announce_to_object(
596 %Activity{data: %{"actor" => actor}},
599 unless actor |> User.get_cached_by_ap_id() |> User.invisible?() do
600 announcements = take_announcements(object)
602 with announcements <- Enum.uniq([actor | announcements]) do
603 update_element_in_object("announcement", announcements, object)
610 def add_announce_to_object(_, object), do: {:ok, object}
612 @spec remove_announce_from_object(Activity.t(), Object.t()) ::
613 {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
614 def remove_announce_from_object(%Activity{data: %{"actor" => actor}}, object) do
615 with announcements <- List.delete(take_announcements(object), actor) do
616 update_element_in_object("announcement", announcements, object)
620 defp take_announcements(%{data: %{"announcements" => announcements}} = _)
621 when is_list(announcements),
624 defp take_announcements(_), do: []
626 #### Unfollow-related helpers
628 def make_unfollow_data(follower, followed, follow_activity, activity_id) do
631 "actor" => follower.ap_id,
632 "to" => [followed.ap_id],
633 "object" => follow_activity.data
635 |> maybe_put("id", activity_id)
638 #### Block-related helpers
639 @spec fetch_latest_block(User.t(), User.t()) :: Activity.t() | nil
640 def fetch_latest_block(%User{ap_id: blocker_id}, %User{ap_id: blocked_id}) do
642 |> Activity.Queries.by_type()
643 |> where(actor: ^blocker_id)
644 # this is to use the index
645 |> Activity.Queries.by_object_id(blocked_id)
646 |> order_by([activity], fragment("? desc nulls last", activity.id))
651 def make_block_data(blocker, blocked, activity_id) do
654 "actor" => blocker.ap_id,
655 "to" => [blocked.ap_id],
656 "object" => blocked.ap_id
658 |> maybe_put("id", activity_id)
661 def make_unblock_data(blocker, blocked, block_activity, activity_id) do
664 "actor" => blocker.ap_id,
665 "to" => [blocked.ap_id],
666 "object" => block_activity.data
668 |> maybe_put("id", activity_id)
671 #### Create-related helpers
673 def make_create_data(params, additional) do
674 published = params.published || make_date()
678 "to" => params.to |> Enum.uniq(),
679 "actor" => params.actor.ap_id,
680 "object" => params.object,
681 "published" => published,
682 "context" => params.context
684 |> Map.merge(additional)
687 #### Listen-related helpers
688 def make_listen_data(params, additional) do
689 published = params.published || make_date()
693 "to" => params.to |> Enum.uniq(),
694 "actor" => params.actor.ap_id,
695 "object" => params.object,
696 "published" => published,
697 "context" => params.context
699 |> Map.merge(additional)
702 #### Flag-related helpers
703 @spec make_flag_data(map(), map()) :: map()
704 def make_flag_data(%{actor: actor, context: context, content: content} = params, additional) do
707 "actor" => actor.ap_id,
708 "content" => content,
709 "object" => build_flag_object(params),
710 "context" => context,
713 |> Map.merge(additional)
716 def make_flag_data(_, _), do: %{}
718 defp build_flag_object(%{account: account, statuses: statuses} = _) do
719 [account.ap_id] ++ build_flag_object(%{statuses: statuses})
722 defp build_flag_object(%{statuses: statuses}) do
723 Enum.map(statuses || [], &build_flag_object/1)
726 defp build_flag_object(act) when is_map(act) or is_binary(act) do
729 %Activity{} = act -> act.data["id"]
730 act when is_map(act) -> act["id"]
731 act when is_binary(act) -> act
734 case Activity.get_by_ap_id_with_object(id) do
735 %Activity{} = activity ->
738 "id" => activity.data["id"],
739 "content" => activity.object.data["content"],
740 "published" => activity.object.data["published"],
742 AccountView.render("show.json", %{
743 user: User.get_by_ap_id(activity.object.data["actor"])
748 %{"id" => id, "deleted" => true}
752 defp build_flag_object(_), do: []
755 Fetches the OrderedCollection/OrderedCollectionPage from `from`, limiting the amount of pages fetched after
756 the first one to `pages_left` pages.
757 If the amount of pages is higher than the collection has, it returns whatever was there.
759 def fetch_ordered_collection(from, pages_left, acc \\ []) do
760 with {:ok, response} <- Tesla.get(from),
761 {:ok, collection} <- Jason.decode(response.body) do
762 case collection["type"] do
763 "OrderedCollection" ->
764 # If we've encountered the OrderedCollection and not the page,
765 # just call the same function on the page address
766 fetch_ordered_collection(collection["first"], pages_left)
768 "OrderedCollectionPage" ->
770 # There are still more pages
771 if Map.has_key?(collection, "next") do
772 # There are still more pages, go deeper saving what we have into the accumulator
773 fetch_ordered_collection(
776 acc ++ collection["orderedItems"]
779 # No more pages left, just return whatever we already have
780 acc ++ collection["orderedItems"]
783 # Got the amount of pages needed, add them all to the accumulator
784 acc ++ collection["orderedItems"]
788 {:error, "Not an OrderedCollection or OrderedCollectionPage"}
793 #### Report-related helpers
794 def get_reports(params, page, page_size) do
797 |> Map.put("type", "Flag")
798 |> Map.put("skip_preload", true)
799 |> Map.put("preload_report_notes", true)
800 |> Map.put("total", true)
801 |> Map.put("limit", page_size)
802 |> Map.put("offset", (page - 1) * page_size)
804 ActivityPub.fetch_activities([], params, :offset)
807 def parse_report_group(activity) do
808 reports = get_reports_by_status_id(activity["id"])
809 max_date = Enum.max_by(reports, &NaiveDateTime.from_iso8601!(&1.data["published"]))
810 actors = Enum.map(reports, & &1.user_actor)
811 [%{data: %{"object" => [account_id | _]}} | _] = reports
814 AccountView.render("show.json", %{
815 user: User.get_by_ap_id(account_id)
818 status = get_status_data(activity)
821 date: max_date.data["published"],
824 actors: Enum.uniq(actors),
829 defp get_status_data(status) do
830 case status["deleted"] do
833 "id" => status["id"],
838 Activity.get_by_ap_id(status["id"])
842 def get_reports_by_status_id(ap_id) do
844 where: fragment("(?)->>'type' = 'Flag'", a.data),
845 where: fragment("(?)->'object' @> ?", a.data, ^[%{id: ap_id}]),
846 or_where: fragment("(?)->'object' @> ?", a.data, ^[ap_id])
848 |> Activity.with_preloaded_user_actor()
852 @spec get_reports_grouped_by_status([String.t()]) :: %{
853 required(:groups) => [
855 required(:date) => String.t(),
856 required(:account) => %{},
857 required(:status) => %{},
858 required(:actors) => [%User{}],
859 required(:reports) => [%Activity{}]
863 def get_reports_grouped_by_status(activity_ids) do
868 |> build_flag_object()
869 |> parse_report_group()
873 groups: parsed_groups
877 @spec get_reported_activities() :: [
879 required(:activity) => String.t(),
880 required(:date) => String.t()
883 def get_reported_activities do
884 reported_activities_query =
886 where: fragment("(?)->>'type' = 'Flag'", a.data),
888 activity: fragment("jsonb_array_elements((? #- '{object,0}')->'object')", a.data)
890 group_by: fragment("activity")
893 from(a in subquery(reported_activities_query),
896 id: fragment("COALESCE(?->>'id'::text, ? #>> '{}')", a.activity, a.activity)
903 def update_report_state(%Activity{} = activity, state)
904 when state in @strip_status_report_states do
905 {:ok, stripped_activity} = strip_report_status_data(activity)
909 |> Map.put("state", state)
910 |> Map.put("object", stripped_activity.data["object"])
913 |> Changeset.change(data: new_data)
917 def update_report_state(%Activity{} = activity, state) when state in @supported_report_states do
918 new_data = Map.put(activity.data, "state", state)
921 |> Changeset.change(data: new_data)
925 def update_report_state(activity_ids, state) when state in @supported_report_states do
926 activities_num = length(activity_ids)
928 from(a in Activity, where: a.id in ^activity_ids)
929 |> update(set: [data: fragment("jsonb_set(data, '{state}', ?)", ^state)])
930 |> Repo.update_all([])
932 {^activities_num, _} -> :ok
933 _ -> {:error, activity_ids}
937 def update_report_state(_, _), do: {:error, "Unsupported state"}
939 def strip_report_status_data(activity) do
940 [actor | reported_activities] = activity.data["object"]
942 stripped_activities =
943 Enum.map(reported_activities, fn
944 act when is_map(act) -> act["id"]
945 act when is_binary(act) -> act
948 new_data = put_in(activity.data, ["object"], [actor | stripped_activities])
950 {:ok, %{activity | data: new_data}}
953 def update_activity_visibility(activity, visibility) when visibility in @valid_visibilities do
954 [to, cc, recipients] =
956 |> get_updated_targets(visibility)
957 |> Enum.map(&Enum.uniq/1)
966 |> Object.change(%{data: object_data})
967 |> Object.update_and_set_cache()
975 |> Map.put(:object, object)
976 |> Activity.change(%{data: activity_data, recipients: recipients})
980 def update_activity_visibility(_, _), do: {:error, "Unsupported visibility"}
982 defp get_updated_targets(
983 %Activity{data: %{"to" => to} = data, recipients: recipients},
986 cc = Map.get(data, "cc", [])
987 follower_address = User.get_cached_by_ap_id(data["actor"]).follower_address
988 public = Pleroma.Constants.as_public()
992 to = [public | List.delete(to, follower_address)]
993 cc = [follower_address | List.delete(cc, public)]
994 recipients = [public | recipients]
998 to = [follower_address | List.delete(to, public)]
999 cc = List.delete(cc, public)
1000 recipients = List.delete(recipients, public)
1001 [to, cc, recipients]
1004 to = [follower_address | List.delete(to, public)]
1005 cc = [public | List.delete(cc, follower_address)]
1006 recipients = recipients ++ [follower_address, public]
1007 [to, cc, recipients]
1010 [to, cc, recipients]
1014 def get_existing_votes(actor, %{data: %{"id" => id}}) do
1016 |> Activity.Queries.by_actor()
1017 |> Activity.Queries.by_type("Create")
1018 |> Activity.with_preloaded_object()
1019 |> where([a, object: o], fragment("(?)->>'inReplyTo' = ?", o.data, ^to_string(id)))
1020 |> where([a, object: o], fragment("(?)->>'type' = 'Answer'", o.data))
1024 def maybe_put(map, _key, nil), do: map
1025 def maybe_put(map, key, value), do: Map.put(map, key, value)