use Ecto.Schema
alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ObjectValidators.Types
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.Types
import Ecto.Changeset
import Pleroma.Web.ActivityPub.Transmogrifier, only: [fix_emoji: 1]
def fix(data) do
data
|> fix_emoji()
+ |> fix_attachment()
|> Map.put_new("actor", data["attributedTo"])
end
+ # Throws everything but the first one away
+ def fix_attachment(%{"attachment" => [attachment | _]} = data) do
+ data
+ |> Map.put("attachment", attachment)
+ end
+
+ def fix_attachment(data), do: data
+
def changeset(struct, data) do
data = fix(data)
def validate_data(data_cng) do
data_cng
|> validate_inclusion(:type, ["ChatMessage"])
- |> validate_required([:id, :actor, :to, :type, :content, :published])
+ |> validate_required([:id, :actor, :to, :type, :published])
+ |> validate_content_or_attachment()
|> validate_length(:to, is: 1)
|> validate_length(:content, max: Pleroma.Config.get([:instance, :remote_limit]))
|> validate_local_concern()
end
+ def validate_content_or_attachment(cng) do
+ attachment = get_field(cng, :attachment)
+
+ if attachment do
+ cng
+ else
+ cng
+ |> validate_required([:content])
+ end
+ end
+
@doc """
Validates the following
- If both users are in our system