From f36724efb1fc0806e11b4c0c32a03d1aeee13da6 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 27 Nov 2019 14:13:36 +0100 Subject: [PATCH] User: Never return nil for user follower counts. --- lib/pleroma/user.ex | 4 ++-- test/user_test.exs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3010fe87f..16d0889c4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -178,8 +178,8 @@ defmodule Pleroma.User do def ap_following(%User{} = user), do: "#{ap_id(user)}/following" def user_info(%User{} = user, args \\ %{}) do - following_count = Map.get(args, :following_count, user.following_count) - follower_count = Map.get(args, :follower_count, user.follower_count) + following_count = Map.get(args, :following_count, user.following_count) || 0 + follower_count = Map.get(args, :follower_count, user.follower_count) || 0 %{ note_count: user.note_count, diff --git a/test/user_test.exs b/test/user_test.exs index e6302b525..4917ea9ce 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1347,6 +1347,14 @@ defmodule Pleroma.UserTest do assert User.user_info(user).follower_count == 2 end + test "with nil follower count fields, 0 will be returned" do + user = insert(:user, follower_count: nil, following_count: nil) + user_info = User.user_info(user) + + assert user_info.follower_count == 0 + assert user_info.following_count == 0 + end + describe "list_inactive_users_query/1" do defp days_ago(days) do NaiveDateTime.add( -- 2.45.2