defmodule Secret do def archive(session, channel) do {:ok, oldest} = UrbitEx.API.Graph.fetch_oldest(session, channel, [count: 999]) recent = last(oldest) Map.merge(oldest, other(session, channel, recent)) end def other(_session, _channel, nil), do: %{} def other(session, channel, last_index) do {:ok, less} = UrbitEx.API.Graph.fetch_newer_than(session, channel, last_index, [count: 999]) recent = last(less) Map.merge(less, other(session, channel, recent)) end def last(%{}), do: nil def last(map), do: Map.keys(map) |> Enum.max() def clean(graph) do graph |> UrbitEx.Graph.to_list() |> Enum.filter(& &1.post != :deleted) |> Enum.sort_by(& &1.post."time-sent") |> Enum.map(& prettify(&1.post)) end def prettify(:deleted), do: "\n\n deleted \n\n" def prettify(post) do """ #{post.author} on #{post."time-sent"}\n\n #{Jason.encode!(post.contents)} """ end end