mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Misc refactoring / tweaks (ThreadMute.exists?/2
).
This commit is contained in:
parent
6b793d3f83
commit
dfbc05d496
5 changed files with 14 additions and 13 deletions
|
@ -68,8 +68,8 @@ defmodule Pleroma.ThreadMute do
|
||||||
|> Repo.delete_all()
|
|> Repo.delete_all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_muted(user_id, context) do
|
def exists?(user_id, context) do
|
||||||
query(user_id, context)
|
query(user_id, context)
|
||||||
|> Repo.all()
|
|> Repo.exists?()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -358,7 +358,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
def thread_muted?(%{id: nil} = _user, _activity), do: false
|
def thread_muted?(%{id: nil} = _user, _activity), do: false
|
||||||
|
|
||||||
def thread_muted?(user, activity) do
|
def thread_muted?(user, activity) do
|
||||||
ThreadMute.check_muted(user.id, activity.data["context"]) != []
|
ThreadMute.exists?(user.id, activity.data["context"])
|
||||||
end
|
end
|
||||||
|
|
||||||
def report(user, %{"account_id" => account_id} = data) do
|
def report(user, %{"account_id" => account_id} = data) do
|
||||||
|
|
|
@ -98,27 +98,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
relationships_opt = %{relationships: opts[:relationships]}
|
render_opts = %{relationships: opts[:relationships]}
|
||||||
|
|
||||||
case mastodon_type do
|
case mastodon_type do
|
||||||
"mention" ->
|
"mention" ->
|
||||||
put_status(response, activity, reading_user, relationships_opt)
|
put_status(response, activity, reading_user, render_opts)
|
||||||
|
|
||||||
"favourite" ->
|
"favourite" ->
|
||||||
put_status(response, parent_activity_fn.(), reading_user, relationships_opt)
|
put_status(response, parent_activity_fn.(), reading_user, render_opts)
|
||||||
|
|
||||||
"reblog" ->
|
"reblog" ->
|
||||||
put_status(response, parent_activity_fn.(), reading_user, relationships_opt)
|
put_status(response, parent_activity_fn.(), reading_user, render_opts)
|
||||||
|
|
||||||
"move" ->
|
"move" ->
|
||||||
put_target(response, activity, reading_user, relationships_opt)
|
put_target(response, activity, reading_user, render_opts)
|
||||||
|
|
||||||
"follow" ->
|
"follow" ->
|
||||||
response
|
response
|
||||||
|
|
||||||
"pleroma:emoji_reaction" ->
|
"pleroma:emoji_reaction" ->
|
||||||
response
|
response
|
||||||
|> put_status(parent_activity_fn.(), reading_user, relationships_opt)
|
|> put_status(parent_activity_fn.(), reading_user, render_opts)
|
||||||
|> put_emoji(activity)
|
|> put_emoji(activity)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
|
|
@ -228,9 +228,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
end
|
end
|
||||||
|
|
||||||
thread_muted? =
|
thread_muted? =
|
||||||
case activity.thread_muted? do
|
cond do
|
||||||
thread_muted? when is_boolean(thread_muted?) -> thread_muted?
|
is_nil(opts[:for]) -> false
|
||||||
nil -> (opts[:for] && CommonAPI.thread_muted?(opts[:for], activity)) || false
|
is_boolean(activity.thread_muted?) -> activity.thread_muted?
|
||||||
|
true -> CommonAPI.thread_muted?(opts[:for], activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
attachment_data = object.data["attachment"] || []
|
attachment_data = object.data["attachment"] || []
|
||||||
|
|
|
@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||||
|
|
||||||
describe "relationship" do
|
describe "relationship" do
|
||||||
defp test_relationship_rendering(user, other_user, expected_result) do
|
defp test_relationship_rendering(user, other_user, expected_result) do
|
||||||
opts = %{user: user, target: other_user}
|
opts = %{user: user, target: other_user, relationships: nil}
|
||||||
assert expected_result == AccountView.render("relationship.json", opts)
|
assert expected_result == AccountView.render("relationship.json", opts)
|
||||||
|
|
||||||
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
|
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
|
||||||
|
|
Loading…
Reference in a new issue