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
|
||||
{: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 =
|
||||
Enum.map(users, fn user ->
|
||||
|
|
|
@ -92,8 +92,9 @@ defmodule Pleroma.Notification do
|
|||
|> join(:left, [n, a], object in Object,
|
||||
on:
|
||||
fragment(
|
||||
"(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)",
|
||||
"(?->>'id') = COALESCE(?->'object'->>'id', ?->>'object')",
|
||||
object.data,
|
||||
a.data,
|
||||
a.data
|
||||
)
|
||||
)
|
||||
|
@ -224,18 +225,8 @@ defmodule Pleroma.Notification do
|
|||
|> Marker.multi_set_last_read_id(user, "notifications")
|
||||
|> Repo.transaction()
|
||||
|
||||
Notification
|
||||
for_user_query(user)
|
||||
|> 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()
|
||||
end
|
||||
|
||||
|
@ -370,7 +361,8 @@ defmodule Pleroma.Notification do
|
|||
when type in ["Create", "Like", "Announce", "Follow", "Move", "EmojiReact"] do
|
||||
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 =
|
||||
potential_receiver_ap_ids
|
||||
|
|
|
@ -1208,8 +1208,9 @@ defmodule Pleroma.User do
|
|||
|
||||
def increment_unread_conversation_count(_, user), do: {:ok, user}
|
||||
|
||||
@spec get_users_from_set([String.t()], boolean()) :: [User.t()]
|
||||
def get_users_from_set(ap_ids, local_only \\ true) do
|
||||
@spec get_users_from_set([String.t()], keyword()) :: [User.t()]
|
||||
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 = 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()
|
||||
|> Object.with_joined_activity()
|
||||
|> select([_like, object, activity], %{activity | object: object})
|
||||
|> order_by([like, _, _], desc: like.id)
|
||||
|> order_by([like, _, _], desc_nulls_last: like.id)
|
||||
|> Pagination.fetch_paginated(
|
||||
Map.merge(params, %{"skip_order" => true}),
|
||||
pagination,
|
||||
|
|
|
@ -1045,10 +1045,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
Map.put(object, "tag", tags)
|
||||
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
|
||||
{enabled_receivers, disabled_receivers} = Utils.get_notified_from_object(object)
|
||||
potential_receivers = enabled_receivers ++ disabled_receivers
|
||||
mentions = Enum.map(potential_receivers, &build_mention_tag/1)
|
||||
to = object["to"] || []
|
||||
cc = object["cc"] || []
|
||||
mentioned = User.get_users_from_set(to ++ cc, local_only: false)
|
||||
|
||||
mentions = Enum.map(mentioned, &build_mention_tag/1)
|
||||
|
||||
tags = object["tag"] || []
|
||||
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}!"
|
||||
})
|
||||
|
||||
[n2, n1] = notifs = Notification.for_user(other_user)
|
||||
assert length(notifs) == 2
|
||||
[n2, n1] = Notification.for_user(other_user)
|
||||
|
||||
assert n2.id > n1.id
|
||||
|
||||
|
@ -464,7 +463,9 @@ defmodule Pleroma.NotificationTest do
|
|||
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)
|
||||
|
||||
|
@ -972,7 +973,9 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
{: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
|
||||
|
||||
test "it doesn't return notifications for muted user with notifications" do
|
||||
|
|
|
@ -1094,23 +1094,28 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
object = modified["object"]
|
||||
with_mock Pleroma.Notification,
|
||||
get_notified_from_activity: fn _, _ -> [] end do
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
expected_mention = %{
|
||||
"href" => other_user.ap_id,
|
||||
"name" => "@#{other_user.nickname}",
|
||||
"type" => "Mention"
|
||||
}
|
||||
object = modified["object"]
|
||||
|
||||
expected_tag = %{
|
||||
"href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
|
||||
"type" => "Hashtag",
|
||||
"name" => "#2hu"
|
||||
}
|
||||
expected_mention = %{
|
||||
"href" => other_user.ap_id,
|
||||
"name" => "@#{other_user.nickname}",
|
||||
"type" => "Mention"
|
||||
}
|
||||
|
||||
assert Enum.member?(object["tag"], expected_tag)
|
||||
assert Enum.member?(object["tag"], expected_mention)
|
||||
expected_tag = %{
|
||||
"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
|
||||
|
||||
test "it adds the sensitive property" do
|
||||
|
|
Loading…
Reference in New Issue