DateTime.utc_now() |> DateTime.to_iso8601()
end
+ # DEPRECATED mostly, context objects are now created at insertion time.
def context_to_conversation_id(context) do
with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
id
import Ecto.Query
+ defp query_context_ids([]), do: []
defp query_context_ids(contexts) do
query = from o in Object,
where: fragment("(?)->>'id' = ANY(?)", o.data, ^contexts)
defp collect_context_ids(activities) do
contexts = activities
+ |> Enum.reject(&(&1.data["context_id"]))
|> Enum.map(fn(%{data: data}) ->
data["context"]
end)
end)
end
+ defp get_context_id(%{data: %{"context_id" => context_id}}, _) when not is_nil(context_id), do: context_id
defp get_context_id(%{data: %{"context" => nil}}, _), do: nil
defp get_context_id(%{data: %{"context" => context}}, options) do
cond do
"possibly_sensitive" => possibly_sensitive
}
end
-
- defp conversation_id(activity) do
- with context when not is_nil(context) <- activity.data["context"] do
- TwitterAPI.context_to_conversation_id(context)
- else
- _e -> nil
- end
- end
end
describe "GET /statusnet/conversation/:id.json" do
test "returns the statuses in the conversation", %{conn: conn} do
{:ok, _user} = UserBuilder.insert()
- {:ok, _activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
+ {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
{:ok, _activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
{:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
- {:ok, object} = Object.context_mapping("2hu") |> Repo.insert()
-
conn =
conn
- |> get("/api/statusnet/conversation/#{object.id}.json")
+ |> get("/api/statusnet/conversation/#{activity.data["context_id"]}.json")
response = json_response(conn, 200)