From: Maksim Pechnikov Date: Sun, 8 Dec 2019 17:14:28 +0000 (+0300) Subject: Merge branch 'develop' into issue/1276 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=6fbafb1cdcba3dc2a7e8b9718e295c9811a726d9;p=akkoma Merge branch 'develop' into issue/1276 --- 6fbafb1cdcba3dc2a7e8b9718e295c9811a726d9 diff --cc CHANGELOG.md index f021fefc3,d00097748..4a2296cdd --- a/CHANGELOG.md +++ b/CHANGELOG.md @@@ -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 ### Added diff --cc lib/pleroma/notification.ex index d6149cd0d,71423ce5e..11adbb77b --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@@ -36,26 -36,25 +38,44 @@@ defmodule Pleroma.Notification d |> cast(attrs, [:seen]) end + @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 + - def for_user_query(user, opts \\ []) do + 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(