Fix issue #124
[akkoma] / lib / pleroma / web / mastodon_api / mastodon_api_controller.ex
index 97a618186388fc303205f4d8922b83e6d93da6a0..21a3660c8714889ccbcd552dd5c3ab473c4d8f8a 100644 (file)
@@ -102,13 +102,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   @instance Application.get_env(:pleroma, :instance)
+  @mastodon_api_level "2.3.3"
 
   def masto_instance(conn, _params) do
     response = %{
       uri: Web.base_url(),
       title: Keyword.get(@instance, :name),
       description: "A Pleroma instance, an alternative fediverse server",
-      version: Keyword.get(@instance, :version),
+      version: "#{@mastodon_api_level} (compatible; #{Keyword.get(@instance, :version)})",
       email: Keyword.get(@instance, :email),
       urls: %{
         streaming_api: String.replace(Web.base_url(), ["http", "https"], "wss")
@@ -211,9 +212,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
         |> Map.put("actor_id", ap_id)
         |> Map.put("whole_db", true)
 
-      activities =
-        ActivityPub.fetch_public_activities(params)
-        |> Enum.reverse()
+      if params["pinned"] == "true" do
+        # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
+        activities = []
+      else
+        activities =
+         ActivityPub.fetch_public_activities(params)
+         |> Enum.reverse()
+      end
 
       conn
       |> add_link_headers(:user_statuses, activities, params["id"])
@@ -514,7 +520,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
             a.data,
             ^query
           ),
-        limit: 20
+        limit: 20,
+        order_by: [desc: :inserted_at]
       )
 
     statuses = Repo.all(q) ++ fetched
@@ -604,35 +611,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
               "video\/mp4"
             ]
           },
-          settings: Map.get(user.info, "settings") || %{
-            onboarded: true,
-            home: %{
-              shows: %{
-                reblog: true,
-                reply: true
-              }
-            },
-            notifications: %{
-              alerts: %{
-                follow: true,
-                favourite: true,
-                reblog: true,
-                mention: true
-              },
-              shows: %{
-                follow: true,
-                favourite: true,
-                reblog: true,
-                mention: true
+          settings:
+            Map.get(user.info, "settings") ||
+              %{
+                onboarded: true,
+                home: %{
+                  shows: %{
+                    reblog: true,
+                    reply: true
+                  }
+                },
+                notifications: %{
+                  alerts: %{
+                    follow: true,
+                    favourite: true,
+                    reblog: true,
+                    mention: true
+                  },
+                  shows: %{
+                    follow: true,
+                    favourite: true,
+                    reblog: true,
+                    mention: true
+                  },
+                  sounds: %{
+                    follow: true,
+                    favourite: true,
+                    reblog: true,
+                    mention: true
+                  }
+                }
               },
-              sounds: %{
-                follow: true,
-                favourite: true,
-                reblog: true,
-                mention: true
-              }
-            }
-          },
           push_subscription: nil,
           accounts: accounts,
           custom_emojis: mastodon_emoji,
@@ -655,7 +664,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
          {:ok, _user} <- User.update_and_set_cache(change) do
       conn
       |> json(%{})
-    else e ->
+    else
+      e ->
         conn
         |> json(%{error: inspect(e)})
     end