Merge remote-tracking branch 'origin/neckbeard' into adminfe
This commit is contained in:
commit
2cb1e2a7e8
|
@ -63,7 +63,7 @@ defmodule Pleroma.Conversation do
|
||||||
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do
|
ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do
|
||||||
{:ok, conversation} = create_for_ap_id(ap_id)
|
{:ok, conversation} = create_for_ap_id(ap_id)
|
||||||
|
|
||||||
users = User.get_users_from_set(activity.recipients, false)
|
users = User.get_users_from_set(activity.recipients, local_only: false)
|
||||||
|
|
||||||
participations =
|
participations =
|
||||||
Enum.map(users, fn user ->
|
Enum.map(users, fn user ->
|
||||||
|
|
|
@ -92,8 +92,9 @@ defmodule Pleroma.Notification do
|
||||||
|> join(:left, [n, a], object in Object,
|
|> join(:left, [n, a], object in Object,
|
||||||
on:
|
on:
|
||||||
fragment(
|
fragment(
|
||||||
"(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
|
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||||
object.data,
|
object.data,
|
||||||
|
a.data,
|
||||||
a.data
|
a.data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -224,18 +225,8 @@ defmodule Pleroma.Notification do
|
||||||
|> Marker.multi_set_last_read_id(user, "notifications")
|
|> Marker.multi_set_last_read_id(user, "notifications")
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|
|
||||||
Notification
|
for_user_query(user)
|
||||||
|> where([n], n.id in ^notification_ids)
|
|> where([n], n.id in ^notification_ids)
|
||||||
|> join(:inner, [n], activity in assoc(n, :activity))
|
|
||||||
|> join(:left, [n, a], object in Object,
|
|
||||||
on:
|
|
||||||
fragment(
|
|
||||||
"(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
|
|
||||||
object.data,
|
|
||||||
a.data
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|> preload([n, a, o], activity: {a, object: o})
|
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -370,7 +361,8 @@ defmodule Pleroma.Notification do
|
||||||
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact"] do
|
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact"] do
|
||||||
potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
|
potential_receiver_ap_ids = get_potential_receiver_ap_ids(activity)
|
||||||
|
|
||||||
potential_receivers = User.get_users_from_set(potential_receiver_ap_ids, local_only)
|
potential_receivers =
|
||||||
|
User.get_users_from_set(potential_receiver_ap_ids, local_only: local_only)
|
||||||
|
|
||||||
notification_enabled_ap_ids =
|
notification_enabled_ap_ids =
|
||||||
potential_receiver_ap_ids
|
potential_receiver_ap_ids
|
||||||
|
|
|
@ -1208,8 +1208,9 @@ defmodule Pleroma.User do
|
||||||
|
|
||||||
def increment_unread_conversation_count(_, user), do: {:ok, user}
|
def increment_unread_conversation_count(_, user), do: {:ok, user}
|
||||||
|
|
||||||
@spec get_users_from_set([String.t()], boolean()) :: [User.t()]
|
@spec get_users_from_set([String.t()], keyword()) :: [User.t()]
|
||||||
def get_users_from_set(ap_ids, local_only \\ true) do
|
def get_users_from_set(ap_ids, opts \\ []) do
|
||||||
|
local_only = Keyword.get(opts, :local_only, true)
|
||||||
criteria = %{ap_id: ap_ids, deactivated: false}
|
criteria = %{ap_id: ap_ids, deactivated: false}
|
||||||
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
|
criteria = if local_only, do: Map.put(criteria, :local, true), else: criteria
|
||||||
|
|
||||||
|
|
|
@ -1158,7 +1158,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|> Activity.with_joined_object()
|
|> Activity.with_joined_object()
|
||||||
|> Object.with_joined_activity()
|
|> Object.with_joined_activity()
|
||||||
|> select([_like, object, activity], %{activity | object: object})
|
|> select([_like, object, activity], %{activity | object: object})
|
||||||
|> order_by([like, _, _], desc: like.id)
|
|> order_by([like, _, _], desc_nulls_last: like.id)
|
||||||
|> Pagination.fetch_paginated(
|
|> Pagination.fetch_paginated(
|
||||||
Map.merge(params, %{"skip_order" => true}),
|
Map.merge(params, %{"skip_order" => true}),
|
||||||
pagination,
|
pagination,
|
||||||
|
|
|
@ -1045,10 +1045,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
Map.put(object, "tag", tags)
|
Map.put(object, "tag", tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO These should be added on our side on insertion, it doesn't make much
|
||||||
|
# sense to regenerate these all the time
|
||||||
def add_mention_tags(object) do
|
def add_mention_tags(object) do
|
||||||
{enabled_receivers, disabled_receivers} = Utils.get_notified_from_object(object)
|
to = object["to"] || []
|
||||||
potential_receivers = enabled_receivers ++ disabled_receivers
|
cc = object["cc"] || []
|
||||||
mentions = Enum.map(potential_receivers, &build_mention_tag/1)
|
mentioned = User.get_users_from_set(to ++ cc, local_only: false)
|
||||||
|
|
||||||
|
mentions = Enum.map(mentioned, &build_mention_tag/1)
|
||||||
|
|
||||||
tags = object["tag"] || []
|
tags = object["tag"] || []
|
||||||
Map.put(object, "tag", tags ++ mentions)
|
Map.put(object, "tag", tags ++ mentions)
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.ChangeNotificationUserIndex do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
drop_if_exists(index(:notifications, [:user_id]))
|
||||||
|
create_if_not_exists(index(:notifications, [:user_id, "id desc nulls last"]))
|
||||||
|
end
|
||||||
|
end
|
|
@ -454,8 +454,7 @@ defmodule Pleroma.NotificationTest do
|
||||||
status: "hey again @#{other_user.nickname}!"
|
status: "hey again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
[n2, n1] = notifs = Notification.for_user(other_user)
|
[n2, n1] = Notification.for_user(other_user)
|
||||||
assert length(notifs) == 2
|
|
||||||
|
|
||||||
assert n2.id > n1.id
|
assert n2.id > n1.id
|
||||||
|
|
||||||
|
@ -464,7 +463,9 @@ defmodule Pleroma.NotificationTest do
|
||||||
status: "hey yet again @#{other_user.nickname}!"
|
status: "hey yet again @#{other_user.nickname}!"
|
||||||
})
|
})
|
||||||
|
|
||||||
Notification.set_read_up_to(other_user, n2.id)
|
[_, read_notification] = Notification.set_read_up_to(other_user, n2.id)
|
||||||
|
|
||||||
|
assert read_notification.activity.object
|
||||||
|
|
||||||
[n3, n2, n1] = Notification.for_user(other_user)
|
[n3, n2, n1] = Notification.for_user(other_user)
|
||||||
|
|
||||||
|
@ -972,7 +973,9 @@ defmodule Pleroma.NotificationTest do
|
||||||
|
|
||||||
{:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
|
{:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
|
||||||
|
|
||||||
assert length(Notification.for_user(user)) == 1
|
[notification] = Notification.for_user(user)
|
||||||
|
|
||||||
|
assert notification.activity.object
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it doesn't return notifications for muted user with notifications" do
|
test "it doesn't return notifications for muted user with notifications" do
|
||||||
|
|
|
@ -1094,23 +1094,28 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
{:ok, activity} =
|
{:ok, activity} =
|
||||||
CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
|
CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
|
||||||
|
|
||||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
with_mock Pleroma.Notification,
|
||||||
object = modified["object"]
|
get_notified_from_activity: fn _, _ -> [] end do
|
||||||
|
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||||
|
|
||||||
expected_mention = %{
|
object = modified["object"]
|
||||||
"href" => other_user.ap_id,
|
|
||||||
"name" => "@#{other_user.nickname}",
|
|
||||||
"type" => "Mention"
|
|
||||||
}
|
|
||||||
|
|
||||||
expected_tag = %{
|
expected_mention = %{
|
||||||
"href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
|
"href" => other_user.ap_id,
|
||||||
"type" => "Hashtag",
|
"name" => "@#{other_user.nickname}",
|
||||||
"name" => "#2hu"
|
"type" => "Mention"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert Enum.member?(object["tag"], expected_tag)
|
expected_tag = %{
|
||||||
assert Enum.member?(object["tag"], expected_mention)
|
"href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
|
||||||
|
"type" => "Hashtag",
|
||||||
|
"name" => "#2hu"
|
||||||
|
}
|
||||||
|
|
||||||
|
refute called(Pleroma.Notification.get_notified_from_activity(:_, :_))
|
||||||
|
assert Enum.member?(object["tag"], expected_tag)
|
||||||
|
assert Enum.member?(object["tag"], expected_mention)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it adds the sensitive property" do
|
test "it adds the sensitive property" do
|
||||||
|
|
Loading…
Reference in New Issue