- def user_info(%User{} = user, args \\ %{}) do
- following_count =
- Map.get(args, :following_count, user.following_count || following_count(user))
-
- follower_count = Map.get(args, :follower_count, user.follower_count)
-
- %{
- note_count: user.note_count,
- locked: user.locked,
- confirmation_pending: user.confirmation_pending,
- default_scope: user.default_scope
- }
- |> Map.put(:following_count, following_count)
- |> Map.put(:follower_count, follower_count)
- end
-
- def follow_state(%User{} = user, %User{} = target) do
- case Utils.fetch_latest_follow(user, target) do
- %{data: %{"state" => state}} -> state
- # Ideally this would be nil, but then Cachex does not commit the value
- _ -> false
- end
- end
-
- def get_cached_follow_state(user, target) do
- key = "follow_state:#{user.ap_id}|#{target.ap_id}"
- Cachex.fetch!(:user_cache, key, fn _ -> {:commit, follow_state(user, target)} end)
- end
-
- @spec set_follow_state_cache(String.t(), String.t(), String.t()) :: {:ok | :error, boolean()}
- def set_follow_state_cache(user_ap_id, target_ap_id, state) do
- Cachex.put(:user_cache, "follow_state:#{user_ap_id}|#{target_ap_id}", state)
- end
-
- def set_info_cache(user, args) do
- Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user, args))
- end
-