mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
32 lines
686 B
Elixir
32 lines
686 B
Elixir
defmodule Philomena.Conversations.Message do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
alias Philomena.Conversations.Conversation
|
|
alias Philomena.Users.User
|
|
|
|
schema "messages" do
|
|
belongs_to :conversation, Conversation
|
|
belongs_to :from, User
|
|
|
|
field :body, :string
|
|
|
|
timestamps(inserted_at: :created_at)
|
|
end
|
|
|
|
@doc false
|
|
def changeset(message, attrs) do
|
|
message
|
|
|> cast(attrs, [])
|
|
|> validate_required([])
|
|
end
|
|
|
|
@doc false
|
|
def creation_changeset(message, attrs, user) do
|
|
message
|
|
|> cast(attrs, [:body])
|
|
|> validate_required([:body])
|
|
|> put_assoc(:from, user)
|
|
|> validate_length(:body, max: 300_000, count: :bytes)
|
|
end
|
|
end
|