# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI do
- alias Pleroma.{User, Repo, Activity, Object}
+ alias Pleroma.User
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.ThreadMute
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Formatter
attachments,
tags,
get_content_type(data["content_type"]),
- Enum.member?([true, "true"], data["no_attachment_links"])
+ Enum.member?(
+ [true, "true"],
+ Map.get(
+ data,
+ "no_attachment_links",
+ Pleroma.Config.get([:instance, :no_attachment_links], false)
+ )
+ )
),
context <- make_context(inReplyTo),
cw <- data["spoiler_text"],
actor: user,
context: context,
object: object,
- additional: %{"cc" => cc}
+ additional: %{"cc" => cc, "directMessage" => visibility == "direct"}
})
res
{:error, "Could not unpin"}
end
end
+
+ def add_mute(user, activity) do
+ with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]) do
+ {:ok, activity}
+ else
+ {:error, _} -> {:error, "conversation is already muted"}
+ end
+ end
+
+ def remove_mute(user, activity) do
+ ThreadMute.remove_mute(user.id, activity.data["context"])
+ {:ok, activity}
+ end
+
+ def thread_muted?(%{id: nil} = _user, _activity), do: false
+
+ def thread_muted?(user, activity) do
+ with [] <- ThreadMute.check_muted(user.id, activity.data["context"]) do
+ false
+ else
+ _ -> true
+ end
+ end
end