Birthdays: hide_birthday -> show_birthday

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-01-23 08:42:18 +01:00
parent aaa9314f4c
commit 0266bc3c96
14 changed files with 39 additions and 37 deletions

View file

@ -28,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added `/manifest.json` for progressive web apps.
- MastoAPI: Support for `birthday` and `show_birthday` field in `/api/v1/accounts/update_credentials`.
- Configuration: Add `birthday_required` and `birthday_min_age` settings to provide a way to require users to enter their birth date.
- PleromaAPI: Add `GET /api/v1/pleroma/birthday_reminders` API endpoint
- PleromaAPI: Add `GET /api/v1/pleroma/birthdays` API endpoint
### Fixed
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies

View file

@ -155,7 +155,7 @@ defmodule Pleroma.User do
field(:is_suggested, :boolean, default: false)
field(:last_status_at, :naive_datetime)
field(:birthday, :date)
field(:hide_birthday, :boolean, default: false)
field(:show_birthday, :boolean, default: false)
embeds_one(
:notification_settings,
@ -473,7 +473,8 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
:also_known_as,
:accepts_chat_messages,
:pinned_objects,
:birthday
:birthday,
:show_birthday
]
)
|> cast(params, [:name], empty_values: [])
@ -536,7 +537,7 @@ def update_changeset(struct, params \\ %{}) do
:accepts_chat_messages,
:disclose_client,
:birthday,
:hide_birthday
:show_birthday
]
)
|> validate_min_age()

View file

@ -234,14 +234,14 @@ defp compose_query({:internal, false}, query) do
defp compose_query({:birthday_day, day}, query) do
query
|> where([u], u.hide_birthday == false)
|> where([u], u.show_birthday == true)
|> where([u], not is_nil(u.birthday))
|> where([u], fragment("date_part('day', ?)", u.birthday) == ^day)
end
defp compose_query({:birthday_month, month}, query) do
query
|> where([u], u.hide_birthday == false)
|> where([u], u.show_birthday == true)
|> where([u], not is_nil(u.birthday))
|> where([u], fragment("date_part('month', ?)", u.birthday) == ^month)
end

View file

@ -1511,6 +1511,8 @@ defp object_to_user_data(data) do
nil
end
show_birthday = !!birthday
user_data = %{
ap_id: data["id"],
uri: get_actor_url(data["url"]),
@ -1534,7 +1536,8 @@ defp object_to_user_data(data) do
shared_inbox: shared_inbox,
accepts_chat_messages: accepts_chat_messages,
pinned_objects: pinned_objects,
birthday: birthday
birthday: birthday,
show_birthday: show_birthday
}
# nickname can be nil because of virtual actors

View file

@ -93,7 +93,7 @@ def render("user.json", %{user: user}) do
end
birthday =
if !user.hide_birthday,
if user.show_birthday,
do: user.birthday,
else: nil

View file

@ -733,10 +733,10 @@ defp update_credentials_request do
description: "User's birthday",
format: :date
},
hide_birthday: %Schema{
show_birthday: %Schema{
allOf: [BooleanLike],
nullable: true,
description: "User's birthday will be hidden"
description: "User's birthday will be visible"
}
},
example: %{
@ -758,7 +758,7 @@ defp update_credentials_request do
also_known_as: ["https://foo.bar/users/foo"],
discoverable: false,
actor_type: "Person",
hide_birthday: true,
show_birthday: false,
birthday: "2001-02-12"
}
}

View file

