- message
- |> Map.put("to", [follower_collection])
- |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+ defp reject_message(message, threshold) when threshold > 0 do
+ with {_, recipients} <- get_recipient_count(message) do
+ if recipients > threshold do
+ {:reject, nil}
+ else
+ {:ok, message}
+ end
+ end
+ end
+
+ defp reject_message(message, _threshold), do: {:ok, message}
+
+ defp get_recipient_count(message) do
+ recipients = (message["to"] || []) ++ (message["cc"] || [])
+ follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
+
+ if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do
+ recipients =
+ recipients
+ |> List.delete("https://www.w3.org/ns/activitystreams#Public")
+ |> List.delete(follower_collection)
+
+ {:public, length(recipients)}
+ else
+ recipients =
+ recipients
+ |> List.delete(follower_collection)
+
+ {:not_public, length(recipients)}
+ end