Make logged user available in nested view model

Hey there,

I have a user view model that has a field called is_friend.
This returns true or false depending on if the logged user is a friend of the user in question.

This user model is a nested model, and being used by multiple parent models.
I need the logged user in order to determine the correct value.

So far I have been passing the logged user to the contexts to load in this field for the users that belong to other structs, such as group members etc, and when I’d render a group I would have the is_friend field to render in the user model I mentioned earlier.

But this doesn’t seem great to me.

Is there some way to have the logged user available in this nested model without having to pass it down through each parent model?

The model is pretty simple:

  def render("user_mini.json", %{user: user}) do
    user_images =
      render_one(
        user,
        UserView,
        "user_image_body.json"
      )
      |> Map.take([:profile_image_urls, :profile_image_key, :profile_image_file_name])

    %{
      id: user.hash_id,
      status: user.status,
      first_name: user.profile.first_name,
      last_name: user.profile.last_name,
      is_friend: user.is_friend,
      is_blocked: user.is_blocked
    }
    |> Map.merge(user_images)
  end