Mastodon StatusView: Return correct visibility.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:51:51 +0000 (13:51 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 12:51:51 +0000 (13:51 +0100)
lib/pleroma/web/mastodon_api/views/status_view.ex

index 64f3155975ccf6968a258373fb33a798909451d7..e205a420db03ca659315d96c735204916288a55f 100644 (file)
@@ -96,7 +96,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       muted: false,
       sensitive: sensitive,
       spoiler_text: object["summary"] || "",
-      visibility: "public",
+      visibility: get_visibility(object),
       media_attachments: attachments |> Enum.take(4),
       mentions: mentions,
       tags: [], # fix,
@@ -109,7 +109,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     }
   end
 
+  def get_visibility(object) do
+    public = "https://www.w3.org/ns/activitystreams#Public"
+    to = object["to"] || []
+    cc = object["cc"] || []
+    cond do
+      public in to -> "public"
+      public in cc -> "unlisted"
+      [] == cc -> "direct"
+      true -> "private"
+    end
+  end
+
   def render("attachment.json", %{attachment: attachment}) do
+    IO.inspect(attachment)
     [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"]
 
     type = cond do