Compare commits
No commits in common. "f70e358a8000cb6f183954cc6ce3f638a497f493" and "37a802b7a88bacc9e3437ff4b3e9e85cdd22040f" have entirely different histories.
f70e358a80
...
37a802b7a8
|
@ -38,7 +38,7 @@ defmodule Frenzy.Item do
|
|||
}
|
||||
|
||||
if item.date do
|
||||
Map.put(res, :published, DateTime.to_iso8601(item.date))
|
||||
Map.put(res, :created_at, DateTime.to_iso8601(item.date))
|
||||
else
|
||||
res
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
defmodule FrenzyWeb.Fervor.ItemsController do
|
||||
use FrenzyWeb, :controller
|
||||
alias Frenzy.{Repo, Item, Group, Feed}
|
||||
alias Frenzy.{Repo, Item}
|
||||
import Ecto.Query
|
||||
alias FrenzyWeb.Fervor.Paginator
|
||||
|
||||
plug :get_specific_item
|
||||
|
||||
def get_specific_item(%Plug.Conn{path_params: %{"id" => id}} = conn, _opts) when id != "sync" do
|
||||
def get_specific_item(%Plug.Conn{path_params: %{"id" => id}} = conn, _opts) do
|
||||
user = conn.assigns[:user] |> Repo.preload(:feeds)
|
||||
|
||||
item = Repo.get(Item, id)
|
||||
|
@ -119,42 +119,4 @@ defmodule FrenzyWeb.Fervor.ItemsController do
|
|||
def unread_multiple(conn, params) do
|
||||
mark_multiple_items(conn, params, %{read: false})
|
||||
end
|
||||
|
||||
def sync(conn, params) do
|
||||
sync_timestamp = Timex.now()
|
||||
|
||||
feed_ids =
|
||||
Group
|
||||
|> where([g], g.user_id == ^conn.assigns.user.id)
|
||||
|> join(:inner, [g], f in Feed, on: f.group_id == g.id)
|
||||
|> select([g, f], f.id)
|
||||
|> Repo.all()
|
||||
|
||||
last_sync =
|
||||
Map.get(params, "last_sync")
|
||||
|> case do
|
||||
s when is_binary(s) -> Timex.parse!(s, "{ISO:Extended:Z}")
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
{deleted_ids, upserted} =
|
||||
case last_sync do
|
||||
nil ->
|
||||
items = Repo.all(from i in Item, where: not i.tombstone and i.feed_id in ^feed_ids)
|
||||
{[], items}
|
||||
|
||||
_ ->
|
||||
all_items =
|
||||
Repo.all(from i in Item, where: i.feed_id in ^feed_ids and i.updated_at >= ^last_sync)
|
||||
|
||||
{tombstones, rest} = Enum.split_with(all_items, & &1.tombstone)
|
||||
{Enum.map(tombstones, & &1.id), rest}
|
||||
end
|
||||
|
||||
json(conn, %{
|
||||
sync_timestamp: Timex.format!(sync_timestamp, "{ISO:Extended:Z}"),
|
||||
delete: Enum.map(deleted_ids, &to_string/1),
|
||||
upsert: Enum.map(upserted, &Item.to_fervor/1)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -110,7 +110,7 @@ defmodule FrenzyWeb.Fervor.OauthController do
|
|||
)
|
||||
|
||||
uri = %URI{parsed | query: query}
|
||||
redirect(conn, external: URI.to_string(uri))
|
||||
redirect(conn, to: uri)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -99,7 +99,6 @@ defmodule FrenzyWeb.Router do
|
|||
post "/api/v1/feeds/:id/delete", FeedsController, :delete
|
||||
|
||||
get "/api/v1/items", ItemsController, :items_list
|
||||
get "/api/v1/items/sync", ItemsController, :sync
|
||||
get "/api/v1/items/:id", ItemsController, :specific_item
|
||||
post "/api/v1/items/:id/read", ItemsController, :read_specific_item
|
||||
post "/api/v1/items/:id/unread", ItemsController, :unread_specific_item
|
||||
|
|
Loading…
Reference in New Issue