Merge branch 'add-muted-to-notifications' into 'develop'

Add `pleroma.is_muted` property to notifications

Closes #1812

See merge request pleroma/pleroma!2670
This commit is contained in:
lain 2020-06-22 15:40:09 +00:00
commit 46f7e51b27
3 changed files with 40 additions and 14 deletions

View File

@ -163,6 +163,13 @@ def notification do
description: description:
"Status that was the object of the notification, e.g. in mentions, reblogs, favourites, or polls.", "Status that was the object of the notification, e.g. in mentions, reblogs, favourites, or polls.",
nullable: true nullable: true
},
pleroma: %Schema{
type: :object,
properties: %{
is_seen: %Schema{type: :boolean},
is_muted: %Schema{type: :boolean}
}
} }
}, },
example: %{ example: %{
@ -170,7 +177,8 @@ def notification do
"type" => "mention", "type" => "mention",
"created_at" => "2019-11-23T07:49:02.064Z", "created_at" => "2019-11-23T07:49:02.064Z",
"account" => Account.schema().example, "account" => Account.schema().example,
"status" => Status.schema().example "status" => Status.schema().example,
"pleroma" => %{"is_seen" => false, "is_muted" => false}
} }
} }
end end

View File

@ -84,12 +84,7 @@ def render(
# Note: :relationships contain user mutes (needed for :muted flag in :status) # Note: :relationships contain user mutes (needed for :muted flag in :status)
status_render_opts = %{relationships: opts[:relationships]} status_render_opts = %{relationships: opts[:relationships]}
account = AccountView.render("show.json", %{user: actor, for: reading_user})
account =
AccountView.render(
"show.json",
%{user: actor, for: reading_user}
)
response = %{ response = %{
id: to_string(notification.id), id: to_string(notification.id),
@ -97,6 +92,7 @@ def render(
created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at), created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
account: account, account: account,
pleroma: %{ pleroma: %{
is_muted: User.mutes?(reading_user, actor),
is_seen: notification.seen is_seen: notification.seen
} }
} }

View File

@ -49,7 +49,7 @@ test "ChatMessage notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "pleroma:chat_mention", type: "pleroma:chat_mention",
account: AccountView.render("show.json", %{user: user, for: recipient}), account: AccountView.render("show.json", %{user: user, for: recipient}),
chat_message: MessageReferenceView.render("show.json", %{chat_message_reference: cm_ref}), chat_message: MessageReferenceView.render("show.json", %{chat_message_reference: cm_ref}),
@ -68,7 +68,7 @@ test "Mention notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "mention", type: "mention",
account: account:
AccountView.render("show.json", %{ AccountView.render("show.json", %{
@ -92,7 +92,7 @@ test "Favourite notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "favourite", type: "favourite",
account: AccountView.render("show.json", %{user: another_user, for: user}), account: AccountView.render("show.json", %{user: another_user, for: user}),
status: StatusView.render("show.json", %{activity: create_activity, for: user}), status: StatusView.render("show.json", %{activity: create_activity, for: user}),
@ -112,7 +112,7 @@ test "Reblog notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "reblog", type: "reblog",
account: AccountView.render("show.json", %{user: another_user, for: user}), account: AccountView.render("show.json", %{user: another_user, for: user}),
status: StatusView.render("show.json", %{activity: reblog_activity, for: user}), status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
@ -130,7 +130,7 @@ test "Follow notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "follow", type: "follow",
account: AccountView.render("show.json", %{user: follower, for: followed}), account: AccountView.render("show.json", %{user: follower, for: followed}),
created_at: Utils.to_masto_date(notification.inserted_at) created_at: Utils.to_masto_date(notification.inserted_at)
@ -171,7 +171,7 @@ test "Move notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "move", type: "move",
account: AccountView.render("show.json", %{user: old_user, for: follower}), account: AccountView.render("show.json", %{user: old_user, for: follower}),
target: AccountView.render("show.json", %{user: new_user, for: follower}), target: AccountView.render("show.json", %{user: new_user, for: follower}),
@ -196,7 +196,7 @@ test "EmojiReact notification" do
expected = %{ expected = %{
id: to_string(notification.id), id: to_string(notification.id),
pleroma: %{is_seen: false}, pleroma: %{is_seen: false, is_muted: false},
type: "pleroma:emoji_reaction", type: "pleroma:emoji_reaction",
emoji: "", emoji: "",
account: AccountView.render("show.json", %{user: other_user, for: user}), account: AccountView.render("show.json", %{user: other_user, for: user}),
@ -206,4 +206,26 @@ test "EmojiReact notification" do
test_notifications_rendering([notification], user, [expected]) test_notifications_rendering([notification], user, [expected])
end end
test "muted notification" do
user = insert(:user)
another_user = insert(:user)
{:ok, _} = Pleroma.UserRelationship.create_mute(user, another_user)
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id)
{:ok, [notification]} = Notification.create_notifications(favorite_activity)
create_activity = Activity.get_by_id(create_activity.id)
expected = %{
id: to_string(notification.id),
pleroma: %{is_seen: false, is_muted: true},
type: "favourite",
account: AccountView.render("show.json", %{user: another_user, for: user}),
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
test_notifications_rendering([notification], user, [expected])
end
end end