-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathconversation.ex
More file actions
39 lines (30 loc) · 1.07 KB
/
conversation.ex
File metadata and controls
39 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule CodeCorps.Conversation do
@moduledoc ~S"""
A header of a `CodeCorps.Message` thread, depicting a start of a conversation
with a specific `CodeCorps.User`
When a project sends a `CodeCorps.Message` to one or more users, a
`CodeCorps.Conversation` needs to be created for each of those users, so
separate conversations can be held with different users starting from the same
original `CodeCorps.Message`
Once replies start coming in, a `CodeCorps.ConversationPart` is created for
each of those replies.
"""
use CodeCorps.Model
@type t :: %__MODULE__{}
schema "conversations" do
field :read_at, :utc_datetime, null: true
field :status, :string, null: false, default: "open"
belongs_to :message, CodeCorps.Message
belongs_to :user, CodeCorps.User
has_many :conversation_parts, CodeCorps.ConversationPart
timestamps()
end
def update_changeset(struct, %{} = params) do
struct
|> cast(params, [:status])
|> validate_inclusion(:status, statuses())
end
defp statuses do
~w{ open closed reopened }
end
end