Conversation: Add Conversations and Participations.
This commit is contained in:
parent
b5cecebbc1
commit
d1da6b155a
6 changed files with 127 additions and 0 deletions
30
lib/conversation.ex
Normal file
30
lib/conversation.ex
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Conversation do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Conversation.Participation
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "conversations" do
|
||||
field(:ap_id, :string)
|
||||
has_many(:participations, Participation)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def creation_cng(struct, params) do
|
||||
struct
|
||||
|> cast(params, [:ap_id])
|
||||
|> validate_required([:ap_id])
|
||||
|> unique_constraint(:ap_id)
|
||||
end
|
||||
|
||||
def create_for_ap_id(ap_id) do
|
||||
%__MODULE__{}
|
||||
|> creation_cng(%{ap_id: ap_id})
|
||||
|> Repo.insert()
|
||||
end
|
||||
end
|
||||
31
lib/conversation/participation.ex
Normal file
31
lib/conversation/participation.ex
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Conversation.Participation do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Conversation
|
||||
alias Pleroma.Repo
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "conversation_participations" do
|
||||
belongs_to(:user, User, type: Pleroma.FlakeId)
|
||||
belongs_to(:conversation, Conversation)
|
||||
field(:read, :boolean, default: false)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def creation_cng(struct, params) do
|
||||
struct
|
||||
|> cast(params, [:user_id, :conversation_id])
|
||||
|> validate_required([:user_id, :conversation_id])
|
||||
end
|
||||
|
||||
def create_for_user_and_conversation(user, conversation) do
|
||||
%__MODULE__{}
|
||||
|> creation_cng(%{user_id: user.id, conversation_id: conversation.id})
|
||||
|> Repo.insert()
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue