Browse Source

fix(feed): Update JSON feed representation.

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

+ 3
- 3
.lvimrc View File

@@ -26,7 +26,7 @@ endfunction
26 26
 let g:test#custom_transformations = {'docker-compose': function('DockerComposeTransform')}
27 27
 let g:test#transformation = 'docker-compose'
28 28
 let g:test#elixir#exunit#options = {
29
-      \ 'file': '--seed=0 --max-cases=3 --slowest=5 --include acceptance:true',
30
-      \ 'suite': '--max-cases=10 --slowest=10 --include acceptance:true',
31
-      \ 'nearest': '--include skip:true --include acceptance:true'
29
+      \ 'file': '--trace --seed=0 --max-cases=3 --slowest=5 --include acceptance:true',
30
+      \ 'suite': '--trace --max-cases=10 --slowest=10 --include acceptance:true',
31
+      \ 'nearest': '--trace --include skip:true --include acceptance:true'
32 32
       \ }

+ 2
- 0
dialyzer.ignore-warnings View File

@@ -0,0 +1,2 @@
1
+0:unknown_function
2
+0:unknown_type

+ 1
- 1
lib/cache.ex View File

@@ -33,7 +33,7 @@ defmodule Koype.Cache do
33 33
   end
34 34
 
35 35
   @doc "Sets a value into the cache."
36
-  @spec set(binary(), binary(), map()) :: {:error, any()} | :ok
36
+  @spec set(binary(), any(), keyword()) :: {:error, any()} | :ok
37 37
   def set(key, value, opts \\ []) do
38 38
     case Cachex.put(:koype, key, value) do
39 39
       {:ok, _code} ->

+ 1
- 1
lib/feed.ex View File

@@ -21,7 +21,7 @@ defmodule Koype.Feed do
21 21
   @semantic_types ~w(all responses content notifications category)a
22 22
 
23 23
   defp do_extract_semantic_types(type, options) when type in @semantic_types,
24
-    do: Koype.Timeline.sequential(options ++ [type: type])
24
+    do: Koype.Timeline.sequential(Keyword.merge(options, type: type))
25 25
 
26 26
   def items(options) do
27 27
     kind = Keyword.get(options, :kind, :timeline)

+ 5
- 6
lib/feed/json_feed.ex View File

@@ -147,16 +147,15 @@ defmodule Koype.Feed.Json do
147 147
     if item.author != Koype.host() do
148 148
       with(
149 149
         {:ok, webmention_json} <- Koype.Repo.Webmention.Json.find(item),
150
-        {:ok, entry} <- IndieWeb.Webmention.resolve_target_from_url(item.target),
151
-        {:ok, %Koype.Page.Structure{author: author}} <- Koype.Page.fetch(item.author)
150
+        {:ok, entry} <- IndieWeb.Webmention.resolve_target_from_url(item.target)
152 151
       ) do
153 152
         content =
154 153
           case entry do
155 154
             :homepage ->
156 155
               %{
157
-                "summary" => "You were mentioned in a #{item.type} by #{author.name}.",
156
+                "summary" => "You were mentioned in a #{item.type} by #{item.author}.",
158 157
                 "tags" => ~w(mention),
159
-                "title" => "New Mention from #{author.name}",
158
+                "title" => "New Mention from #{item.author}",
160 159
                 "url" => item.source
161 160
               }
162 161
 
@@ -166,7 +165,7 @@ defmodule Koype.Feed.Json do
166 165
               %{
167 166
                 "summary" => webmention_json["summary"],
168 167
                 "tags" => do_extract_category_names(loaded_entry.categories),
169
-                "title" => "#{author.name} sent a #{item.type} for #{entry.name}",
168
+                "title" => "#{item.author} sent a #{item.type} for #{entry.name}",
170 169
                 "url" => item.source
171 170
               }
172 171
 
@@ -185,7 +184,7 @@ defmodule Koype.Feed.Json do
185 184
           "content_html" => webmention_json["source"]["content"]["html"],
186 185
           "content_text" =>
187 186
             webmention_json["source"]["content"]["text"] ||
