Conversations: Import order, import as read.
This commit is contained in:
parent
e6d7f8d223
commit
a33bec7d58
4 changed files with 13 additions and 8 deletions
|
|
@ -22,15 +22,17 @@ defmodule Pleroma.Conversation.Participation do
|
|||
|
||||
def creation_cng(struct, params) do
|
||||
struct
|
||||
|> cast(params, [:user_id, :conversation_id])
|
||||
|> cast(params, [:user_id, :conversation_id, :read])
|
||||
|> validate_required([:user_id, :conversation_id])
|
||||
end
|
||||
|
||||
def create_for_user_and_conversation(user, conversation) do
|
||||
def create_for_user_and_conversation(user, conversation, opts \\ []) do
|
||||
read = !!opts[:read]
|
||||
|
||||
%__MODULE__{}
|
||||
|> creation_cng(%{user_id: user.id, conversation_id: conversation.id})
|
||||
|> creation_cng(%{user_id: user.id, conversation_id: conversation.id, read: read})
|
||||
|> Repo.insert(
|
||||
on_conflict: [set: [read: false, updated_at: NaiveDateTime.utc_now()]],
|
||||
on_conflict: [set: [read: read, updated_at: NaiveDateTime.utc_now()]],
|
||||
returning: true,
|
||||
conflict_target: [:user_id, :conversation_id]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue