activity: add helpers for updating activities in the database
authorWilliam Pitcock <nenolod@dereferenced.org>
Thu, 29 Nov 2018 06:52:54 +0000 (06:52 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 4 Dec 2018 04:52:09 +0000 (04:52 +0000)
lib/pleroma/activity.ex

index 34d0a34b8e8a1c93519094d313f07823fa823ba0..e3aa4eb976ae5b9ec2287dca86f216c9ffd3ef62 100644 (file)
@@ -1,7 +1,7 @@
 defmodule Pleroma.Activity do
   use Ecto.Schema
   alias Pleroma.{Repo, Activity, Notification, Object}
-  import Ecto.Query
+  import Ecto.{Query, Changeset}
 
   schema "activities" do
     field(:data, :map)
@@ -22,6 +22,13 @@ defmodule Pleroma.Activity do
     )
   end
 
+  def change(struct, params \\ %{}) do
+    struct
+    |> cast(params, [:data])
+    |> validate_required([:data])
+    |> unique_constraint(:ap_id, name: :activities_unique_apid_index)
+  end
+
   # TODO:
   # Go through these and fix them everywhere.
   # Wrong name, only returns create activities