188
-              "You received a #{item.type} from #{author.name}",
187
+              "You received a #{item.type} from #{item.author}",
189 188
           "date_published" => Calendar.DateTime.Format.rfc3339(item.inserted_at, 3),
190 189
           "date_modified" => Calendar.DateTime.Format.rfc3339(item.updated_at, 3),
191 190
           "tags" => content["tags"]

+ 14
- 2
lib/indieweb/micropub/content.ex View File

@@ -351,11 +351,23 @@ defmodule IndieWeb.Micropub.Content do
351 351
   end
352 352
 
353 353
   defp do_parse_extension("visibility", visibility, model) when is_binary(visibility) do
354
-    Koype.Repo.Entry.update(model, %{visibility: visibility})
354
+    case Koype.Repo.Entry.Json.find(model) do
355
+      {:ok, json} ->
356
+        Koype.Repo.Entry.update(model, Map.merge(json, %{visibility: visibility}))
357
+
358
+      _ ->
359
+        {:ok, model}
360
+    end
355 361
   end
356 362
 
357 363
   defp do_parse_extension("post-status", post_status, model) when is_binary(post_status) do
358
-    Koype.Repo.Entry.update(model, %{post_status: post_status})
364
+    case Koype.Repo.Entry.Json.find(model) do
365
+      {:ok, json} ->
366
+        Koype.Repo.Entry.update(model, Map.merge(json, %{post_status: post_status}))
367
+
368
+      _ ->
369
+        {:ok, model}
370
+    end
359 371
   end
360 372
 
361 373
   defp do_parse_extension("syndication", syndication_link, model)

+ 3
- 1
lib/indieweb/micropub/query.ex View File

@@ -135,7 +135,9 @@ defmodule IndieWeb.Micropub.Query do
135 135
       {"content", content}, acc -> Map.put(acc, "content", [content["value"] |> Enum.join("\n")])
136 136
       {key, value}, acc -> Map.put(acc, key, value)
137 137
     end)
138
-    |> Map.put("published", [Calendar.DateTime.Format.rfc3339(model.published_at)])
138
+    |> Map.put("published", [
139
+      Calendar.DateTime.Format.rfc3339(model.published_at || model.inserted_at)
140
+    ])
139 141
     |> Map.put("updated", [Calendar.DateTime.Format.rfc3339(model.updated_at)])
140 142
     |> Map.put("name", [model.name])
141 143
     |> Map.put("url", [Koype.Repo.Entry.get_uri(model)])

+ 1
- 1
lib/page/parser/activitystreams2.ex View File

@@ -5,7 +5,7 @@ defmodule Koype.Page.ActivityStreams2Parser do
5 5
     Enum.find_value(Map.to_list(resp), fn
6 6
       {:body, html} ->
7 7
         case Floki.find(html, "link[type='application/activity+json'][rel=alternate]") do
8
-          elem when not is_nil(elem) -> Floki.attribute(elem, "href") |> List.first()
8
+          elem when not is_nil(elem) -> elem |> Floki.attribute("href") |> List.first()
9 9
           _ -> nil
10 10
         end
11 11
 

+ 4
- 1
lib/web.ex View File

@@ -17,6 +17,7 @@
17 17
 # You should have received a copy of the GNU Affero General Public License
18 18
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 19
 defmodule Koype.Web do
20
+  @moduledoc false
20 21
   def controller do
21 22
     quote do
22 23
       use Phoenix.Controller, namespace: Koype.Web
@@ -41,7 +42,9 @@ defmodule Koype.Web do
41 42
             current_path: Phoenix.Controller.current_path(conn),
42 43
             conn: conn,
43 44
             flash:
44
-              Enum.map(~w(error info warn success), fn state -> {state, get_flash(conn, state)} end)
45
+              Enum.map(~w(error info warn success), fn state ->
46
+                {state, get_flash(conn, state)}
47
+              end)
45 48
               |> Enum.reject(fn {_, v} -> is_nil(v) end)
46 49
               |> Map.new()
47 50
           })

Loading…
Cancel
Save