- def fetch_activities_for_context(context) do
- query = from activity in Activity,
- where: fragment("? @> ?", activity.data, ^%{ context: context })
- Repo.all(query)
+ def make_user_from_nickname(nickname) do
+ with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
+ make_user_from_ap_id(ap_id)
+ end
+ end
+
+ def publish(actor, activity) do
+ followers = if actor.follower_address in activity.recipients do
+ {:ok, followers} = User.get_followers(actor)
+ followers
+ else
+ []
+ end
+
+ remote_inboxes = (Pleroma.Web.Salmon.remote_users(activity) ++ followers)
+ |> Enum.filter(fn (user) -> User.ap_enabled?(user) end)
+ |> Enum.map(fn (%{info: %{"source_data" => data}}) ->
+ (data["endpoints"] && data["endpoints"]["sharedInbox"]) || data["inbox"]
+ end)
+ |> Enum.uniq
+
+ {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
+ json = Poison.encode!(data)
+ Enum.each remote_inboxes, fn(inbox) ->
+ Logger.info("Federating #{activity.data["id"]} to #{inbox}")
+ host = URI.parse(inbox).host
+ signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)})
+ @httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}])
+ end