X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fdelivery.ex;h=0ded2855c79dc76783a609979b7513e7be2d6840;hb=2ee0fc194a3118e2b562744cb2854d048c829b1e;hp=f9a9e35cd2ed2570d9e563d3104a3109b94d09cc;hpb=769fb778d41df77c2514b5e3c663f3f624c0a266;p=akkoma
diff --git a/lib/pleroma/delivery.ex b/lib/pleroma/delivery.ex
index f9a9e35cd..0ded2855c 100644
--- a/lib/pleroma/delivery.ex
+++ b/lib/pleroma/delivery.ex
@@ -1,28 +1,28 @@
# 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.Delivery do
use Ecto.Schema
alias Pleroma.Delivery
- alias Pleroma.FlakeId
- alias Pleroma.User
- alias Pleroma.Repo
alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.User
import Ecto.Changeset
import Ecto.Query
schema "deliveries" do
- belongs_to(:user, User, type: FlakeId)
+ belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
belongs_to(:object, Object)
end
def changeset(delivery, params \\ %{}) do
delivery
|> cast(params, [:user_id, :object_id])
+ |> validate_required([:user_id, :object_id])
|> foreign_key_constraint(:object_id)
|> foreign_key_constraint(:user_id)
|> unique_constraint(:user_id, name: :deliveries_user_id_object_id_index)
@@ -31,7 +31,7 @@ defmodule Pleroma.Delivery do
def create(object_id, user_id) do
%Delivery{}
|> changeset(%{user_id: user_id, object_id: object_id})
- |> Repo.insert()
+ |> Repo.insert(on_conflict: :nothing)
end
def get(object_id, user_id) do
@@ -39,20 +39,12 @@ defmodule Pleroma.Delivery do
|> Repo.one()
end
- def get_or_create(object_id, user_id) do
- case get(object_id, user_id) do
- %Delivery{} = delivery -> {:ok, delivery}
- nil -> create(object_id, user_id)
- end
- end
+ # A hack because user delete activities have a fake id for whatever reason
+ # TODO: Get rid of this
+ def delete_all_by_object_id("pleroma:fake_object_id"), do: {0, []}
def delete_all_by_object_id(object_id) do
from(d in Delivery, where: d.object_id == ^object_id)
|> Repo.delete_all()
end
-
- def get_all_by_object_id(object_id) do
- from(d in Delivery, where: d.object_id == ^object_id)
- |> Repo.all()
- end
end