mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
automatically subscribe user on post
This commit is contained in:
parent
eef29910de
commit
de48c06f99
4 changed files with 10 additions and 0 deletions
|
@ -9,6 +9,7 @@ defmodule Philomena.Comments do
|
|||
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Images
|
||||
alias Philomena.Notifications
|
||||
|
||||
@doc """
|
||||
|
@ -51,6 +52,9 @@ defmodule Philomena.Comments do
|
|||
Multi.new
|
||||
|> Multi.insert(:comment, comment)
|
||||
|> Multi.update_all(:image, image_query, inc: [comments_count: 1])
|
||||
|> Multi.run(:subscribe, fn _repo, _changes ->
|
||||
Images.create_subscription(image, user)
|
||||
end)
|
||||
|> Repo.transaction()
|
||||
end
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ defmodule Philomena.Images do
|
|||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_subscription(image, nil), do: {:ok, nil}
|
||||
def create_subscription(image, user) do
|
||||
%Subscription{image_id: image.id, user_id: user.id}
|
||||
|> Subscription.changeset(%{})
|
||||
|
|
|
@ -8,6 +8,7 @@ defmodule Philomena.Posts do
|
|||
alias Philomena.Repo
|
||||
|
||||
alias Philomena.Topics.Topic
|
||||
alias Philomena.Topics
|
||||
alias Philomena.Posts.Post
|
||||
alias Philomena.Forums.Forum
|
||||
alias Philomena.Notifications
|
||||
|
@ -75,6 +76,9 @@ defmodule Philomena.Posts do
|
|||
|
||||
{:ok, count}
|
||||
end)
|
||||
|> Multi.run(:subscribe, fn _repo, _changes ->
|
||||
Topics.create_subscription(topic, user)
|
||||
end)
|
||||
|> Repo.isolated_transaction(:serializable)
|
||||
end
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ defmodule Philomena.Topics do
|
|||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_subscription(topic, nil), do: {:ok, nil}
|
||||
def create_subscription(topic, user) do
|
||||
%Subscription{topic_id: topic.id, user_id: user.id}
|
||||
|> Subscription.changeset(%{})
|
||||
|
|
Loading…
Reference in a new issue