Browse Source

fix(webmention): Support updating of Webmentions vs making new one.

jackyalcine 8 months ago
parent
commit
3ecf02d1d9
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 1
- 1
lib/repo/webmention.ex View File

@@ -105,7 +105,7 @@ defmodule Koype.Repo.Webmention do
105 105
   def update(model, args) do
106 106
     with(
107 107
       {:ok, author_hcard} <- IndieWeb.HCard.resolve(Keyword.get(args, :source, model.source)),
108
-      cs <- changeset(model, %{}) |> change(args),
108
+      cs <- changeset(model, %{}) |> change(args |> Keyword.drop(~w(mf2)a)),
109 109
       {:ok, record} <- Koype.Repo.update(cs),
110 110
       {:ok, _path} <- __MODULE__.Json.persist(record, author: author_hcard, mf2: args[:mf2])
111 111
     ) do

+ 7
- 0
lib/webmention.ex View File

@@ -176,7 +176,14 @@ defmodule Koype.Webmention do
176 176
 
177 177
       Logger.info("Saving Webmention from #{source} to #{target_url}.")
178 178
 
179
+      id =
180
+        case Koype.Repo.get_by(Koype.Repo.Webmention, source: source) do
181
+          nil -> nil
182
+          webmention -> webmention.id
183
+        end
184
+
179 185
       case Koype.Repo.upsert(Koype.Repo.Webmention,
186
+             id: id,
180 187
              source: source,
181 188
              target: target_url,
182 189
              type: Atom.to_string(type),

+ 0
- 3
test/unit/indieweb/syndication_test.exs View File

@@ -77,9 +77,6 @@ defmodule IndieWeb.SyndicationTest do
77 77
 
78 78
   defp build_entry(_), do: {:ok, [entry: insert(:entry)]}
79 79
 
80
-  defp build_existing_results(entry, target) do
81
-  end
82
-
83 80
   defp build_targets(_),
84 81
     do:
85 82
       {:ok,

+ 1
- 1
test/unit/webmention_test.exs View File

@@ -84,7 +84,7 @@ defmodule Koype.WebmentionTest do
84 84
       use_cassette :stub, url: source_uri, body: html, status_code: 200 do
85 85
         assert {:ok, updated_webmention} = Subject.receive!(source: source_uri, target: target_uri)
86 86
         assert updated_webmention.id == webmention.id
87
-        assert updated_webmention.type == "like"
87
+        assert updated_webmention.type == "article"
88 88
       end
89 89
     end
90 90
 

Loading…
Cancel
Save