- def like(%User{ap_id: ap_id} = user, %Object{data: %{ "id" => id}} = object) do
- cond do
- # There's already a like here, so return the original activity.
- ap_id in (object.data["likes"] || []) ->
- query = from activity in Activity,
- where: fragment("? @> ?", activity.data, ^%{actor: ap_id, object: id, type: "Like"})
-
- activity = Repo.one(query)
- {:ok, activity, object}
- true ->
- data = %{
- "type" => "Like",
- "actor" => ap_id,
- "object" => id,
- "to" => [User.ap_followers(user)]
- }
-
- {:ok, activity} = insert(data)
-
- likes = [ap_id | (object.data["likes"] || [])] |> Enum.uniq
-
- new_data = object.data
- |> Map.put("like_count", length(likes))
- |> Map.put("likes", likes)
-
- changeset = Ecto.Changeset.change(object, data: new_data)
- {:ok, object} = Repo.update(changeset)
-
- update_object_in_activities(object)
-
- {:ok, activity, object}
+ def stream_out(activity) do
+ if activity.data["type"] in ["Create", "Announce"] do
+ Pleroma.Web.Streamer.stream("user", activity)
+ if Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do
+ Pleroma.Web.Streamer.stream("public", activity)
+ if activity.local do
+ Pleroma.Web.Streamer.stream("public:local", activity)
+ end
+ end