def render("index.json", %{users: users} = opts) do
relationships_opt =
- if Map.has_key?(opts, :relationships) do
- opts[:relationships]
- else
- UserRelationship.view_relationships_option(opts[:for], users)
+ cond do
+ Map.has_key?(opts, :relationships) ->
+ opts[:relationships]
+
+ is_nil(opts[:for]) ->
+ UserRelationship.view_relationships_option(nil, [])
+
+ true ->
+ UserRelationship.view_relationships_option(opts[:for], users)
end
opts = Map.put(opts, :relationships, relationships_opt)
def render("relationships.json", %{user: user, targets: targets} = opts) do
relationships_opt =
- if Map.has_key?(opts, :relationships) do
- opts[:relationships]
- else
- UserRelationship.view_relationships_option(user, targets)
+ cond do
+ Map.has_key?(opts, :relationships) ->
+ opts[:relationships]
+
+ is_nil(opts[:for]) ->
+ UserRelationship.view_relationships_option(nil, [])
+
+ true ->
+ UserRelationship.view_relationships_option(user, targets)
end
render_opts = %{as: :target, user: user, relationships: relationships_opt}
|> Pleroma.Repo.all()
relationships_opt =
- if Map.has_key?(opts, :relationships) do
- opts[:relationships]
- else
- move_activities_targets =
- activities
- |> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))
- |> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
-
- actors =
- activities
- |> Enum.map(fn a -> User.get_cached_by_ap_id(a.data["actor"]) end)
- |> Enum.filter(& &1)
- |> Kernel.++(move_activities_targets)
-
- UserRelationship.view_relationships_option(reading_user, actors)
+ cond do
+ Map.has_key?(opts, :relationships) ->
+ opts[:relationships]
+
+ is_nil(opts[:for]) ->
+ UserRelationship.view_relationships_option(nil, [])
+
+ true ->
+ move_activities_targets =
+ activities
+ |> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))
+ |> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
+
+ actors =
+ activities
+ |> Enum.map(fn a -> User.get_cached_by_ap_id(a.data["actor"]) end)
+ |> Enum.filter(& &1)
+ |> Kernel.++(move_activities_targets)
+
+ UserRelationship.view_relationships_option(reading_user, actors)
end
opts = %{
|> Repo.all()
relationships_opt =
- if Map.has_key?(opts, :relationships) do
- opts[:relationships]
- else
- actors = Enum.map(activities ++ parent_activities, &get_user(&1.data["actor"]))
- UserRelationship.view_relationships_option(opts[:for], actors)
+ cond do
+ Map.has_key?(opts, :relationships) ->
+ opts[:relationships]
+
+ is_nil(opts[:for]) ->
+ UserRelationship.view_relationships_option(nil, [])
+
+ true ->
+ actors = Enum.map(activities ++ parent_activities, &get_user(&1.data["actor"]))
+
+ UserRelationship.view_relationships_option(opts[:for], actors)
end
opts =