SideEffects / ChatView: Add an unread cache.

This is to prevent wrong values in the stream.
This commit is contained in:
lain 2020-06-05 12:01:33 +02:00
commit cc8a7dc205
5 changed files with 30 additions and 22 deletions

View file

@ -142,6 +142,11 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
{:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
{:ok, cm_ref} = ChatMessageReference.create(chat, object, user.ap_id != actor.ap_id)
# We add a cache of the unread value here so that it doesn't change when being streamed out
chat =
chat
|> Map.put(:unread, ChatMessageReference.unread_count_for_chat(chat))
Streamer.stream(
["user", "user:pleroma_chat"],
{user, %{cm_ref | chat: chat, object: object}}