Get rid of unsafe variables.
authoreal <eal@waifu.club>
Sun, 6 May 2018 06:58:59 +0000 (09:58 +0300)
committereal <eal@waifu.club>
Sun, 6 May 2018 06:58:59 +0000 (09:58 +0300)
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/views/user_view.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/web_finger/web_finger.ex

index ea1af0f4d0f75be6f9ae0c246e847caa352ac3dd..31105ffe9802d96b98596e703f1f03d7ab845c70 100644 (file)
@@ -17,9 +17,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
     if actor_info.host in @media_removal do
       child_object = Map.delete(object["object"], "attachment")
       object = Map.put(object, "object", child_object)
+      {:ok, object}
+    else
+      {:ok, object}
     end
-
-    {:ok, object}
   end
 
   @media_nsfw Keyword.get(@mrf_policy, :media_nsfw)
@@ -32,9 +33,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
       child_object = Map.put(child_object, "tags", tags)
       child_object = Map.put(child_object, "sensitive", true)
       object = Map.put(object, "object", child_object)
+      {:ok, object}
+    else
+      {:ok, object}
     end
-
-    {:ok, object}
   end
 
   @ftl_removal Keyword.get(@mrf_policy, :federated_timeline_removal)
@@ -43,22 +45,28 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
       user = User.get_by_ap_id(object["actor"])
 
       # flip to/cc relationship to make the post unlisted
-      if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and
-           user.follower_address in object["cc"] do
-        to =
-          List.delete(object["to"], "https://www.w3.org/ns/activitystreams#Public") ++
-            [user.follower_address]
+      object =
+        if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and
+             user.follower_address in object["cc"] do
+          to =
+            List.delete(object["to"], "https://www.w3.org/ns/activitystreams#Public") ++
+              [user.follower_address]
 
-        cc =
-          List.delete(object["cc"], user.follower_address) ++
-            ["https://www.w3.org/ns/activitystreams#Public"]
+          cc =
+            List.delete(object["cc"], user.follower_address) ++
+              ["https://www.w3.org/ns/activitystreams#Public"]
 
-        object = Map.put(object, "to", to)
-        object = Map.put(object, "cc", cc)
-      end
-    end
+          object
+          |> Map.put("to", to)
+          |> Map.put("cc", cc)
+        else
+          object
+        end
 
-    {:ok, object}
+      {:ok, object}
+    else
+      {:ok, object}
+    end
   end
 
   def filter(object) do
index 2871a2544738086cffe934707c2359f9ec386aa5..c5d1ec0c29b662929c042eb5ca0bcc0bc6dbffb3 100644 (file)
@@ -72,9 +72,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
       |> Enum.reduce(%{}, fn data, mapping ->
         name = data["name"]
 
-        if String.starts_with?(name, ":") do
-          name = name |> String.slice(1..-2)
-        end
+        name =
+          if String.starts_with?(name, ":") do
+            name = name |> String.slice(1..-2)
+          else
+            name
+          end
 
         mapping |> Map.put(name, data["icon"]["url"])
       end)
index 92afd0872091727412f7af9918fc2a11fa236773..74f89c51668ad0c9067ff8ee756cc010024da8d9 100644 (file)
@@ -123,9 +123,12 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "limit" => "10"
     }
 
-    if max_qid != nil do
-      params = Map.put(params, "max_id", max_qid)
-    end
+    params =
+      if max_qid != nil do
+        Map.put(params, "max_id", max_qid)
+      else
+        params
+      end
 
     activities = ActivityPub.fetch_public_activities(params)
     min_id = Enum.at(activities, 0).id
index b77c9fc02f86dedc05fef7a3b3064810aa402cd5..9f4261143889976834586ff51080e21510478f51 100644 (file)
@@ -212,14 +212,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
         |> Map.put("actor_id", ap_id)
         |> Map.put("whole_db", true)
 
-      if params["pinned"] == "true" do
-        # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
-        activities = []
-      else
-        activities =
+      activities =
+        if params["pinned"] == "true" do
+          # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
+          []
+        else
           ActivityPub.fetch_public_activities(params)
           |> Enum.reverse()
-      end
+        end
 
       conn
       |> add_link_headers(:user_statuses, activities, params["id"])
index dc9ad2014216d425ac08b22993c00b6cb82c94d6..e1b552cdc455ce9fd3cb5c6a98b3e172253ac501 100644 (file)
@@ -239,13 +239,14 @@ defmodule Pleroma.Web.WebFinger do
           URI.parse(account).host
       end
 
-    case find_lrdd_template(domain) do
-      {:ok, template} ->
-        address = String.replace(template, "{uri}", URI.encode(account))
+    address =
+      case find_lrdd_template(domain) do
+        {:ok, template} ->
+          String.replace(template, "{uri}", URI.encode(account))
 
-      _ ->
-        address = "http://#{domain}/.well-known/webfinger?resource=acct:#{account}"
-    end
+        _ ->
+          "http://#{domain}/.well-known/webfinger?resource=acct:#{account}"
+      end
 
     with response <-
            @httpoison.get(