mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-15 17:16:57 +00:00
MastoAPI AccountView: Add mute/block expiry to the relationship object
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
d6bec8b6b7
commit
6fac6ff7f1
3 changed files with 56 additions and 26 deletions
|
|
@ -45,7 +45,7 @@ defmodule Pleroma.UserRelationship do
|
|||
do: exists?(unquote(relationship_type), source, target)
|
||||
|
||||
# `def get_block_expire_date/2`, `def get_mute_expire_date/2`,
|
||||
# `def get_reblog_mute_expire_date/2`, `def get_notification_mute_exists?/2`,
|
||||
# `def get_reblog_mute_expire_date/2`, `def get_notification_mute_expire_date/2`,
|
||||
# `def get_inverse_subscription_expire_date/2`, `def get_inverse_endorsement_expire_date/2`
|
||||
def unquote(:"get_#{relationship_type}_expire_date")(source, target),
|
||||
do: get_expire_date(unquote(relationship_type), source, target)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
|||
requested: %Schema{type: :boolean},
|
||||
showing_reblogs: %Schema{type: :boolean},
|
||||
subscribing: %Schema{type: :boolean},
|
||||
notifying: %Schema{type: :boolean}
|
||||
notifying: %Schema{type: :boolean},
|
||||
mute_expires_at: %Schema{type: :string, format: "date-time", nullable: true},
|
||||
block_expires_at: %Schema{type: :string, format: "date-time", nullable: true}
|
||||
},
|
||||
example: %{
|
||||
"blocked_by" => false,
|
||||
|
|
|
|||
|
|
@ -96,6 +96,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
followed_by = FollowingRelationship.following?(target, reading_user)
|
||||
following = FollowingRelationship.following?(reading_user, target)
|
||||
|
||||
blocking =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:block,
|
||||
reading_user,
|
||||
target,
|
||||
&User.blocks_user?(&1, &2)
|
||||
)
|
||||
|
||||
muting =
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:mute,
|
||||
reading_user,
|
||||
target,
|
||||
&User.mutes?(&1, &2)
|
||||
)
|
||||
|
||||
requested =
|
||||
cond do
|
||||
following -> false
|
||||
|
|
@ -116,14 +134,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
id: to_string(target.id),
|
||||
following: following,
|
||||
followed_by: followed_by,
|
||||
blocking:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:block,
|
||||
reading_user,
|
||||
target,
|
||||
&User.blocks_user?(&1, &2)
|
||||
),
|
||||
blocking: blocking,
|
||||
blocked_by:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
|
|
@ -132,14 +143,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
reading_user,
|
||||
&User.blocks_user?(&1, &2)
|
||||
),
|
||||
muting:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
:mute,
|
||||
reading_user,
|
||||
target,
|
||||
&User.mutes?(&1, &2)
|
||||
),
|
||||
muting: muting,
|
||||
muting_notifications:
|
||||
UserRelationship.exists?(
|
||||
user_relationships,
|
||||
|
|
@ -174,6 +178,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
&User.endorses?(&1, &2)
|
||||
)
|
||||
}
|
||||
|> maybe_put_mute_expires_at(target, reading_user, %{mutes: muting})
|
||||
|> maybe_put_block_expires_at(target, reading_user, %{blocks: blocking})
|
||||
end
|
||||
|
||||
def render("relationships.json", %{user: user, targets: targets} = opts) do
|
||||
|
|
@ -343,8 +349,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|> maybe_put_unread_conversation_count(user, opts[:for])
|
||||
|> maybe_put_unread_notification_count(user, opts[:for])
|
||||
|> maybe_put_email_address(user, opts[:for])
|
||||
|> maybe_put_mute_expires_at(user, opts[:for], opts)
|
||||
|> maybe_put_block_expires_at(user, opts[:for], opts)
|
||||
|> maybe_put_mute_expires_at(user, opts[:for], opts, relationship)
|
||||
|> maybe_put_block_expires_at(user, opts[:for], opts, relationship)
|
||||
|> maybe_show_birthday(user, opts[:for])
|
||||
end
|
||||
|
||||
|
|
@ -472,25 +478,47 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
|
||||
defp maybe_put_email_address(data, _, _), do: data
|
||||
|
||||
defp maybe_put_mute_expires_at(data, %User{} = user, target, %{mutes: true}) do
|
||||
defp maybe_put_mute_expires_at(data, target, user, opts, relationship \\ nil)
|
||||
|
||||
defp maybe_put_mute_expires_at(data, _target, _user, %{mutes: true}, %{
|
||||
mute_expires_at: mute_expires_at
|
||||
}) do
|
||||
Map.put(data, :mute_expires_at, mute_expires_at)
|
||||
end
|
||||
|
||||
defp maybe_put_mute_expires_at(data, %User{} = target, user, %{mutes: true}, _relationship) do
|
||||
Map.put(
|
||||
data,
|
||||
:mute_expires_at,
|
||||
UserRelationship.get_mute_expire_date(target, user)
|
||||
UserRelationship.get_mute_expire_date(user, target)
|
||||
)
|
||||
end
|
||||
|
||||
defp maybe_put_mute_expires_at(data, _, _, _), do: data
|
||||
defp maybe_put_mute_expires_at(data, _, _, _, _), do: data
|
||||
|
||||
defp maybe_put_block_expires_at(data, %User{} = user, target, %{blocks: true}) do
|
||||
defp maybe_put_block_expires_at(data, target, user, opts, relationship \\ nil)
|
||||
|
||||
defp maybe_put_block_expires_at(data, _target, _user, %{blocks: true}, %{
|
||||
block_expires_at: block_expires_at
|
||||
}) do
|
||||
Map.put(data, :block_expires_at, block_expires_at)
|
||||
end
|
||||
|
||||
defp maybe_put_block_expires_at(
|
||||
data,
|
||||
%User{} = target,
|
||||
%User{} = user,
|
||||
%{blocks: true},
|
||||
_relationship
|
||||
) do
|
||||
Map.put(
|
||||
data,
|
||||
:block_expires_at,
|
||||
UserRelationship.get_block_expire_date(target, user)
|
||||
UserRelationship.get_block_expire_date(user, target)
|
||||
)
|
||||
end
|
||||
|
||||
defp maybe_put_block_expires_at(data, _, _, _), do: data
|
||||
defp maybe_put_block_expires_at(data, _, _, _, _), do: data
|
||||
|
||||
defp maybe_show_birthday(data, %User{id: user_id} = user, %User{id: user_id}) do
|
||||
data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue