Mark the conversations with the blocked user as read and update the blocking user's unread_conversation_count.
Since the conversations with the blocked user are invisible, they are excluded from the blocking user's `unread_conversation_count`.
This commit is contained in:
parent
653054d301
commit
0580654485
5 changed files with 175 additions and 11 deletions
|
|
@ -32,11 +32,20 @@ defmodule Pleroma.Conversation.Participation do
|
|||
|
||||
def create_for_user_and_conversation(user, conversation, opts \\ []) do
|
||||
read = !!opts[:read]
|
||||
invisible_conversation = !!opts[:invisible_conversation]
|
||||
|
||||
update_on_conflict =
|
||||
if(invisible_conversation, do: [], else: [read: read])
|
||||
|> Keyword.put(:updated_at, NaiveDateTime.utc_now())
|
||||
|
||||
%__MODULE__{}
|
||||
|> creation_cng(%{user_id: user.id, conversation_id: conversation.id, read: read})
|
||||
|> creation_cng(%{
|
||||
user_id: user.id,
|
||||
conversation_id: conversation.id,
|
||||
read: invisible_conversation || read
|
||||
})
|
||||
|> Repo.insert(
|
||||
on_conflict: [set: [read: read, updated_at: NaiveDateTime.utc_now()]],
|
||||
on_conflict: [set: update_on_conflict],
|
||||
returning: true,
|
||||
conflict_target: [:user_id, :conversation_id]
|
||||
)
|
||||
|
|
@ -69,7 +78,26 @@ defmodule Pleroma.Conversation.Participation do
|
|||
end
|
||||
end
|
||||
|
||||
def mark_all_as_read(user) do
|
||||
def mark_all_as_read(%User{local: true} = user, %User{} = target_user) do
|
||||
target_conversation_ids =
|
||||
__MODULE__
|
||||
|> where([p], p.user_id == ^target_user.id)
|
||||
|> select([p], p.conversation_id)
|
||||
|> Repo.all()
|
||||
|
||||
__MODULE__
|
||||
|> where([p], p.user_id == ^user.id)
|
||||
|> where([p], p.conversation_id in ^target_conversation_ids)
|
||||
|> update([p], set: [read: true])
|
||||
|> Repo.update_all([])
|
||||
|
||||
{:ok, user} = User.set_unread_conversation_count(user)
|
||||
{:ok, user, []}
|
||||
end
|
||||
|
||||
def mark_all_as_read(%User{} = user, %User{}), do: {:ok, user, []}
|
||||
|
||||
def mark_all_as_read(%User{} = user) do
|
||||
{_, participations} =
|
||||
__MODULE__
|
||||
|> where([p], p.user_id == ^user.id)
|
||||
|
|
@ -78,8 +106,8 @@ defmodule Pleroma.Conversation.Participation do
|
|||
|> select([p], p)
|
||||
|> Repo.update_all([])
|
||||
|
||||
User.set_unread_conversation_count(user)
|
||||
{:ok, participations}
|
||||
{:ok, user} = User.set_unread_conversation_count(user)
|
||||
{:ok, user, participations}
|
||||
end
|
||||
|
||||
def mark_as_unread(participation) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue