X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fmarker.ex;h=4439273922d2916e11886c302e9f7603b237ea07;hb=46f051048fb1afb02fe81b872ae9f595f2c5f2c1;hp=ff5f60351baad1cb833f08e656da6c0eaeb2e3b2;hpb=10f452ad1feae9a882b6dc4cd35e09adb7e78208;p=akkoma
diff --git a/lib/pleroma/marker.ex b/lib/pleroma/marker.ex
index ff5f60351..443927392 100644
--- a/lib/pleroma/marker.ex
+++ b/lib/pleroma/marker.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Marker do
@@ -9,34 +9,24 @@ defmodule Pleroma.Marker do
import Ecto.Query
alias Ecto.Multi
- alias Pleroma.Notification
alias Pleroma.Repo
alias Pleroma.User
- alias __MODULE__
@timelines ["notifications"]
- @type t :: %__MODULE__{}
schema "markers" do
field(:last_read_id, :string, default: "")
field(:timeline, :string, default: "")
field(:lock_version, :integer, default: 0)
- field(:unread_count, :integer, default: 0, virtual: true)
belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
timestamps()
end
- @doc "Gets markers by user and timeline."
- @spec get_markers(User.t(), list(String)) :: list(t())
def get_markers(user, timelines \\ []) do
- user
- |> get_query(timelines)
- |> unread_count_query()
- |> Repo.all()
+ Repo.all(get_query(user, timelines))
end
- @spec upsert(User.t(), map()) :: {:ok | :error, any()}
def upsert(%User{} = user, attrs) do
attrs
|> Map.take(@timelines)
@@ -55,27 +45,6 @@ defmodule Pleroma.Marker do
|> Repo.transaction()
end
- @spec multi_set_last_read_id(Multi.t(), User.t(), String.t()) :: Multi.t()
- def multi_set_last_read_id(multi, %User{} = user, "notifications") do
- multi
- |> Multi.run(:counters, fn _repo, _changes ->
- {:ok, %{last_read_id: Repo.one(Notification.last_read_query(user))}}
- end)
- |> Multi.insert(
- :marker,
- fn %{counters: attrs} ->
- %Marker{timeline: "notifications", user_id: user.id}
- |> struct(attrs)
- |> Ecto.Changeset.change()
- end,
- returning: true,
- on_conflict: {:replace, [:last_read_id]},
- conflict_target: [:user_id, :timeline]
- )
- end
-
- def multi_set_last_read_id(multi, _, _), do: multi
-
defp get_marker(user, timeline) do
case Repo.find_resource(get_query(user, timeline)) do
{:ok, marker} -> %__MODULE__{marker | user: user}
@@ -102,16 +71,4 @@ defmodule Pleroma.Marker do
|> by_user_id(user.id)
|> by_timeline(timelines)
end
-
- defp unread_count_query(query) do
- from(
- q in query,
- left_join: n in "notifications",
- on: n.user_id == q.user_id and n.seen == false,
- group_by: [:id],
- select_merge: %{
- unread_count: fragment("count(?)", n.id)
- }
- )
- end
end