@ -54,7 +54,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
description:
"whether the user account is waiting on email confirmation to be activated"
},
hide_birthday: %Schema{type: :boolean, nullable: true},
show_birthday: %Schema{type: :boolean, nullable: true},
hide_favorites: %Schema{type: :boolean},
hide_followers_count: %Schema{
type: :boolean,

View file

@ -192,7 +192,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
:allow_following_move,
:also_known_as,
:accepts_chat_messages,
:hide_birthday
:show_birthday
]
|> Enum.reduce(%{}, fn key, acc ->
Maps.put_if_present(acc, key, params[key], &{:ok, Params.truthy_param?(&1)})

View file

@ -298,8 +298,7 @@ defp do_render("show.json", %{user: user} = opts) do
background_image: image_url(user.background) |> MediaProxy.url(),
accepts_chat_messages: user.accepts_chat_messages,
favicon: favicon,
birthday: user.birthday,
hide_birthday: user.hide_birthday
birthday: user.birthday
}
}
|> maybe_put_role(user, opts[:for])
@ -313,7 +312,7 @@ defp do_render("show.json", %{user: user} = opts) do
|> maybe_put_unread_conversation_count(user, opts[:for])
|> maybe_put_unread_notification_count(user, opts[:for])
|> maybe_put_email_address(user, opts[:for])
|> maybe_hide_birthday(user, opts[:for])
|> maybe_show_birthday(user, opts[:for])
end
defp username_from_nickname(string) when is_binary(string) do
@ -347,6 +346,7 @@ defp maybe_put_settings(
|> Kernel.put_in([:source, :privacy], user.default_scope)
|> Kernel.put_in([:source, :pleroma, :show_role], user.show_role)
|> Kernel.put_in([:source, :pleroma, :no_rich_text], user.no_rich_text)
|> Kernel.put_in([:source, :pleroma, :show_birthday], user.show_birthday)
end
defp maybe_put_settings(data, _, _, _), do: data
@ -435,22 +435,18 @@ defp maybe_put_email_address(data, %User{id: user_id}, %User{id: user_id} = user
defp maybe_put_email_address(data, _, _), do: data
defp maybe_hide_birthday(data, %User{id: user_id}, %User{id: user_id}) do
defp maybe_show_birthday(data, %User{id: user_id} = user, %User{id: user_id}) do
data
|> Kernel.put_in([:pleroma, :birthday], user.birthday)
end
defp maybe_hide_birthday(data, %User{hide_birthday: true}, _) do
defp maybe_show_birthday(data, %User{show_birthday: true} = user, _) do
data
|> Kernel.pop_in([:pleroma, :birthday])
|> elem(1)
|> Kernel.pop_in([:pleroma, :hide_birthday])
|> elem(1)
|> Kernel.put_in([:pleroma, :birthday], user.birthday)
end
defp maybe_hide_birthday(data, _, _) do
defp maybe_show_birthday(data, _, _) do
data
|> Kernel.pop_in([:pleroma, :hide_birthday])
|> elem(1)
end
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href

View file

@ -143,7 +143,7 @@ def unsubscribe(%{assigns: %{user: user, account: subscription_target}} = conn,
end
end
@doc "GET /api/v1/pleroma/birthday_reminders"
@doc "GET /api/v1/pleroma/birthdays"
def birthdays(%{assigns: %{user: %User{} = user}} = conn, %{day: day, month: month} = _params) do
birthdays =
User.get_friends_birthdays_query(user, day, month)

View file

@ -449,7 +449,7 @@ defmodule Pleroma.Web.Router do
post("/accounts/:id/subscribe", AccountController, :subscribe)
post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
get("/birthday_reminders", AccountController, :birthdays)
get("/birthdays", AccountController, :birthdays)
end
post("/accounts/confirmation_resend", AccountController, :confirmation_resend)

View file

@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.AddBirthDateToUsers do
def change do
alter table(:users) do
add_if_not_exists(:birthday, :date)
add_if_not_exists(:hide_birthday, :boolean, default: false, null: false)
add_if_not_exists(:show_birthday, :boolean, default: false, null: false)
end
end
end

View file

@ -380,14 +380,14 @@ test "updates birth date", %{conn: conn} do
assert user_data["pleroma"]["birthday"] == "2001-02-12"
end
test "updates the user's hide_birthday status", %{conn: conn} do
test "updates the user's show_birthday status", %{conn: conn} do
res =
patch(conn, "/api/v1/accounts/update_credentials", %{
"hide_birthday" => true
"show_birthday" => true
})
assert user_data = json_response_and_validate_schema(res, 200)
assert user_data["pleroma"]["hide_birthday"] == true
assert user_data["pleroma"]["source"]["show_birthday"] == true
end
test "emojis in fields labels", %{conn: conn} do

View file

@ -312,12 +312,14 @@ test "returns a list of friends having birthday on specified day" do
%{id: id1} =
user1 =
insert(:user, %{
birthday: "2001-02-12"
birthday: "2001-02-12",
show_birthday: true
})
user2 =
insert(:user, %{
birthday: "2001-02-14"
birthday: "2001-02-14",
show_birthday: true
})
user3 = insert(:user)
@ -328,7 +330,7 @@ test "returns a list of friends having birthday on specified day" do
[%{"id" => ^id1}] =
conn
|> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|> json_response_and_validate_schema(:ok)
end
@ -338,14 +340,14 @@ test "the list doesn't list friends with hidden birth date" do
user1 =
insert(:user, %{
birthday: "2001-02-12",
hide_birthday: true
show_birthday: false
})
%{id: id2} =
user2 =
insert(:user, %{
birthday: "2001-02-12",
hide_birthday: false
show_birthday: true
})
CommonAPI.follow(user, user1)
@ -353,7 +355,7 @@ test "the list doesn't list friends with hidden birth date" do
[%{"id" => ^id2}] =
conn
|> get("/api/v1/pleroma/birthday_reminders?day=12&month=2")
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|> json_response_and_validate_schema(:ok)
end
end