Merge branch 'develop' into issue/1276
authorMaksim Pechnikov <parallel588@gmail.com>
Sun, 8 Dec 2019 17:14:28 +0000 (20:14 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Sun, 8 Dec 2019 17:14:28 +0000 (20:14 +0300)
1  2 
CHANGELOG.md
lib/pleroma/notification.ex
test/notification_test.exs

diff --cc CHANGELOG.md
index f021fefc3b23ff4969c00090ecbb9dbc3056673d,d000977482f42fed2265c1a57193aa688ed28843..4a2296cdd071107c308b4a842494d497c3d2ea2d
@@@ -35,7 -36,7 +36,8 @@@ The format is based on [Keep a Changelo
  - Mastodon API: `pleroma.thread_muted` to the Status entity
  - Mastodon API: Mark the direct conversation as read for the author when they send a new direct message
  - Mastodon API, streaming: Add `pleroma.direct_conversation_id` to the `conversation` stream event payload.
 +- Mastodon API: Add `pleroma.unread_count` to the Marker entity
+ - Admin API: Render whole status in grouped reports
  </details>
  
  ### Added
index d6149cd0da2bf8500bab549e7b3fd0efc063fa6e,71423ce5e89695175073e6d44d41bfaba56b5f88..11adbb77bf7e9278cb959878a6b79e65450ea851
@@@ -36,26 -36,25 +38,44 @@@ defmodule Pleroma.Notification d
      |> cast(attrs, [:seen])
    end
  
-   def for_user_query(user, opts \\ []) do
 +  @spec unread_count_query(User.t()) :: Ecto.Queryable.t()
 +  def unread_count_query(user) do
 +    from(q in Pleroma.Notification,
 +      where: q.user_id == ^user.id,
 +      where: q.seen == false
 +    )
 +  end
 +
 +  @spec last_read_query(User.t()) :: Ecto.Queryable.t()
 +  def last_read_query(user) do
 +    from(q in Pleroma.Notification,
 +      where: q.user_id == ^user.id,
 +      where: q.seen == true,
 +      select: type(q.id, :string),
 +      limit: 1,
 +      order_by: [desc: :id]
 +    )
 +  end
 +
+   defp for_user_query_ap_id_opts(user, opts) do
+     ap_id_relations =
+       [:block] ++
+         if opts[@include_muted_option], do: [], else: [:notification_mute]
+     preloaded_ap_ids = User.outgoing_relations_ap_ids(user, ap_id_relations)
+     exclude_blocked_opts = Map.merge(%{blocked_users_ap_ids: preloaded_ap_ids[:block]}, opts)
+     exclude_notification_muted_opts =
+       Map.merge(%{notification_muted_users_ap_ids: preloaded_ap_ids[:notification_mute]}, opts)
+     {exclude_blocked_opts, exclude_notification_muted_opts}
+   end
+   def for_user_query(user, opts \\ %{}) do
+     {exclude_blocked_opts, exclude_notification_muted_opts} =
+       for_user_query_ap_id_opts(user, opts)
      Notification
      |> where(user_id: ^user.id)
      |> where(
Simple merge