added privacy option to push notifications

This commit is contained in:
Maksim Pechnikov 2019-10-29 21:33:17 +03:00
commit 04a8ffbe84
6 changed files with 76 additions and 40 deletions

View file

@ -12,29 +12,10 @@ defmodule Pleroma.User.NotificationSettingTest do
changeset =
NotificationSetting.changeset(
%NotificationSetting{},
%{"privacy_option" => "name_only"}
%{"privacy_option" => true}
)
assert %Ecto.Changeset{valid?: true} = changeset
end
test "returns invalid changeset when privacy option is incorrect" do
changeset =
NotificationSetting.changeset(
%NotificationSetting{},
%{"privacy_option" => "full_content"}
)
assert %Ecto.Changeset{valid?: false} = changeset
assert [
privacy_option:
{"is invalid",
[
validation: :inclusion,
enum: ["name_and_message", "name_only", "no_name_or_message"]
]}
] = changeset.errors
end
end
end

View file

@ -6,6 +6,7 @@ defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
@ -182,4 +183,50 @@ defmodule Pleroma.Web.Push.ImplTest do
assert Impl.format_title(%{activity: activity}) ==
"New Direct Message"
end
describe "build_content/3" do
test "returns info content for direct message with enabled privacy option" do
user = insert(:user, nickname: "Bob")
user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})
{:ok, activity} =
CommonAPI.post(user, %{
"visibility" => "direct",
"status" => "<Lorem ipsum dolor sit amet."
})
notif = insert(:notification, user: user2, activity: activity)
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
object = Object.normalize(activity)
assert Impl.build_content(notif, actor, object) == %{
body: "@Bob",
title: "New Direct Message"
}
end
test "returns regular content for direct message with disabled privacy option" do
user = insert(:user, nickname: "Bob")
user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false})
{:ok, activity} =
CommonAPI.post(user, %{
"visibility" => "direct",
"status" =>
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
notif = insert(:notification, user: user2, activity: activity)
actor = User.get_cached_by_ap_id(notif.activity.data["actor"])
object = Object.normalize(activity)
assert Impl.build_content(notif, actor, object) == %{
body:
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini...",
title: "New Direct Message"
}
end
end
end

View file

@ -164,7 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
follows: true,
non_follows: true,
non_followers: true,
privacy_option: "name_and_message"
privacy_option: false
} == user.notification_settings
end
@ -173,7 +173,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
conn
|> assign(:user, user)
|> put("/api/pleroma/notification_settings", %{"privacy_option" => "name_only"})
|> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
|> json_response(:ok)
user = refresh_record(user)
@ -183,7 +183,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
follows: true,
non_follows: true,
non_followers: true,
privacy_option: "name_only"
privacy_option: true
} == user.notification_settings
end
end