Browse Source

feat(micropub): Add logic for '?q=contact'.

jackyalcine 2 weeks ago
parent
commit
2254636647
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 9
- 0
lib/indieweb/micropub/query.ex View File

@@ -13,6 +13,15 @@ defmodule IndieWeb.Micropub.Query do
13 13
     {:ok, %{"categories" => category_names}}
14 14
   end
15 15
 
16
+  def invoke("contact", %{}) do
17
+    contacts =
18
+      Koype.Repo.Contact
19
+      |> Koype.Repo.all()
20
+      |> Enum.map(&Map.take(&1, ~w(name photo url nickname)a))
21
+
22
+    {:ok, %{"contacts" => contacts}}
23
+  end
24
+
16 25
   def invoke("category", %{"search" => name}) when is_binary(name) do
17 26
     category_names = Koype.Repo.Category.find_matching(name) |> Enum.map(& &1.name)
18 27
     {:ok, %{"categories" => category_names}}

+ 14
- 0
test/integration/controllers/indie/micropub_controller_test.exs View File

@@ -620,6 +620,20 @@ defmodule Koype.Web.Indie.MicropubControllerTest do
620 620
       |> Enum.each(fn key -> assert Map.has_key?(resp, key) end)
621 621
     end
622 622
 
623
+    test "200 lists all contacts" do
624
+      contacts = insert_list(10, :contact)
625
+
626
+      conn =
627
+        build_conn()
628
+        |> indie_sign_in_conn(@client_id, ~w(read))
629
+        |> get(@route, %{"q" => "contact"})
630
+
631
+      assert %{"contacts" => fetched_contacts} = json_response(conn, :ok)
632
+
633
+      assert Enum.map(fetched_contacts, &Map.get(&1, "url")) ==
634
+               Enum.map(contacts, &Map.get(&1, :url))
635
+    end
636
+
623 637
     test "200 shows syndication targets" do
624 638
       conn =
625 639
         build_conn()

+ 1
- 1
web/authentication_helpers.ex View File

@@ -30,7 +30,7 @@ defmodule Koype.Web.AuthenticationHelpers do
30 30
     conn
31 31
     |> KGPlug.sign_in(
32 32
       Koype.host(),
33
-      %{"id" => Koype.host() |> URI.parse |> IndieWeb.URL.canonalize |> URI.to_string},
33
+      %{"id" => Koype.host() |> URI.parse() |> IndieWeb.URL.canonalize() |> URI.to_string()},
34 34
       ttl: {1, :week},
35 35
       key: :owner
36 36
     )

+ 1
- 1
web/controllers/indie/token_api_controller.ex View File

@@ -65,7 +65,7 @@ defmodule Koype.Web.Indie.TokenApiController do
65 65
       |> put_resp_header("authorization", "Bearer #{token}")
66 66
       |> json(%{
67 67
         access_token: token,
68
-        me: Koype.host() |> URI.parse |> IndieWeb.URL.canonalize |> URI.to_string,
68
+        me: Koype.host() |> URI.parse() |> IndieWeb.URL.canonalize() |> URI.to_string(),
69 69
         scope: scope_str,
70 70
         token_type: :bearer
71 71
       })

Loading…
Cancel
Save