Mastodon API: Set follower/following counters to 0 when hiding
followers/following is enabled We are already doing that in AP representation, so I think we should do it here as well for consistency.
This commit is contained in:
parent
9c499435f0
commit
dcd30e3ceb
3 changed files with 40 additions and 2 deletions
|
@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
|
## [1.0.5] - 2019-08-??
|
||||||
|
### Fixed
|
||||||
|
- Mastodon API: follower/following counters not being nullified, when `hide_follows`/`hide_followers` is set
|
||||||
|
|
||||||
## [1.0.4] - 2019-08-01
|
## [1.0.4] - 2019-08-01
|
||||||
### Fixed
|
### Fixed
|
||||||
- Invalid SemVer version generation, when the current branch does not have commits ahead of tag/checked out on a tag
|
- Invalid SemVer version generation, when the current branch does not have commits ahead of tag/checked out on a tag
|
||||||
|
|
|
@ -71,6 +71,13 @@ defp do_render("account.json", %{user: user} = opts) do
|
||||||
image = User.avatar_url(user) |> MediaProxy.url()
|
image = User.avatar_url(user) |> MediaProxy.url()
|
||||||
header = User.banner_url(user) |> MediaProxy.url()
|
header = User.banner_url(user) |> MediaProxy.url()
|
||||||
user_info = User.get_cached_user_info(user)
|
user_info = User.get_cached_user_info(user)
|
||||||
|
|
||||||
|
following_count =
|
||||||
|
((!user.info.hide_follows or opts[:for] == user) && user_info.following_count) || 0
|
||||||
|
|
||||||
|
followers_count =
|
||||||
|
((!user.info.hide_followers or opts[:for] == user) && user_info.follower_count) || 0
|
||||||
|
|
||||||
bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
|
bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
|
||||||
|
|
||||||
emojis =
|
emojis =
|
||||||
|
@ -101,8 +108,8 @@ defp do_render("account.json", %{user: user} = opts) do
|
||||||
display_name: display_name,
|
display_name: display_name,
|
||||||
locked: user_info.locked,
|
locked: user_info.locked,
|
||||||
created_at: Utils.to_masto_date(user.inserted_at),
|
created_at: Utils.to_masto_date(user.inserted_at),
|
||||||
followers_count: user_info.follower_count,
|
followers_count: followers_count,
|
||||||
following_count: user_info.following_count,
|
following_count: following_count,
|
||||||
statuses_count: user_info.note_count,
|
statuses_count: user_info.note_count,
|
||||||
note: bio || "",
|
note: bio || "",
|
||||||
url: user.ap_id,
|
url: user.ap_id,
|
||||||
|
|
|
@ -275,4 +275,31 @@ test "sanitizes display names" do
|
||||||
result = AccountView.render("account.json", %{user: user})
|
result = AccountView.render("account.json", %{user: user})
|
||||||
refute result.display_name == "<marquee> username </marquee>"
|
refute result.display_name == "<marquee> username </marquee>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "hiding follows/following" do
|
||||||
|
test "shows when follows/following are hidden and sets follower/following count to 0" do
|
||||||
|
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||||
|
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
followers_count: 0,
|
||||||
|
following_count: 0,
|
||||||
|
pleroma: %{hide_follows: true, hide_followers: true}
|
||||||
|
} = AccountView.render("account.json", %{user: user})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "shows actual follower/following count to the account owner" do
|
||||||
|
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||||
|
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
followers_count: 1,
|
||||||
|
following_count: 1
|
||||||
|
} = AccountView.render("account.json", %{user: user, for: user})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue